From 6f70bad0a0586d70510e2a077396178cd720a5e6 Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Thu, 7 Sep 2023 09:40:17 -0400 Subject: [PATCH] [Bugfix] Docker image builds (#739) --- .../workflows/{cd-docker-hub.yml => cd.yml} | 37 +++++++++------- .github/workflows/{cd-ghcr.yml => ci.yml} | 44 ++++++++++--------- .github/workflows/test.yml | 6 ++- 3 files changed, 49 insertions(+), 38 deletions(-) rename .github/workflows/{cd-docker-hub.yml => cd.yml} (66%) rename .github/workflows/{cd-ghcr.yml => ci.yml} (52%) diff --git a/.github/workflows/cd-docker-hub.yml b/.github/workflows/cd.yml similarity index 66% rename from .github/workflows/cd-docker-hub.yml rename to .github/workflows/cd.yml index ae560acae..2fd9dbb6b 100644 --- a/.github/workflows/cd-docker-hub.yml +++ b/.github/workflows/cd.yml @@ -1,19 +1,12 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# GitHub recommends pinning actions to a commit SHA. -# To get a newer version, you will need to update the SHA. -# You can also reference a tag or branch, but the action may change without warning. - -name: Build and push Docker image to Docker Hub +name: Build and push Docker images on: + # release: + # types: [ published ] + push: + tags: + - 'v*' workflow_dispatch: - release: - branches: [ main ] - types: [ published ] env: PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7 @@ -21,6 +14,9 @@ env: jobs: build_and_push_image: runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write steps: - name: Checkout repository @@ -38,6 +34,13 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: docker-image-to-lowercase name: Convert Docker image to lower case run: echo "DOCKER_IMAGE=$(echo ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV @@ -46,12 +49,14 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.DOCKER_IMAGE }} + images: | + ${{ env.DOCKER_IMAGE }} + ghcr.io/${{ github.repository }} tags: | type=semver,pattern={{version}} - latest + type=semver,pattern={{major}}.{{minor}} - - name: Build and push image to Docker Hub + - name: Build and push Docker images uses: docker/build-push-action@v3 with: context: . diff --git a/.github/workflows/cd-ghcr.yml b/.github/workflows/ci.yml similarity index 52% rename from .github/workflows/cd-ghcr.yml rename to .github/workflows/ci.yml index 1b9baa8b8..8992ecefb 100644 --- a/.github/workflows/cd-ghcr.yml +++ b/.github/workflows/ci.yml @@ -1,27 +1,16 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# GitHub recommends pinning actions to a commit SHA. -# To get a newer version, you will need to update the SHA. -# You can also reference a tag or branch, but the action may change without warning. - -name: Build and push Docker image to GHCR +name: Build and test Docker images on: + push: + branches: + - 'release-**' workflow_dispatch: - release: - branches: [ main ] - types: [ published ] env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7 jobs: - build_and_push_image: + build_and_test_images: runs-on: ubuntu-22.04 permissions: contents: read @@ -37,24 +26,39 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Log in to the Container registry uses: docker/login-action@v2 with: - registry: ${{ env.REGISTRY }} + registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - id: docker-image-to-lowercase + name: Convert Docker image to lower case + run: echo "DOCKER_IMAGE=$(echo ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: | + ${{ env.DOCKER_IMAGE }} + ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} - - name: Build and push image to GHCR + - name: Build and push Docker images uses: docker/build-push-action@v3 with: context: . - push: true + push: false platforms: ${{ env.PLATFORMS }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c00146aa5..f7e7bf93b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,9 @@ name: Test + on: - - push - - workflow_dispatch + push: + workflow_dispatch: + jobs: test: strategy: