Skip to content

Commit 1a649dc

Browse files
committed
Requiring api_address for a more explicit and simple workflow
1 parent 7da2431 commit 1a649dc

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ inputs:
4242
description: Git host for the Algorithmia algorithm repository. Change to git.algorithmia.com if the algorithm is hosted on Algorithmia Marketplace or git.YOUR_DOMAIN for enterprise installations.
4343
required: false
4444
default: 'github.com'
45+
algorithmia_api:
46+
description: API endpoint Algorithmia installation, for enterprise customers.
47+
required: false
48+
default: 'https://api.algorithmia.com'
4549
runs:
4650
using: 'docker'
4751
image: 'Dockerfile'
@@ -57,5 +61,6 @@ runs:
5761
- ${{ inputs.model_path }}
5862
- ${{ inputs.notebook_path }}
5963
- ${{ inputs.git_host }}
64+
- ${{ inputs.algorithmia_host }}
6065

6166

src/algorithmia_deployer.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
class AlgorithmiaDeployer:
99
def __init__(
10-
self, api_key, git_host, username, algo_name, model_path, workspace_path,
10+
self, api_key, api_address, username, algo_name, model_path, workspace_path,
1111
) -> None:
12-
self.algo_client = Algorithmia.client(
13-
api_key, self._api_addr_from_git_host(git_host)
14-
)
12+
self.algo_client = Algorithmia.client(api_key, api_address)
1513
self.username = username
1614
self.algo_name = algo_name
1715
self.model_path = model_path
@@ -20,6 +18,8 @@ def __init__(
2018
self.model_full_path = f"{workspace_path}/{model_path}"
2119
self.model_full_path = model_path
2220

21+
print(f"Initialized AlgorithmiaDeployer to deploy for {api_address}")
22+
2323
def upload_and_link_algo_model(
2424
self, upload_path, git_repo, git_ref, commit_SHA, commit_msg
2525
):
@@ -28,6 +28,9 @@ def upload_and_link_algo_model(
2828
if model_md5_hash:
2929
upload_path = self._replace_placeholders(upload_path)
3030
algorithmia_upload_path = self._upload_model(upload_path, commit_SHA)
31+
print(
32+
f"Expect to find your uploaded model at {algorithmia_upload_path}. Now it's time to update your model manifest!"
33+
)
3134
if algorithmia_upload_path:
3235
self._update_algo_model_manifest(
3336
git_repo=git_repo,
@@ -50,16 +53,6 @@ def upload_and_link_algo_model(
5053
f"Model file not found at {self.model_full_path}. Please check your workflow configuration."
5154
)
5255

53-
def _api_addr_from_git_host(self, git_host):
54-
# Examples:
55-
# git.devopsbay1.enthalpy.click -> https://api.devopsbay1.enthalpy.click
56-
# git.algorithmia.com -> https://api.algorithmia.com
57-
# git.test.algorithmia.com -> https://api.test.algorithmia.com
58-
domain = git_host.split("git.", 1)[1]
59-
api_addr = f"https://api.{domain}"
60-
print(f"API address for Algorithmia client is: {api_addr}")
61-
return api_addr
62-
6356
def _replace_placeholders(self, parametric_str):
6457
if "$ALGORITHMIA_USERNAME" in parametric_str:
6558
print(f"Replacing $ALGORITHMIA_USERNAME in {parametric_str}")
@@ -92,7 +85,7 @@ def _upload_model(self, remote_path, commit_SHA):
9285
name_before_ext, ext = tuple(os.path.splitext(model_name))
9386
unique_model_name = "{}_{}{}".format(name_before_ext, commit_SHA, ext)
9487
print(
95-
"Will upload {} from {} to {}".format(
88+
"Will upload model {} from {} to {}".format(
9689
unique_model_name, self.model_full_path, remote_path
9790
)
9891
)
@@ -103,12 +96,14 @@ def _upload_model(self, remote_path, commit_SHA):
10396
self.algo_client.dir(remote_path).create()
10497
full_remote_path = "{}/{}".format(remote_path, unique_model_name)
10598
if self.algo_client.file(full_remote_path).exists():
106-
print(f"File with the same name exists, overriding: {full_remote_path}")
99+
print(
100+
f"Model file with the same name exists, overriding: {full_remote_path}"
101+
)
107102
result = self.algo_client.file(full_remote_path).putFile(
108103
self.model_full_path
109104
)
110105
if result.path:
111-
print(f"File successfully uploaded at: {full_remote_path}")
106+
print(f"Model file successfully uploaded at: {full_remote_path}")
112107
upload_path = result.path
113108
except Exception as e:
114109
print(
@@ -145,3 +140,7 @@ def _update_algo_model_manifest(
145140

146141
with open(manifest_full_path, "w+") as new_manifest_file:
147142
json.dump(manifest, new_manifest_file)
143+
144+
print(
145+
"Successfully updated algorithm's model_manifest.json file with the model path"
146+
)

0 commit comments

Comments
 (0)