-
Notifications
You must be signed in to change notification settings - Fork 221
Deploy command #173
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
Draft
braelyn-ai
wants to merge
58
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
58 commits
Select commit
Hold shift + click to select a range
d8e7afa
serve
braelyn-ai 7a60fc0
fix serve file and dockerfile
braelyn-ai 7f88cc0
serve from inside source
braelyn-ai b067837
load dotenv
braelyn-ai 606fd44
load dotenv from one up
braelyn-ai a240d5d
health endpoint
braelyn-ai b9d9942
env path
braelyn-ai e25b51a
loadenv before import
braelyn-ai 8c13295
Merge branch 'main' into deploy
braelyn-ai 83fc0c7
Merge branch 'main' into deploy
braelyn-ai 77657f3
Merge branch 'main' into deploy
braelyn-ai 6ccbcda
Merge branch 'main' into deploy
braelyn-ai 2d80e52
Merge branch 'main' into deploy
braelyn-ai f51de09
Merge branch 'main' into deploy
braelyn-ai 6896a22
create project on deploy
braelyn-ai 15d2cab
Merge branch 'main' into deploy-command
braelyn-ai 6190572
Merge branch 'main' into deploy-command
braelyn-ai 41b9b9a
zip code and upload
braelyn-ai 033711a
Merge branch 'main' into deploy
braelyn-ai 80a1932
Merge branch 'main' into deploy-command
braelyn-ai dcacaca
fix deploy
braelyn-ai de2d4aa
Merge branch 'refs/heads/main' into deploy
braelyn-ai ef3a3fd
serve working
braelyn-ai a1a26bd
Merge branch 'main' into deploy-command
braelyn-ai 140b80f
Merge branch 'main' into deploy-command
braelyn-ai 71f474f
build all but some folders
braelyn-ai 066fa2d
Merge branch 'main' into deploy-command
braelyn-ai 620f7fb
better upload
braelyn-ai d8055bd
spinner tests
braelyn-ai 3fd8ef1
deploy tests
braelyn-ai 044e053
logging
braelyn-ai d2590e0
use websockets
braelyn-ai 9ee0ecd
Merge branch 'deploy' into deploy-command
braelyn-ai 325d76e
use proper dockerfile
braelyn-ai 7883198
Merge branch 'main' into deploy-command
braelyn-ai 4da6cf7
Merge branch 'main' into deploy-command
braelyn-ai 4b31001
build, push, track, webhooks
braelyn-ai 6a30280
serve work
braelyn-ai 0ad98ea
dockerfile works and new run func
braelyn-ai 2b94a9f
import fix
braelyn-ai 023b3ce
run proj from serve.py
braelyn-ai 72161d3
if main at bottom
braelyn-ai 35d94a4
input handling
braelyn-ai 0a7eba7
log import
braelyn-ai cf49ff8
log import fix
braelyn-ai bf7fd6e
todos
braelyn-ai 4b5a178
update serve
braelyn-ai dc3cbf4
Merge branch 'main' into deploy-command
braelyn-ai 8c7ea35
use gunincorn
braelyn-ai f578b00
fix name
braelyn-ai 3cdb963
return before processing
braelyn-ai 5378071
return result
braelyn-ai abd383b
return session_id
braelyn-ai 318c4b8
guid to string
braelyn-ai e4991eb
use waitress
braelyn-ai 94ee47f
use hosted
braelyn-ai 9c96e45
remove waitress import
braelyn-ai f8e69e4
end deploy logs on finish deploy
braelyn-ai 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 hidden or 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 hidden or 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: | ||
|
Collaborator
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 hidden or 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 hidden or 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
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