<@ULVA73B9P> is there a way to prevent `prefect de...
# ask-marvin
t
@Marvin is there a way to prevent
prefect deploy --all
from pushing the docker image multiple times? my deploy has been getting
Copy code
OSError: tag invalid: The image tag '49595c4' already exists in the 'dwh' repository and cannot be overwritten because the repository is immutable.
I'm tagging my docker image using the git commit hash
m
It seems there are no specific GitHub issues directly addressing this problem. However, the Prefect documentation provides some details about controlling Docker image builds and pushes. When using
prefect deploy
, you can customize the build and push process in the
prefect.yaml
file. This can help prevent multiple pushes of the same Docker image. Here are some relevant points and examples: 1. Use a Git Commit Hash for Tagging: You can set your Docker image's tag to a Git commit hash using a script. Here’s an example from the documentation:
Copy code
yaml
   build:
     - 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:
         requires: prefect-docker
         image_name: my-image
         image_tag: "{{ get-commit-hash.stdout }}"
         dockerfile: auto
2. Deployment Instruction Overrides: You can override the
build
,
push
, and
pull
sections in the
prefect.yaml
file to cater to specific needs. This customization allows you to implement different behavior for different deployments, such as avoiding repeated Docker pushes:
Copy code
yaml
   build:
     image_name: <your_image_name_here>
     image_tag: {{ your_commit_hash }}
     push: false  # or implement conditional logic
3. Customizing Push Logic: Consider implementing custom logic for pushing to handle immutable repositories correctly. You can add checks and conditions or use different strategies based on your needs:
Copy code
yaml
   push:
     - prefect_shell_script:
         script: |
           if ! docker images -q <your_image_name>:{{ your_commit_hash }}; then
             docker push <your_image_name>:{{ your_commit_hash }}
           fi
Sources: - Prefect Deployment Guide - Prefect Kubernetes Deployment These references provide more specifics and could be instrumental in avoiding redundant image pushes.
k
cc @Nate I know you have thoughts on this
t
I saw this github issue that was related https://github.com/PrefectHQ/prefect/issues/9921
we only started seeing this when we started using
all-deployments: true
in the prefect deploy action https://github.com/PrefectHQ/actions-prefect-deploy/tree/main
n
check this out: • define custom steps to cache image builds • use them
will get these into
prefect-docker
as soon as possible so this behavior is default
t
nice!!!
thank you @Nate, I'll try these out today and see what happens
n
👍 ill just call out that step names like
prefect_docker.deployments.steps.build_docker_image
and the cached ones i have here that wrap those are just fully qualified names of python functions, so whatever python you have that runs
prefect deploy
will need access to those modules, which is why I have the steps defined in a package (but strictly speaking you shouldnt need a package)
t
does your custom step have an issue with
buildargs
? we use those to pass in github creds to install some private packages but I think it's causing some hangups due to an unhashable type dict.
n
aha - good point i didn't handle that but we should be able to handle that easily enough in the eventual version
👍 1
just thinking out loud for later: we could probably have some
BuildKwargs(BaseModel, frozen=True)
in the signature of the step which can scoop a
dict
from yaml but also is hashable