We are using the free builder at the moment from Github CI actions.
Both for prod and pr review app deployments.
I am working on setting up a multi stage docker image to have separate steps for the hex and npm packages.
I am wondering how does the following scenario play out:
Change deps on a pr
destroy builder on fly to clear the cache
Deploy the pr
deploy prod
Will in this case the prod deploy use the layer (for anything) that was cached by the pr deployment?
Would the pr docker image/layers impact the prod deployment?
The caching from the PR deployment can affect the production deployment yep. There’s very little hidden magic to the builder, it’s just a VM with Docker running in it (it’s not refreshed between builds or anything).
This begs the question of what’s going on where deploying a PR might cache something you don’t want cached - I’m guessing that’s related to the multi-stage part?
What I’ve done is set a build argument in a stage, and then changed/used a specific build argument if I needed to bust the cache of that build step - perhaps depending on staging vs production, etc.
I think something like this might work:
###
# Build the foobar command
##
FROM golang:1.19 as some-client
# >>>>>>>>>>>>>>>>>>> Here's the build argument I'm talking about
ARG BUILD_ENV="staging"
WORKDIR /opt
# >>>>>>>>>>>>>>>>>>> Cache busted here
RUN echo "building $BUILD_ENV"
RUN --mount=type=secret,id=secrets,dst=/tmp/secrets bash -c 'source /tmp/secrets \
&& git clone --single-branch --branch main https://$GITHUB_ACCESS_TOKEN:x-oauth-basic@github.com/foo/bar.git /opt'
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o bin/foobar cmd/main.go
###
# Put everything together in last stage
##
FROM ubuntu:22.04
COPY --from=some-client /opt/bin/foobar /usr/local/bin/foobar
# and so on...