|
| 1 | +# Source code for the repos |
| 2 | +ARG UI_SOURCE_CODE=./frontend |
| 3 | +ARG BFF_SOURCE_CODE=./bff |
| 4 | + |
| 5 | +# Set the base images for the build stages |
| 6 | +ARG NODE_BASE_IMAGE=node:22 |
| 7 | +ARG GOLANG_BASE_IMAGE=golang:1.24.6 |
| 8 | +ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot |
| 9 | + |
| 10 | +# UI build stage |
| 11 | +FROM ${NODE_BASE_IMAGE} AS ui-builder |
| 12 | + |
| 13 | +ARG UI_SOURCE_CODE |
| 14 | +ARG DEPLOYMENT_MODE |
| 15 | +ARG STYLE_THEME |
| 16 | + |
| 17 | +WORKDIR /usr/src/app |
| 18 | + |
| 19 | +# Copy the source code to the container |
| 20 | +COPY ${UI_SOURCE_CODE} /usr/src/app |
| 21 | + |
| 22 | +# Install the dependencies and build |
| 23 | +RUN npm cache clean --force |
| 24 | +RUN npm ci --omit=optional |
| 25 | +RUN DEPLOYMENT_MODE=${DEPLOYMENT_MODE} STYLE_THEME=${STYLE_THEME} npm run build:prod |
| 26 | + |
| 27 | +# BFF build stage |
| 28 | +FROM ${GOLANG_BASE_IMAGE} AS bff-builder |
| 29 | + |
| 30 | +ARG BFF_SOURCE_CODE |
| 31 | + |
| 32 | +ARG TARGETOS |
| 33 | +ARG TARGETARCH |
| 34 | + |
| 35 | +WORKDIR /usr/src/app |
| 36 | + |
| 37 | +# Copy the Go Modules manifests |
| 38 | +COPY ${BFF_SOURCE_CODE}/go.mod ${BFF_SOURCE_CODE}/go.sum ./ |
| 39 | + |
| 40 | +# Download dependencies |
| 41 | +RUN go mod download |
| 42 | + |
| 43 | +# Copy the go source files |
| 44 | +COPY ${BFF_SOURCE_CODE}/cmd/ cmd/ |
| 45 | +COPY ${BFF_SOURCE_CODE}/internal/ internal/ |
| 46 | + |
| 47 | +# Build the Go application |
| 48 | +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o bff ./cmd |
| 49 | + |
| 50 | +# Install setup-envtest and download K8s binaries for mock mode |
| 51 | +RUN go install sigs.k8s.io/controller-runtime/tools/ [email protected] |
| 52 | +RUN setup-envtest use 1.29.0 --bin-dir /envtest-bin -p path |
| 53 | + |
| 54 | +# Final stage |
| 55 | +# Use distroless as minimal base image to package the application binary |
| 56 | +FROM ${DISTROLESS_BASE_IMAGE} |
| 57 | +WORKDIR / |
| 58 | +COPY --from=bff-builder /usr/src/app/bff ./ |
| 59 | +COPY --from=ui-builder /usr/src/app/dist ./static/ |
| 60 | +# Copy envtest binaries for mock K8s mode |
| 61 | +COPY --from=bff-builder /envtest-bin /envtest-bin |
| 62 | +ENV ENVTEST_ASSETS_DIR=/envtest-bin |
| 63 | +USER 65532:65532 |
| 64 | + |
| 65 | +# Expose port 8080 |
| 66 | +EXPOSE 8080 |
| 67 | + |
| 68 | +ENTRYPOINT ["/bff"] |
0 commit comments