-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deploy command #173
Draft
bboynton97
wants to merge
8
commits into
main
Choose a base branch
from
deploy-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Deploy command #173
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6896a22
create project on deploy
bboynton97 15d2cab
Merge branch 'main' into deploy-command
bboynton97 6190572
Merge branch 'main' into deploy-command
bboynton97 41b9b9a
zip code and upload
bboynton97 80a1932
Merge branch 'main' into deploy-command
bboynton97 dcacaca
fix deploy
bboynton97 a1a26bd
Merge branch 'main' into deploy-command
bboynton97 140b80f
Merge branch 'main' into deploy-command
bboynton97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import os | ||
import tempfile | ||
import tomllib | ||
import webbrowser | ||
import zipfile | ||
from pathlib import Path | ||
|
||
from agentstack.auth import get_stored_token, login | ||
from agentstack.conf import ConfigFile | ||
from agentstack.utils import term_color | ||
import requests | ||
|
||
|
||
def deploy(): | ||
bearer_token = get_stored_token() | ||
if not bearer_token: | ||
success = login() | ||
if success: | ||
bearer_token = get_stored_token() | ||
else: | ||
print(term_color("Failed to authenticate with AgentStack.sh", "red")) | ||
return | ||
|
||
project_id = get_project_id() | ||
pyproject = load_pyproject() | ||
files = list(Path('.').rglob('*.py')) | ||
|
||
with tempfile.NamedTemporaryFile(suffix='.zip') as tmp: | ||
with zipfile.ZipFile(tmp.name, 'w') as zf: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth just building the project into a |
||
for file in files: | ||
zf.write(file) | ||
if pyproject: | ||
zf.write("pyproject.toml") | ||
|
||
response = requests.post( | ||
'http://localhost:3000/deploy/build', | ||
files={'code': ('code.zip', open(tmp.name, 'rb'))}, | ||
params={'projectId': project_id}, | ||
headers={'Authorization': bearer_token} | ||
) | ||
|
||
if response.status_code != 200: | ||
print(term_color("Failed to deploy with AgentStack.sh", "red")) | ||
print(response.text) | ||
return | ||
|
||
webbrowser.open(f"http://localhost:5173/project/{project_id}") | ||
|
||
|
||
def load_pyproject(): | ||
if os.path.exists("pyproject.toml"): | ||
with open("pyproject.toml", "rb") as f: | ||
return tomllib.load(f) | ||
return None | ||
|
||
def get_project_id(): | ||
project_config = ConfigFile() | ||
project_id = project_config.hosted_project_id | ||
|
||
if project_id: | ||
return project_id | ||
|
||
bearer_token = get_stored_token() | ||
|
||
# if not in config, create project and store it | ||
print(term_color("🚧 Creating AgentStack.sh Project", "green")) | ||
headers = { | ||
'Authorization': f'Bearer {bearer_token}', | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
payload = { | ||
'name': project_config.project_name | ||
} | ||
|
||
try: | ||
response = requests.post( | ||
url="http://localhost:3000/projects", | ||
# url="https://api.agentstack.sh/projects", | ||
headers=headers, | ||
json=payload | ||
) | ||
|
||
response.raise_for_status() | ||
res_data = response.json() | ||
project_id = res_data['id'] | ||
project_config.hosted_project_id = project_id | ||
project_config.write() | ||
return project_id | ||
|
||
except requests.exceptions.RequestException as e: | ||
print(f"Error making request: {e}") | ||
return None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
agentstack/templates/crewai/{{cookiecutter.project_metadata.project_slug}}/agentstack.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a deploy stub to /cli that manages the CLI interaction and logging, then use the deploy function from this file