From b3cf97ce4085bd80438fa7591841df153d1dfcbe Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sun, 26 Mar 2023 17:18:01 -0400 Subject: [PATCH] Improvements to github actions (#79) * Improvements to github actions * Change username to repo owner username --- .github/dependabot.yml | 7 +++ .github/workflows/docker-image.yml | 79 ++++++++++++++++-------------- 2 files changed, 48 insertions(+), 38 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2c7d170 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 2679275..82d7569 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,53 +1,56 @@ name: Create and publish a Docker image on: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + workflow_dispatch: release: - types: [published] - -env: - REGISTRY: ghcr.io - OWNER: ${{ github.repository.owner }} + types: [published, edited] jobs: - build-and-push-image: + build-and-publish-image: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - dockerfile: ./Dockerfile - image: serge - context: . - permissions: - contents: read - packages: write - steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v3 - - - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} + images: | + ghcr.io/nsarrazin/serge + tags: | + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: nsarrazin password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 - with: - images: ${{ env.REGISTRY }}/${{ github.event.repository.owner.name }}/${{ matrix.image }} - - name: Build and Publish Docker Image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v4 with: - file: ${{ matrix.dockerfile }} - context: ${{ matrix.context }} - push: true - tags: | - ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}:release - ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}:${{ github.event.release.tag_name }} - + context: . + push: ${{ github.event_name != 'pull_request' }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} -