-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0479de1
commit a2c15d0
Showing
5 changed files
with
169 additions
and
50 deletions.
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
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,118 @@ | ||
# Scenario | ||
|
||
This repository supposes the following, for the sake of example: | ||
|
||
- You have two Prefect workspaces, one used for staging and one used for production | ||
- You have one or more deployments which should be mirrored across workspaces | ||
- Your deployments are configured to use git code storage, and the branch a deployment uses should differ per workspace | ||
- Flows run in containers, so images need to be rebuilt when dependencies or build steps change. Since dependencies can differ per branch/workspace, each branch/workspace pairing should have its own image | ||
|
||
# Select Actions | ||
|
||
`select_actions` allows users to choose from a list of predefined actions for their `build`, `push`, and `pull` steps. When `select_actions` is invoked, any combination of `build`, `push`, and `pull` may be provided. These steps must be defined under the `actions` portion of a `prefect.yaml` file. Each action selected will override the default step definition at the root level of your `prefect.yaml`. | ||
|
||
## Example | ||
|
||
This example uses `select_actions.py` as part of a Github Actions workflow to modify `prefect.yaml` according to a set of triggers and conditions. | ||
|
||
``` | ||
actions: | ||
build: | ||
build_image_stg: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-stg | ||
tag: '{{ get-commit-hash.stdout }}' | ||
dockerfile: Dockerfile | ||
build_image_prod: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-prod | ||
tag: '{{ get-commit-hash.stdout }}' | ||
dockerfile: Dockerfile | ||
push: | ||
push_image: | ||
- prefect_docker.deployments.steps.push_docker_image: | ||
requires: prefect-docker | ||
image_name: '{{ build-image.image_name }}' | ||
tag: '{{ build-image.tag }}' | ||
pull: | ||
staging: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: staging | ||
credentials: '{{ prefect.blocks.github-credentials.my-block-name }}' | ||
production: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: main | ||
credentials: '{{ prefect.blocks.github-credentials.my-block-name }}' | ||
build: null | ||
push: null | ||
pull: null | ||
``` | ||
|
||
`python select_actions.py --build build_image --push push_image --pull production` | ||
|
||
``` | ||
actions: | ||
build: | ||
build_image_stg: &id001 | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-stg | ||
tag: '{{ get-commit-hash.stdout }}' | ||
dockerfile: Dockerfile | ||
build_image_prod: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-prod | ||
tag: '{{ get-commit-hash.stdout }}' | ||
dockerfile: Dockerfile | ||
push: | ||
push_image: &id002 | ||
- prefect_docker.deployments.steps.push_docker_image: | ||
requires: prefect-docker | ||
image_name: '{{ build-image.image_name }}' | ||
tag: '{{ build-image.tag }}' | ||
pull: | ||
staging: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: staging | ||
credentials: '{{ prefect.blocks.github-credentials.my-block-name }}' | ||
production: &id003 | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: main | ||
credentials: '{{ prefect.blocks.github-credentials.my-block-name }}' | ||
build: *id001 | ||
push: *id002 | ||
pull: *id003 | ||
``` |
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 |
---|---|---|
|
@@ -6,52 +6,48 @@ | |
name: prefect-select-actions | ||
prefect-version: 2.14.3 | ||
|
||
definitions: | ||
actions: | ||
build: | ||
no_action: | ||
build_image_stg: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-stg | ||
tag: "{{ get-commit-hash.stdout }}" | ||
dockerfile: Dockerfile | ||
build_image_prod: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-prod | ||
tag: "{{ get-commit-hash.stdout }}" | ||
dockerfile: Dockerfile | ||
push: | ||
no_action: | ||
push_image: | ||
- prefect_docker.deployments.steps.push_docker_image: | ||
requires: prefect-docker | ||
image_name: "{{ build-image.image_name }}" | ||
tag: "{{ build-image.tag }}" | ||
pull: | ||
staging: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: staging | ||
credentials: "{{ prefect.blocks.github-credentials.my-block-name }}" | ||
production: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: main | ||
credentials: "{{ prefect.blocks.github-credentials.my-block-name }}" | ||
actions: | ||
build: | ||
build_image_stg: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-stg | ||
tag: "{{ get-commit-hash.stdout }}" | ||
dockerfile: Dockerfile | ||
build_image_prod: | ||
- prefect.deployments.steps.run_shell_script: | ||
id: get-commit-hash | ||
script: git rev-parse --short HEAD | ||
stream_output: false | ||
- prefect_docker.deployments.steps.build_docker_image: | ||
id: build-image | ||
requires: prefect-docker | ||
image_name: kevingrismoreprefect/github-actions-demo-prod | ||
tag: "{{ get-commit-hash.stdout }}" | ||
dockerfile: Dockerfile | ||
push: | ||
push_image: | ||
- prefect_docker.deployments.steps.push_docker_image: | ||
requires: prefect-docker | ||
image_name: "{{ build-image.image_name }}" | ||
tag: "{{ build-image.tag }}" | ||
pull: | ||
staging: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: staging | ||
credentials: "{{ prefect.blocks.github-credentials.my-block-name }}" | ||
production: | ||
- prefect.deployments.steps.git_clone: | ||
repository: [email protected]:kevingrismore/prefect-select-actions.git | ||
branch: main | ||
credentials: "{{ prefect.blocks.github-credentials.my-block-name }}" | ||
|
||
# build section allows you to manage and build docker images | ||
build: null | ||
|
||
push: null | ||
|
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