From 9666a229c2c56b59e13e57f093c4e4b532a619bb Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:09:51 -0800 Subject: [PATCH 1/2] Updates the image building to use support multi-arch images for amd64, arm64 and armv7 Uses docker/metadata-action, docker/build-push-action and docker/login-action --- .github/workflows/build-and-deploy.yml | 89 ++++++++++---------------- 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index c1e63b1..48eff70 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -9,67 +9,46 @@ jobs: build: name: Build - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: FranzDiebold/github-env-vars-action@v2 - - - name: Set major tag name - run: echo "TAG_MAJOR=$(echo $CI_REF_NAME | cut -d. -f1)" >> $GITHUB_ENV - - - name: Set major tag name - run: echo "TAG_MINOR=${{ env.TAG_MAJOR }}.$(echo $CI_REF_NAME | cut -d. -f2)" >> $GITHUB_ENV - - - name: Build image - run: | - docker build --no-cache \ - -t baldissaramatheus/tasks.md:latest \ - -t baldissaramatheus/tasks.md:$CI_REF_NAME \ - -t baldissaramatheus/tasks.md:${{ env.TAG_MAJOR }} \ - -t baldissaramatheus/tasks.md:${{ env.TAG_MINOR }} \ - . - - name: Save Docker image as artifact - run: | - docker save -o /tmp/image.tar \ - baldissaramatheus/tasks.md:latest \ - baldissaramatheus/tasks.md:$CI_REF_NAME \ - baldissaramatheus/tasks.md:${{ env.TAG_MAJOR }} \ - baldissaramatheus/tasks.md:${{ env.TAG_MINOR }} - - name: Upload artifact - uses: actions/upload-artifact@v2 + - name: Gather Docker metadata + id: docker-meta + uses: docker/metadata-action@v4 with: - name: image - path: /tmp/image.tar - - deploy: - name: Deploy - - needs: [build] - - runs-on: ubuntu-20.04 + images: | + aldissaramatheus/tasks.md + tags: | + # Process semver like tags + # For a tag x.y.z or vX.Y.Z, output an x.y.z, x.y and x image tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Login to Docker Hub + uses: docker/login-action@v2 + # Don't attempt to login is not pushing to Docker Hub + if: github.event_name != 'pull_request' + with: + username: "${{ secrets.DOCKER_USERNAME }}" + password: ${{ secrets.DOCKER_PASSWORD }} - steps: - - uses: FranzDiebold/github-env-vars-action@v2 + # Login to GitHub container registry could happen here - - name: Set major tag name - run: echo "TAG_MAJOR=$(echo $CI_REF_NAME | cut -d. -f1)" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Set major tag name - run: echo "TAG_MINOR=${{ env.TAG_MAJOR }}.$(echo $CI_REF_NAME | cut -d. -f2)" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 - - name: Download artifact - uses: actions/download-artifact@v2 + - name: Build and push + uses: docker/build-push-action@v4 with: - name: image - path: /tmp - - - name: Load Docker image - run: | - docker load --input /tmp/image.tar - docker image ls -a - - name: Push Docker image - run: | - echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - docker push --all-tags baldissaramatheus/tasks.md + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm/v7,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.docker-meta.outputs.tags }} + labels: ${{ steps.docker-meta.outputs.labels }} From c67c0241330c7045cb126a9a19fe71bdb55ce77f Mon Sep 17 00:00:00 2001 From: Matheus Baldissara Date: Sun, 12 Mar 2023 13:38:48 -0300 Subject: [PATCH 2/2] Fix image name typo --- .github/workflows/build-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 48eff70..7e56e33 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -19,7 +19,7 @@ jobs: uses: docker/metadata-action@v4 with: images: | - aldissaramatheus/tasks.md + baldissaramatheus/tasks.md tags: | # Process semver like tags # For a tag x.y.z or vX.Y.Z, output an x.y.z, x.y and x image tag