One Dockerfile, three stages
A single multi-stage Dockerfile covers the whole lifecycle. The
build stage compiles a static Go binary with
CGO_ENABLED=0 and stripped symbols. The
dev stage runs it with air for hot
reload. The prod stage starts from
scratch and copies in only the binary, the CA
certificates and the assets.
The result is a tiny image with no OS underneath and a near-zero cold start, which is exactly what a scale-to-zero Cloud Run service wants.
FROM scratch AS prod
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /server /server
COPY app/templates/ /templates/
COPY app/static/ /static/
ENTRYPOINT ["/server"]