Andrew
11/29/2023, 11:18 PMprefect deploy --all
) and have it include the updated code. right now I’m getting this during the docker image build
Step 5/6 : WORKDIR /opt/prefect/flows/
---> Using cache
---> 07afdee1b173
for context, I’m using the kubernetes worker pool on gke. What are the best practices here?Marvin
11/29/2023, 11:18 PMprefect deploy --all
command. This command will deploy all deployments. If you want to deploy specific deployments, you can use the --name
flag followed by the name of your flow and deployment (source).
Regarding the Docker image build, once you have a Dockerfile, you can build your image by running docker build -t your-image-name .
. Make sure your Dockerfile includes the necessary commands to copy your updated code into the image. You can check that your build worked by running a container from your new image. The container will need an API URL and an API key to communicate with Prefect Cloud. You can get an API key from the API Keys section of the user settings in the Prefect UI (source).
For your Kubernetes worker pool on GKE, you will create a Docker type work pool via the CLI. Using the Docker work pool type means that all work sent to this work pool will run within a dedicated Docker container using a Docker client available to the worker (source).
Please note that these are general guidelines and you may need to adjust them based on your specific setup and requirements.Nate
11/29/2023, 11:19 PMFor your Kubernetes worker pool on GKE, you will create a Docker type work pool via the CLI🙅 there's the k8s work pool for that, but I suspect you already know that
Nate
11/29/2023, 11:19 PMgit_clone
pull step?Andrew
11/29/2023, 11:20 PMAndrew
11/29/2023, 11:21 PMNate
11/29/2023, 11:28 PMDockerfile
that does pip install .
or pip install -r requirements.txt
or whatever your flow would need for deps
• either use a `build` step to build this image, or build / push the image in your own CI / image pipeline if preferred. either way, set that image
as a job_variable
on your work pool directly, or override the `image` on the work pool _for this specific deployment_
• use a git clone pull step to pull your flow source code down from your repo at runtime on top of your image
built in above steps
the thing i like about this is that, most often for me, my flow source code changes much more often than image
/ deps need to, i.e. i shouldn't have to rebuild my image
just bc i add a comment in my flow, for example. with the above, all i have to do is push my code to github / gitlab etc like I normally would anyways, and then thats the code thats gonna get pulled down at runtime
only gotcha there is that you actually have to remember to push your code 🙂 there's been times where I make local changes to my flow and test and accidentally use the version of the flow in main
bc may changes hadnt been pushed, but for prod deployments that shouldnt be such a gotchaAndrew
11/29/2023, 11:34 PMNate
11/29/2023, 11:43 PMprefect --no-prompt deploy -n some-deploy
, then docker will use cached layers the same way as it would if you did docker build
n times in a row
im pretty sure if you say prefect deploy --all
and all of them use the same build
step, then we'll only run docker build
on your behalf one time, but I'm not 100% on that off the topAndrew
11/29/2023, 11:44 PMNate
11/29/2023, 11:46 PMAndrew
11/30/2023, 12:08 AMCOPY
section, since I have the pull part now?Nate
11/30/2023, 12:10 AMCOPY
of your source codeNate
11/30/2023, 12:10 AMdockerfile: auto
is implicitly saying "please bake my code into this image you're building"Andrew
11/30/2023, 12:12 AMAndrew
11/30/2023, 3:18 AMprefect block register -m prefect_gitlab
, and then added the credentials block, and added my access token inside the block. Then put the name of the block in the prefect.yaml
file, like shown in the docs. access_token: "{{ prefect.blocks.secret.gitlab-access-token }}"
.
Any ideas there? I saw somewhere you may need a username with the access token, but I didn’t see a place to put thatNate
11/30/2023, 3:44 AMAndrew
11/30/2023, 3:46 AMNate
11/30/2023, 3:49 AMNate
11/30/2023, 3:49 AMNate
11/30/2023, 3:49 AMAndrew
11/30/2023, 3:50 AMAndrew
11/30/2023, 3:59 AMFlow could not be retrieved from deployment.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 156, in run_steps
step_output = await run_step(step, upstream_outputs)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 123, in run_step
inputs = await resolve_block_document_references(inputs)
File "/usr/local/lib/python3.10/site-packages/prefect/client/utilities.py", line 51, in with_injected_client
return await fn(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/prefect/utilities/templating.py", line 205, in resolve_block_document_references
updated_value = await resolve_block_document_references(
File "/usr/local/lib/python3.10/site-packages/prefect/client/utilities.py", line 51, in with_injected_client
return await fn(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/prefect/utilities/templating.py", line 228, in resolve_block_document_references
block_type_slug, block_document_name = (
ValueError: too many values to unpack (expected 2)
Nate
11/30/2023, 4:10 AMAndrew
11/30/2023, 4:13 AMpull:
- prefect.deployments.steps.run_shell_script:
id: get-git-branch
script: git rev-parse --abbrev-ref HEAD
stream_output: false
- prefect.deployments.steps.git_clone: &clone_repo
repository: <https://gitlab.com/org/repo.git>
branch: "{{ get-git-branch.stdout }}"
access_token: "{{ prefect.blocks.secret.gitlab-credentials.gitlab-access-token }}"
Nate
11/30/2023, 4:17 AMprefect.blocks.gitlab-credentials.gitlab-access-token
because its
prefect.blocks.{block-type}.{block-document-name}
where secret
is just a common type of block, often templated in pull steps like this. your block is type gitlab-credentials
Andrew
11/30/2023, 4:20 AMNate
11/30/2023, 4:21 AMAndrew
11/30/2023, 4:27 AMFile "/usr/local/lib/python3.10/site-packages/prefect/runner/storage.py", line 615, in _format_token_from_credentials
if not user_provided_token.startswith("oauth2:")
AttributeError: 'dict' object has no attribute 'startswith'
I just pasted in the access token string under "Token" in the block.
I'm looking here: https://docs.prefect.io/latest/guides/deployment/storage-guide/#__tabbed_1_3
And I'm not sure what "In addition to the block name, most users will need to fill in the GitLab Username and GitLab Personal Access Token fields." refers to, in step 4. And its also not clear to me what the prefect block register
command does, vs. adding them in the cloud UINate
11/30/2023, 4:32 AMpip install git+<https://github.com/PrefectHQ/prefect.git>
does it work?Andrew
11/30/2023, 4:34 AMAndrew
11/30/2023, 4:37 AMAndrew
11/30/2023, 4:37 AMNate
11/30/2023, 4:41 AMgit+<https://github.com/PrefectHQ/prefect.git>
in your reqs file (until we go ahead and release 2.14.9 with the fix tomorrow) - or you could test it locally if you have like docker desktop / minikube if you wantNate
11/30/2023, 4:43 AM- name: host-env-test
entrypoint: src/demo_project/read_env.py:read_env
work_pool:
name: docker-work
job_variables:
env:
EXTRA_PIP_PACKAGES: git+<https://github.com/PrefectHQ/prefect.git>
Nate
11/30/2023, 4:44 AMpull:
- prefect.deployments.steps.git_clone:
repository: <https://github.com/PrefectHQ/marvin-recipes.git>
branch: main
- prefect.deployments.steps.run_shell_script:
script: pip install git+<https://github.com/PrefectHQ/prefect.git>
Andrew
11/30/2023, 4:44 AMAndrew
11/30/2023, 4:45 AMNate
11/30/2023, 4:45 AMAndrew
11/30/2023, 4:45 AMAndrew
11/30/2023, 4:55 AMNate
11/30/2023, 5:06 AMAndrew
11/30/2023, 5:14 AMCollecting prefect@ git+<https://github.com/PrefectHQ/prefect.git>
during the buildAndrew
11/30/2023, 3:59 PM2.14.8+4.g3c8f95331
. Not sure if that is the expected version or not. I’m not exactly sure how to debug that. Either the code version isn’t right, or when “access_token”or “token”is pulled from the credentials dict, then its still a dict somehow.Andrew
11/30/2023, 4:00 PMusername
from the credentials in the code, and I’m not sure how to add that to the block, I just see the token areaNate
11/30/2023, 4:03 PM2.14.8+4.g3c8f95331
yeah this "dirty" version is expected if you install from main like that
mm there's likely some issue with the credentials value (or its type) provided if it doesnt work on main
all you're doing is templating in a gitlab creds block into your pull step right?
pull:
- prefect.deployments.steps.run_shell_script:
id: get-git-branch
script: git rev-parse --abbrev-ref HEAD
stream_output: false
- prefect.deployments.steps.git_clone: &clone_repo
repository: <https://gitlab.com/org/repo.git>
branch: "{{ get-git-branch.stdout }}"
access_token: "{{ prefect.blocks.gitlab-credentials.gitlab-access-token }}"
i can try to reproduce this later if this is all it takes to produce the error?Andrew
11/30/2023, 4:09 PMfrom prefect_gitlab import GitLabCredentials
gitlab_credentials_block = GitLabCredentials.load("gitlab-access-token")
credentials = gitlab_credentials_block.dict()
credentials["token"] = credentials["token"].get_secret_value()
print(credentials["token"]
Then it prints the token value as a stringAndrew
11/30/2023, 4:10 PMAndrew
11/30/2023, 4:12 PMNate
11/30/2023, 4:12 PMAndrew
11/30/2023, 4:12 PMAndrew
11/30/2023, 4:13 PMNate
11/30/2023, 4:14 PMprefect worker start
from your dev venvAndrew
11/30/2023, 4:14 PMAndrew
11/30/2023, 4:20 PMAndrew
11/30/2023, 4:20 PMAndrew
11/30/2023, 4:25 PM{'access_token': {'token': '<token>'}}
So it gets “access_token” which isn’t None, and expects it to be a SecretStr, when its actually a dict with “token” in itNate
11/30/2023, 4:26 PMAndrew
11/30/2023, 4:27 PMNate
11/30/2023, 4:29 PMNate
11/30/2023, 4:30 PMAndrew
11/30/2023, 4:30 PMName: prefect
Version: 2.14.8+4.g3c8f95331
Summary: Workflow orchestration and management.
Home-page: <https://www.prefect.io>
Author: Prefect Technologies, Inc.
Author-email: <mailto:help@prefect.io|help@prefect.io>
I feel like I just have something off though..Nate
11/30/2023, 4:31 PMpull:
- prefect.deployments.steps.run_shell_script:
id: get-git-branch
script: git rev-parse --abbrev-ref HEAD
stream_output: false
- prefect.deployments.steps.git_clone: &clone_repo
repository: <https://gitlab.com/org/repo.git>
branch: "{{ get-git-branch.stdout }}"
credentials: "{{ prefect.blocks.gitlab-credentials.gitlab-access-token }}"
Nate
11/30/2023, 4:31 PMaccess_token
-> credentials
Nate
11/30/2023, 4:31 PMAndrew
11/30/2023, 4:32 PMAndrew
11/30/2023, 4:35 PMAndrew
11/30/2023, 4:35 PMmain
, does that branch logic I have seem right?Nate
11/30/2023, 4:37 PMaccess_token
as well as credentials
for blocks there
what exactly is your intention, like what branch do you want to be cloning / how do you want to decide that?
does that branch logic I have seem right?
Andrew
11/30/2023, 4:38 PMAndrew
11/30/2023, 4:38 PMgit rev-parse --abbrev-ref HEAD
would get the current branch name, but I’m not sure if branch:
works like thatNate
11/30/2023, 4:39 PMstream_output
is false, that get-git-branch.stdout
is empty and we default to main
Nate
11/30/2023, 4:40 PMAndrew
11/30/2023, 4:40 PMNate
11/30/2023, 4:45 PMstream_output: false
if i switch to some test
branch
- name: host-env-test
entrypoint: src/demo_project/read_env.py:read_env
build:
- prefect.deployments.steps.run_shell_script:
id: get-branch
script: git rev-parse --abbrev-ref HEAD
stream_output: false
- prefect.deployments.steps.run_shell_script:
script: echo "we're on branch {{ get-branch.stdout }}"
gives
(prefect-monorepo) pad-2 :: src/demos/prefect-monorepo ‹test›
» prefect deploy -n host-env-test
Running deployment build steps...
> Running run_shell_script step...
> Running run_shell_script step...
we're on branch test
Nate
11/30/2023, 4:46 PMgit rev-parse
actually will look at before you clone the repo, since cloning happens secondAndrew
11/30/2023, 4:49 PMAndrew
11/30/2023, 4:49 PMNate
11/30/2023, 4:49 PM