https://prefect.io logo
g

Gregory Hunt

07/13/2023, 7:55 PM
When using the new deployment management, if I have multiple deployments that use the same build it build the container again for every deployment, if there a way to prevent that and only build and push the image once?
Bumping this
@Jeff Hale @Nate
n

Nate

07/17/2023, 3:51 PM
are you using different build time environments for each deployment? otherwise wouldnt docker cache your layers?
g

Gregory Hunt

07/17/2023, 3:52 PM
Yes it does, but prefect deploy builds the image multiple times and pushes it
n

Nate

07/17/2023, 3:55 PM
hmm gotcha - maybe you could just run the docker commands in a shell script via
prefect.deployments.steps.run_shell_script
which adds some logic in a shell script?
g

Gregory Hunt

07/17/2023, 3:55 PM
The subsequent builds and pushes are faster
So those are also run again
Which is the issue, I have a time stamp in a run_shell to tag the image and I end up with an image with multiple tags and the deployments all reference different tags
What I am looking for is all of them to reference the same image tag
n

Nate

07/17/2023, 4:00 PM
can you just have the image tag be the GITHUB_SHA and then have the shell script do something like
Copy code
if docker inspect "$IMAGE:$TAG" >/dev/null 2>&1; then
    echo "Image exists"
else
    echo "Image does not exist. Building the image."
    docker build -t "$IMAGE:$TAG" .
fi

exit 0
and add this to your
defintions
in prefect.yaml and give it to each deployment as the
build
step?
g

Gregory Hunt

07/17/2023, 4:01 PM
I can do something like that
Is there a reason the build gets run on every deployment
n

Nate

07/17/2023, 4:02 PM
for each deployment definition, if you have a
build
section, it will run when you do
prefect deploy
g

Gregory Hunt

07/17/2023, 4:03 PM
When referencing the same build section, you would think it would know and pull in the values from the previous build
n

Nate

07/17/2023, 4:05 PM
that sounds like a reasonable feature request! the tricky part i think would be deciding where to keep that state i.e. "is this build the same as the last one?" but seems doable
but i think the key thing at this point in time is that the build push and pull sections are things that an individual deployment has