build: fix goose binary copy path for cross-compile
Backend CI / Test (push) Has been cancelled
Backend CI / Contract Tests (push) Has been cancelled
Backend CI / Build (push) Has been cancelled
Backend CI / Lint (push) Has been cancelled
Backend CI / Secret Scanning (push) Has been cancelled

go install with GOOS/GOARCH set drops binaries in /go/bin/<goos>_<goarch>/,
which broke the COPY in go-base. Switching to git clone + go build with
explicit -o /app/goose so the output path is stable regardless of host
platform.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-04-26 22:48:08 -05:00
parent 12b2f9d43b
commit 0f7450ada9
+11 -4
View File
@@ -51,9 +51,16 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o /
# Install goose CLI for production migrations. Pinned to a specific version # Install goose CLI for production migrations. Pinned to a specific version
# so an upstream behavioural change can't break a deploy unannounced. # so an upstream behavioural change can't break a deploy unannounced.
# Bumping is a deliberate, reviewable diff. # Bumping is a deliberate, reviewable diff. We `go build` rather than
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \ # `go install` so the output path is predictable across host platforms —
go install github.com/pressly/goose/v3/cmd/goose@v3.22.1 # `go install` with cross-compile env vars drops the binary in
# /go/bin/<goos>_<goarch>/, which is awkward to COPY from.
RUN cd /tmp && \
git clone --depth=1 --branch=v3.22.1 https://github.com/pressly/goose.git goose-src && \
cd goose-src && \
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \
go build -ldflags="-w -s" -o /app/goose ./cmd/goose && \
cd / && rm -rf /tmp/goose-src
# Base runtime stage for Go services # Base runtime stage for Go services
FROM alpine:3.19 AS go-base FROM alpine:3.19 AS go-base
@@ -72,7 +79,7 @@ COPY --from=builder /app/api /app/api
COPY --from=builder /app/worker /app/worker COPY --from=builder /app/worker /app/worker
# goose is the migration runner — same image is reused as the migrate Job # goose is the migration runner — same image is reused as the migrate Job
# entrypoint via `command: ["/usr/local/bin/goose", ...]`. # entrypoint via `command: ["/usr/local/bin/goose", ...]`.
COPY --from=builder /go/bin/goose /usr/local/bin/goose COPY --from=builder /app/goose /usr/local/bin/goose
# Copy templates directory # Copy templates directory
COPY --from=builder /app/templates /app/templates COPY --from=builder /app/templates /app/templates