From 8f8bcb67e27cc96bb2c1299b1079b985360fff02 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Thu, 19 Dec 2024 14:13:20 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20docker=20build=20for=20releases=20?= =?UTF-8?q?=F0=9F=A4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .buildkite/docker-image.yml | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/.buildkite/docker-image.yml b/.buildkite/docker-image.yml index 9e8eededf8..7f4f09e6ce 100644 --- a/.buildkite/docker-image.yml +++ b/.buildkite/docker-image.yml @@ -20,13 +20,26 @@ steps: . - wait - label: "🚀 Build & publish the release image to Docker Hub" - if: build.tag =~ /@core\/sync-service@/ + if: build.branch == "main" command: - export ELECTRIC_IMAGE_NAME="${DOCKERHUB_REPO}/${IMAGE_NAME}" - cd ./packages/sync-service + - git fetch --tags - export ELECTRIC_VERSION=$(jq '.version' -r package.json) - - docker buildx build --platform linux/arm64/v8,linux/amd64 --push - --build-arg ELECTRIC_VERSION=$${ELECTRIC_VERSION} - -t $${ELECTRIC_IMAGE_NAME}:$${ELECTRIC_VERSION} - -t $${ELECTRIC_IMAGE_NAME}:latest - . + # Get the latest version from DockerHub + - | + DOCKERHUB_VERSION=$(curl -s "https://hub.docker.com/v2/repositories/${DOCKERHUB_REPO}/${IMAGE_NAME}/tags/?page_size=100" | \ + jq -r '.results[] | select(.name | test("^[0-9]+\\.[0-9]+\\.[0-9]+.*$")) | .name' | \ + sort -V | tail -n1 || echo "0.0.0") + # Compare versions and only build if local is newer + - | + if [ "$(printf '%s\n' "$DOCKERHUB_VERSION" "$ELECTRIC_VERSION" | sort -V | tail -n1)" = "$ELECTRIC_VERSION" ]; then + echo "Building new version $ELECTRIC_VERSION (current version on DockerHub is $DOCKERHUB_VERSION)" + docker buildx build --platform linux/arm64/v8,linux/amd64 --push \ + --build-arg ELECTRIC_VERSION=$${ELECTRIC_VERSION} \ + -t $${ELECTRIC_IMAGE_NAME}:$${ELECTRIC_VERSION} \ + -t $${ELECTRIC_IMAGE_NAME}:latest \ + . + else + echo "Current version $ELECTRIC_VERSION is not newer than DockerHub version $DOCKERHUB_VERSION. Skipping build." + fi