-
Notifications
You must be signed in to change notification settings - Fork 0
Submit to argo #16
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
Merged
Merged
Submit to argo #16
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ddcd84e
fix(auth): updates templates, adds example 2
Matt-Carre 828731a
feat(auth): updates templates to align with keycloak, .env variables
Matt-Carre de8af43
feat(copier): updates copier template to new standards
Matt-Carre e615563
feat(api): reworks submission to argo
Matt-Carre 623cab0
feat(copier): adds instructions on how to submit a workflow to argo
Matt-Carre ca94c99
feat(argo): added underscore in example name to avoid duplication
Matt-Carre 5f1897e
fix(api): fixes code based on comments
Matt-Carre 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
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 was deleted.
Oops, something went wrong.
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,24 @@ | ||
| # Setting up a development environment | ||
| 1. run "uv lock" to generate the uv.lock file | ||
| 2. Create .env in this folder (with the path src/.env) containing the following variables: | ||
|
|
||
| HOST=https://argo-workflows.workflows.diamond.ac.uk/ (to submit to the production cluster) | ||
| DEFAULT_IMAGE= (usually python 3.10) | ||
| NAMESPACE= (the cluster you wish to run the templates on) | ||
|
|
||
| 3. Build the dev container | ||
|
|
||
| # Submitting a workflow to Argo | ||
| 1. At the start of your workflow definition file, add: | ||
|
|
||
| ```python | ||
| from {{project_name}}.submit_to_argo import submit_workflow_to_argo | ||
| ``` | ||
|
|
||
| 2. At the end of a workflow definition file, once your workflow (w) is created, add: | ||
| ```python | ||
| submit_workflow_to_argo(w) | ||
| ``` | ||
|
|
||
| NOTE: Be sure to remove this line upon commiting changes, as all workflow definition files are | ||
| by default, ran on pre-commit, to ensure that any yaml files they create are up to date. |
24 changes: 24 additions & 0 deletions
24
src/copier_template/src/{{ project_name }}/submit_to_argo.py.jinja
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,24 @@ | ||
| import os | ||
| from typing import cast | ||
|
|
||
| import dotenv | ||
| from hera.shared import global_config | ||
| from hera.workflows import Workflow, WorkflowsService | ||
| from hera.workflows import models as m | ||
|
|
||
| from {{project_name}}.auth.keycloak_checker import set_token_env_variable | ||
|
|
||
|
|
||
| def submit_workflow_to_argo(w: Workflow): | ||
| set_token_env_variable() | ||
| dotenv.load_dotenv(dotenv_path="src/.env", override=True) | ||
| w.namespace = os.environ.get("NAMESPACE") | ||
| w.workflows_service = WorkflowsService( | ||
| host=str(os.environ.get("HOST")).strip("'"), | ||
| token=str(os.environ.get("TOKEN")).strip("'"), | ||
| ) | ||
| global_config.image = str(os.environ.get("DEFAULT_IMAGE")) | ||
| submitted_w = cast(m.Workflow, w.create()) | ||
| name = submitted_w.metadata.name | ||
| namespace = submitted_w.metadata.namespace | ||
| print(f"submitted {name} to {namespace}") |
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
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
|
Matt-Carre marked this conversation as resolved.
|
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 was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/copier_template/tests/test_submit_workflow_to_argo.jinja
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,20 @@ | ||
| from unittest.mock import MagicMock, call, patch | ||
|
|
||
| from {{project_name}}.submit_to_argo import submit_workflow_to_argo | ||
|
|
||
|
|
||
| @patch("{{project_name}}.submit_to_argo.Workflow") | ||
| @patch("{{project_name}}.submit_to_argo.os.environ.get") | ||
| @patch("{{project_name}}.submit_to_argo.dotenv.load_dotenv") | ||
| @patch("{{project_name}}.submit_to_argo.set_token_env_variable") | ||
| def test_submit_workflow_to_argo( | ||
| mock_key: MagicMock, | ||
| mock_load_env: MagicMock, | ||
| mock_get_env_var: MagicMock, | ||
| mock_workflow: MagicMock, | ||
| ): | ||
| mock_workflow = MagicMock() | ||
| submit_workflow_to_argo(mock_workflow) | ||
| mock_key.assert_called_once_with(staging=True) | ||
| mock_load_env.assert_called_once_with(dotenv_path="src/.env", override=True) | ||
| mock_get_env_var.assert_has_calls([call("HOST"), call("TOKEN")], any_order=True) |
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
|
Matt-Carre marked this conversation as resolved.
|
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 was deleted.
Oops, something went wrong.
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,24 @@ | ||
| import os | ||
| from typing import cast | ||
|
|
||
| import dotenv | ||
| from hera.shared import global_config | ||
| from hera.workflows import Workflow, WorkflowsService | ||
| from hera.workflows import models as m | ||
|
|
||
| from python_interface_to_workflows.auth.keycloak_checker import set_token_env_variable | ||
|
|
||
|
|
||
| def submit_workflow_to_argo(w: Workflow): | ||
| set_token_env_variable(staging=True) | ||
|
Matt-Carre marked this conversation as resolved.
|
||
| dotenv.load_dotenv(dotenv_path="src/.env", override=True) | ||
| w.namespace = os.environ.get("NAMESPACE") | ||
| w.workflows_service = WorkflowsService( | ||
| host=str(os.environ.get("HOST")).strip("'"), | ||
| token=str(os.environ.get("TOKEN")).strip("'"), | ||
| ) | ||
| global_config.image = str(os.environ.get("DEFAULT_IMAGE")) | ||
| submitted_w = cast(m.Workflow, w.create()) | ||
| name = submitted_w.metadata.name | ||
| namespace = submitted_w.metadata.namespace | ||
| print(f"submitted {name} to {namespace}") | ||
|
Matt-Carre marked this conversation as resolved.
|
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.