From 20a3fd579b3899308249ce5b1d98bfc9f3f8958f Mon Sep 17 00:00:00 2001 From: Patryk Zawadzki <81205+patrys@users.noreply.github.com> Date: Wed, 28 Aug 2024 12:12:34 +0200 Subject: [PATCH] Bring Docker image publishing in line with Saleor Core (#5101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Bring Docker image publishing in line with Saleor Core This will automatically tag images with with both the full version and just the minor (e.g., "3.20"). It may change the reported version strings for untagged releases so please review if the behavior of `PROJECT_VERSION` is acceptable. * Create giant-colts-pump.md --------- Co-authored-by: Patryk Andrzejewski Co-authored-by: Paweł Chyła --- .changeset/giant-colts-pump.md | 5 ++ .github/workflows/publish-containers.yml | 62 +++++++++++------------- 2 files changed, 32 insertions(+), 35 deletions(-) create mode 100644 .changeset/giant-colts-pump.md diff --git a/.changeset/giant-colts-pump.md b/.changeset/giant-colts-pump.md new file mode 100644 index 00000000000..5a9c5483699 --- /dev/null +++ b/.changeset/giant-colts-pump.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": patch +--- + +Docker images will be automatically tag with with both the full version and just the minor diff --git a/.github/workflows/publish-containers.yml b/.github/workflows/publish-containers.yml index dc91aaba13a..d7ecb44e4cb 100644 --- a/.github/workflows/publish-containers.yml +++ b/.github/workflows/publish-containers.yml @@ -7,53 +7,44 @@ on: jobs: docker: runs-on: ubuntu-20.04 + permissions: contents: read packages: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Outputs the name of the repository (owner/repo) - - name: Get image name + - name: Build Image Name id: image run: | IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') - echo "image_name=ghcr.io/${IMAGE_NAME}" >> $GITHUB_OUTPUT - - # Tags stable versions as :latest - # Pre-releases, alphas, etc. as :snapshot - - name: Output image tags from git tag events - if: ${{ startsWith(github.ref, 'refs/tags/') }} - env: - GH_TOKEN: ${{ github.token }} - run: | - LATEST_VERSION=$(gh api repos/saleor/saleor-dashboard/releases/latest | jq -r .tag_name) - CURRENT_TAG=${GITHUB_REF#refs/tags/} + echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT - if [ "$LATEST_VERSION" = "$CURRENT_TAG" ]; then - TAGS=${{ steps.image.outputs.image_name }}:${CURRENT_TAG},${{ steps.image.outputs.image_name }}:latest - else - TAGS=${{ steps.image.outputs.image_name }}:${CURRENT_TAG} - fi - - echo " - DASHBOARD_VERSION=${CURRENT_TAG} - CONTAINER_TAGS=${TAGS} - " >> "${GITHUB_ENV}" + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ steps.image.outputs.image_name }} + tags: | + type=ref,event=branch + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} - - name: Set up Docker QEMU - uses: docker/setup-qemu-action@v1 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 with: platforms: arm64 - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -61,21 +52,22 @@ jobs: - name: Build and Push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: builder: ${{ steps.buildx.outputs.name }} - context: ./ + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64 push: true - tags: ${{ env.CONTAINER_TAGS }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + tags: ${{ steps.meta.outputs.tags }} build-args: | COMMIT_ID=${{ github.sha }} - PROJECT_VERSION=$DASHBOARD_VERSION + PROJECT_VERSION=${{ steps.meta.outputs.version }} - - name: Output image digest + - name: Image digest run: | echo $"\ Digest: ${{ steps.docker_build.outputs.digest }} - Tags: ${{ env.CONTAINER_TAGS }}" + Tags: ${{ steps.meta.outputs.tags }}"