Skip to content

Commit

Permalink
support --main file in deploy cli
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Aug 14, 2024
1 parent 581e0fd commit 371ab4f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.7.0

- Support for `--main` deployment file in `hal9 deploy`

## 2.6.9

- Documentation improvements
Expand Down
6 changes: 4 additions & 2 deletions python/hal9/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ def run(path :str):
@click.option('--type', '-f', 'typename', default='ability', help='Deployment content')
@click.option('--data', '-d', 'data', default=None, help='Deployment data path')
@click.option('--access', '-a', 'access', default="private", help='Deployment access level')
def deploy(path :str, target :str, url :str, name :str, typename :str, data :str, access :str):
@click.option('--main', '-m', 'main', default="app.py", help='Deployment main file')
def deploy(path :str, target :str, url :str, name :str, typename :str, data :str, access :str, main :str):
"""
Deploy Project
--path: The path to the project. Required argument.
--url: The server url to deploy to. Defaults to https://api.hal9.com.
--name: The server url to deploy to. Defaults to https://api.hal9.com.
--type: The type of content to deploy. Defaults to (chatbot) ability.
--main: The main file deploy. Defaults to 'app.py'.
"""

if (name is None):
name = f'{os.path.basename(path)}-{int(datetime.datetime.now().timestamp() * 1000)}'

api_deploy(path, target, url, name, typename, data, access)
api_deploy(path, target, url, name, typename, data, access, main)

cli.add_command(create)
cli.add_command(run)
Expand Down
6 changes: 4 additions & 2 deletions python/hal9/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'hal9': deploy_hal9,
}

def deploy(path :str, target :str, url :str, name :str, typename :str, data :str, access :str) -> str:
def deploy(path :str, target :str, url :str, name :str, typename :str, data :str, access :str, main :str) -> str:
"""Deploy an application
Parameters
Expand All @@ -23,9 +23,11 @@ def deploy(path :str, target :str, url :str, name :str, typename :str, data :str
The data schema to use, defaults to empty.
access : str
The access level, defaults to 'private'.
main : str
The main file to use, defaults to 'app.py'.
"""

if target in targets:
targets[target](path, url, name, typename, data, access)
targets[target](path, url, name, typename, data, access, main)
else:
raise Exception(f"Deployment target '{target}' is unsupported.")
2 changes: 1 addition & 1 deletion python/hal9/targets/docker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shutil
from pathlib import Path

def deploy(path :str, url :str, name :str, typename :str, access :str) -> str:
def deploy(path :str, url :str, name :str, typename :str, access :str, main :str) -> str:
package_dir = Path(__file__).parent.parent
source_path = package_dir / 'templates' / 'docker' / 'Dockerfile'
destination_path = Path(path) / 'Dockerfile'
Expand Down
27 changes: 6 additions & 21 deletions python/hal9/targets/hal9.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,16 @@ def read_files(path):

return files_dict

def request_deploy(path :str, url :str, name :str, typename :str, data :str, access :str) -> str:
project_name = project_from_path(path)
zip_path = create_deployment(path)

unixtime = int(time.time())

with open(zip_path, 'rb') as file:
file_content = file.read()
encoded_content = base64.b64encode(file_content).decode('utf-8')
upload_name = f'{project_name}-{unixtime}.zip'

# use app.py until backend supports zip content
with open(Path(path) / 'app.py', 'rb') as file:
file_content = file.read()
encoded_content = base64.b64encode(file_content).decode('utf-8')
upload_name = f'app.py'

def request_deploy(path :str, url :str, name :str, typename :str, data :str, access :str, main :str) -> str:
payload = {
'filename': upload_name,
'filename': main,
'type': typename,
'name': name,
'format': 'b64',
'files': read_files(path),
'schemapath': data,
'access': access
'access': access,
'sourcefile': main
}

headers = {
Expand All @@ -73,12 +58,12 @@ def request_deploy(path :str, url :str, name :str, typename :str, data :str, acc
response_data = response.json()
print(response_data['url'])

def deploy(path :str, url :str, name :str, typename :str, data :str, access :str) -> str:
def deploy(path :str, url :str, name :str, typename :str, data :str, access :str, main :str) -> str:
if 'HAL9_TOKEN' in os.environ:
hal9_token = os.environ['HAL9_TOKEN']
else:
exit(f'HAL9_TOKEN environment variable missing, see https://hal9.com/deploy')
# hal9_token = browser_login()

request_deploy(path, url, name, typename, data, access)
request_deploy(path, url, name, typename, data, access, main)

2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hal9"
version = "2.6.9"
version = "2.7.0"
description = ""
authors = ["Javier Luraschi <javier@hal9.ai>"]
readme = "README.md"
Expand Down

0 comments on commit 371ab4f

Please sign in to comment.