From 30e8cbf250bd299706295220a95b41561608783a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 2 Apr 2023 14:58:22 +0200 Subject: [PATCH] fix: broken release pipeline on docker push --- .releaserc.yml | 20 ++------------------ hack/build-docker-image.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) create mode 100755 hack/build-docker-image.sh diff --git a/.releaserc.yml b/.releaserc.yml index 9c66e0f..8846278 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -11,16 +11,7 @@ plugins: - npmPublish: false - - "@semantic-release/exec" - prepareCmd: | - # Build Docker Container - # Build now but dont push; this validates that the image builds - # successfully and we can later re-use the cached build results to - # push in "publish" stage - docker buildx build \ - -t apricote/listory \ - --build-arg VERSION=${nextRelease.version} \ - --build-arg GIT_COMMIT=`git rev-parse HEAD` \ - --platform=linux/amd64,linux/arm64 \ - . + hack/build-docker-image.sh prepare ${nextRelease.version} # Update version in Helm Chart CHART_FILE=charts/listory/Chart.yaml @@ -40,14 +31,7 @@ plugins: docker-compose.prod.yml publishCmd: | - # Build (with cache) & push Docker Images - docker buildx build \ - -t apricote/listory:${nextRelease.version} \ - -t apricote/listory:latest \ - --build-arg VERSION=${nextRelease.version} \ - --build-arg GIT_COMMIT=`git rev-parse HEAD` \ - --platform=linux/amd64,linux/arm64 \ - --push \ + hack/build-docker-image.sh publish ${nextRelease.version} - - "@semantic-release/git" - assets: diff --git a/hack/build-docker-image.sh b/hack/build-docker-image.sh new file mode 100755 index 0000000..7bd3d78 --- /dev/null +++ b/hack/build-docker-image.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -o pipefail +set -e + +PREPARE_OR_PUBLISH="$1" +VERSION="$2" + +REPO="apricote/listory" + +PLATFORMS="--platform=linux/amd64,linux/arm64" +TAGS="--tag ${REPO}:${VERSION} --tag ${REPO}:latest" +ARGS="--build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=`git rev-parse HEAD`" + +CACHE="" +PUSH="" + +# We "build" the image twice, once in "prepare" and then again in "publish" stage. +# - Prepare makes sure that the image is buildable and utilizes the remote cache. +# - Publish utilizes the local cache from prepare stage and pushes the image. +if [ "$PREPARE_OR_PUBLISH" = "prepare" ]; then + CACHE="--cache-from=type=registry,ref=${REPO}:buildcache --cache-to=type=registry,ref=${REPO}:buildcache" +else + # Uses local buildkit cache + PUSH="--push" +fi + +docker buildx build $PLATFORMS $TAGS $ARGS $CACHE $PUSH .