From 056f8792b7f55690bf749f3a31ad06382ee3a898 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 28 Aug 2022 20:53:38 +0200 Subject: [PATCH] release target with checksums Signed-off-by: CrazyMax --- .github/workflows/build.yml | 13 +++----- Dockerfile | 64 +++++++++++++++++++++++++------------ Makefile | 39 ++++++---------------- README.md | 2 +- docker-bake.hcl | 6 ++++ hack/git-meta | 16 ++++++++++ hack/release | 59 ++++++++++++++++++++++++++++++++++ 7 files changed, 138 insertions(+), 61 deletions(-) create mode 100755 hack/git-meta create mode 100755 hack/release diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 67a3451..cac543c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -138,16 +138,11 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Build - uses: docker/bake-action@v2 - with: - targets: binaries - set: | - *.cache-from=type=gha,scope=build - *.cache-to=type=gha,scope=build,mode=max - - - name: Move artifacts run: | - mv ${{ env.DESTDIR }}/**/* ${{ env.DESTDIR }}/ + make release + env: + CACHE_FROM: type=gha,scope=build + CACHE_TO: type=gha,scope=build,mode=max - name: Upload artifacts uses: actions/upload-artifact@v3 diff --git a/Dockerfile b/Dockerfile index 8137f38..13296a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,54 +85,76 @@ EOT FROM scratch AS test-coverage COPY --from=test /out / +FROM gobase AS version +RUN --mount=target=. \ + echo -n "$(./hack/git-meta version)" | tee /tmp/.version ; echo -n "$(./hack/git-meta revision)" | tee /tmp/.revision + FROM base AS build-linux ARG PACKAGE -ARG TARGETOS -ARG TARGETARCH -ARG TARGETVARIANT RUN --mount=type=bind,target=. \ --mount=type=cache,target=/root/.cache \ - --mount=type=cache,target=/go/pkg/mod <" + exit 1 + ;; +esac diff --git a/hack/release b/hack/release new file mode 100755 index 0000000..aff1c64 --- /dev/null +++ b/hack/release @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +set -e + +: "${BUILDX_CMD=docker buildx}" +: "${DESTDIR=./bin/release}" +: "${CACHE_FROM=}" +: "${CACHE_TO=}" + +: "${SIGN=}" +: "${PFX=}" +: "${PFXPASSWORD=}" + +if [ -n "$CACHE_FROM" ]; then + for cfrom in $CACHE_FROM; do + cacheFlags+=(--set "*.cache-from=$cfrom") + done +fi +if [ -n "$CACHE_TO" ]; then + for cto in $CACHE_TO; do + cacheFlags+=(--set "*.cache-to=$cto") + done +fi + +dockerpfx=$(mktemp -t dockercredhelper-pfx.XXXXXXXXXX) +function clean { + rm -f "$dockerpfx" +} +trap clean EXIT + +# release +( + set -x + ${BUILDX_CMD} bake "${cacheFlags[@]}" --set "*.output=$DESTDIR" release +) + +# wrap binaries +mv -f ./${DESTDIR}/**/* ./${DESTDIR}/ +find ./${DESTDIR} -type d -empty -delete + +# sign binaries +if [ -n "$SIGN" ]; then + for f in "${DESTDIR}"/*".darwin-"*; do + SIGNINGHASH=$(security find-identity -v -p codesigning | grep "Developer ID Application: Docker Inc" | cut -d ' ' -f 4) + xcrun -log codesign -s "$SIGNINGHASH" --force --verbose "$f" + xcrun codesign --verify --deep --strict --verbose=2 --display "$f" + done + for f in "${DESTDIR}"/*".windows-"*; do + echo ${PFX} | base64 -d > "$dockerpfx" + signtool sign /fd SHA256 /a /f pfx /p ${PFXPASSWORD} /d Docker /du https://www.docker.com /t http://timestamp.verisign.com/scripts/timestamp.dll "$f" + done +fi + +# checksums +( + cd ${DESTDIR} + sha256sum -b docker-credential-* > ./checksums.txt + sha256sum -c --strict checksums.txt +)