diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index c1e63b1..7e56e33 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: | + 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 + 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 }}