LEAS-2795 mc: Dockerfile with pins, build and final stages
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
ARG GO_BUILDER
|
||||
ARG BASE_IMAGE
|
||||
|
||||
FROM ${GO_BUILDER} AS pins
|
||||
ARG UPSTREAM_RELEASE
|
||||
ARG UPSTREAM_COMMIT
|
||||
ARG MODULE
|
||||
ARG MODULE_VERSION
|
||||
ARG MODULE_SUM
|
||||
ENV GOTOOLCHAIN=local GOFLAGS=-mod=readonly CGO_ENABLED=0 GOOS=linux GOARCH=amd64
|
||||
COPY src /src
|
||||
WORKDIR /src
|
||||
RUN set -eu; \
|
||||
test "$(git rev-parse HEAD)" = "${UPSTREAM_COMMIT}" || { echo "REFUSED pins: src HEAD is not UPSTREAM_COMMIT"; exit 1; }; \
|
||||
test -z "$(git status --porcelain)" || { echo "REFUSED pins: src working tree is not clean"; git status --porcelain; exit 1; }; \
|
||||
test "$(go list -m)" = "${MODULE}" || { echo "REFUSED pins: src module is not MODULE"; exit 1; }; \
|
||||
scratch="$(mktemp -d)"; \
|
||||
(cd "${scratch}" && env -u GOFLAGS go mod download -json "${MODULE}@${MODULE_VERSION}" > "${scratch}/module.json"); \
|
||||
sum="$(sed -n 's/^[[:space:]]*"Sum": "\([^"]*\)".*/\1/p' "${scratch}/module.json")"; \
|
||||
hash="$(sed -n 's/^[[:space:]]*"Hash": "\([^"]*\)".*/\1/p' "${scratch}/module.json")"; \
|
||||
test "${sum}" = "${MODULE_SUM}" || { echo "REFUSED pins: module sum is ${sum}, PINS says MODULE_SUM=${MODULE_SUM}"; exit 1; }; \
|
||||
test "${hash}" = "${UPSTREAM_COMMIT}" || { echo "REFUSED pins: module origin hash is ${hash}, PINS says UPSTREAM_COMMIT=${UPSTREAM_COMMIT}"; exit 1; }; \
|
||||
go mod download; \
|
||||
go mod verify
|
||||
|
||||
FROM pins AS build
|
||||
ARG UPSTREAM_RELEASE
|
||||
ARG UPSTREAM_COMMIT
|
||||
RUN set -eu; \
|
||||
LDFLAGS="$(MC_RELEASE=RELEASE go run buildscripts/gen-ldflags.go "${UPSTREAM_RELEASE#RELEASE.}")"; \
|
||||
case "${LDFLAGS}" in *"cmd.ReleaseTag=${UPSTREAM_RELEASE} "*) ;; *) echo "REFUSED build: ldflags lack ReleaseTag=${UPSTREAM_RELEASE}"; exit 1;; esac; \
|
||||
case "${LDFLAGS}" in *"cmd.CommitID=${UPSTREAM_COMMIT} "*) ;; *) echo "REFUSED build: ldflags lack CommitID=${UPSTREAM_COMMIT}"; exit 1;; esac; \
|
||||
mkdir -p /out; \
|
||||
go build -trimpath -tags kqueue -ldflags "${LDFLAGS}" -o /out/mc .; \
|
||||
go version -m /out/mc > /out/buildinfo.txt; \
|
||||
grep -Eq "^[[:space:]]+build[[:space:]]+vcs.revision=${UPSTREAM_COMMIT}$" /out/buildinfo.txt || { echo "REFUSED build: vcs.revision is not UPSTREAM_COMMIT"; exit 1; }; \
|
||||
grep -Eq "^[[:space:]]+build[[:space:]]+vcs.modified=false$" /out/buildinfo.txt || { echo "REFUSED build: vcs.modified is not false"; exit 1; }; \
|
||||
grep -Eq "^[[:space:]]+build[[:space:]]+-trimpath=true$" /out/buildinfo.txt || { echo "REFUSED build: -trimpath is not true"; exit 1; }; \
|
||||
grep -Eq "^[[:space:]]+build[[:space:]]+CGO_ENABLED=0$" /out/buildinfo.txt || { echo "REFUSED build: CGO_ENABLED is not 0"; exit 1; }; \
|
||||
grep -Eq "^[[:space:]]+build[[:space:]]+-tags=kqueue$" /out/buildinfo.txt || { echo "REFUSED build: -tags is not kqueue"; exit 1; }; \
|
||||
cat /out/buildinfo.txt; \
|
||||
sha256sum /out/mc | cut -d' ' -f1 > /out/mc.sha256
|
||||
|
||||
FROM ${BASE_IMAGE}
|
||||
ARG UPSTREAM_RELEASE
|
||||
ARG UPSTREAM_COMMIT
|
||||
ARG RECIPE_COMMIT
|
||||
ARG BINARY_SHA256
|
||||
LABEL org.opencontainers.image.source="https://git.vezha.io/para/mc" \
|
||||
org.opencontainers.image.revision="${UPSTREAM_COMMIT}" \
|
||||
org.opencontainers.image.version="${UPSTREAM_RELEASE}" \
|
||||
org.opencontainers.image.licenses="AGPL-3.0" \
|
||||
io.vezha.recipe="${RECIPE_COMMIT}" \
|
||||
io.vezha.binary.sha256="${BINARY_SHA256}"
|
||||
COPY --from=build /out/mc /usr/bin/mc
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY src/LICENSE /licenses/LICENSE
|
||||
COPY src/CREDITS /licenses/CREDITS
|
||||
COPY vezha/SOURCE /licenses/SOURCE
|
||||
ENTRYPOINT ["mc"]
|
||||
Reference in New Issue
Block a user