From 2aba80d0ca1e34c4bf3bbc77fa361c2dbde0e07c Mon Sep 17 00:00:00 2001 From: Tom Plant <21111317+pl4nty@users.noreply.github.com> Date: Sat, 22 Apr 2023 09:41:33 +1000 Subject: [PATCH 1/6] Support GitHub Container Registry --- .github/workflows/push-docker.yml | 65 +++++++++++++------------------ 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml index 0aefaa00..16093070 100644 --- a/.github/workflows/push-docker.yml +++ b/.github/workflows/push-docker.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - testGit - main jobs: push: @@ -37,43 +36,35 @@ jobs: uses: docker/login-action@v2.1.0 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_API }} - - # - name: Check if tag exists - # id: checkIdExists - # continue-on-error: true - # run: | - # response=$(curl -s https://hub.docker.com/v2/repositories/frooodle/s-pdf/tags/?name=${{ steps.versionNumber.outputs.versionNumber }}) - # result=$(echo $response | jq ".results") - # if [ "$result" == "[]" ]; then - # echo "Tag ${{ steps.versionNumber.outputs.versionNumber }} doesnt exist. Continuing with build and push." - # else - # echo "Tag ${{ steps.versionNumber.outputs.versionNumber }} already exists. Skipping build and push." - # exit 1; - # fi - - - - - name: Setup buildx - run: | - docker buildx create --name mybuilder - docker buildx use mybuilder - - - name: Build and push versioned amd64 and v8 - if: github.ref == 'refs/heads/main' - run: | - docker buildx build --platform="linux/amd64,linux/arm64/v8" --push --tag "frooodle/s-pdf:${{ steps.versionNumber.outputs.versionNumber }}-alpha" . - + password: ${{ secrets.DOCKER_HUB_API }} - - name: Build and push versioned amd64 and v8 - if: github.ref == 'refs/heads/master' - run: | - docker buildx build --platform="linux/amd64,linux/arm64/v8" --push --tag "frooodle/s-pdf:${{ steps.versionNumber.outputs.versionNumber }}" . + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Generate tags + id: meta + uses: docker/metadata-action@v4 + with: + images: | + frooodle/s-pdf + ghcr.io/${{ github.repository_owner }}/s-pdf + tags: | + ${{ steps.versionNumber.outputs.versionNumber }}${{ github.ref == 'refs/heads/main' && '-alpha' || '' }} - - name: Build and push latest amd64 and v8 - if: github.ref == 'refs/heads/master' - run: | - docker buildx build --platform="linux/amd64,linux/arm64/v8" --push --tag "frooodle/s-pdf:latest" . - + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and push + uses: docker/build-push-action@v4 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64/v8 From 5897f0e3ed819a779f2af32f42deb9c0954f768c Mon Sep 17 00:00:00 2001 From: Tom Plant <21111317+pl4nty@users.noreply.github.com> Date: Sat, 22 Apr 2023 09:45:11 +1000 Subject: [PATCH 2/6] Pin action versions --- .github/workflows/push-docker.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml index 16093070..b09361a4 100644 --- a/.github/workflows/push-docker.yml +++ b/.github/workflows/push-docker.yml @@ -11,16 +11,16 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3.5.2 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v3.11.0 with: java-version: '17' distribution: 'temurin' - - uses: gradle/gradle-build-action@v2.3.3 + - uses: gradle/gradle-build-action@v2.4.2 with: gradle-version: 7.6 arguments: clean build @@ -39,7 +39,7 @@ jobs: password: ${{ secrets.DOCKER_HUB_API }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v2.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -47,7 +47,7 @@ jobs: - name: Generate tags id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v4.4.0 with: images: | frooodle/s-pdf @@ -56,13 +56,13 @@ jobs: ${{ steps.versionNumber.outputs.versionNumber }}${{ github.ref == 'refs/heads/main' && '-alpha' || '' }} - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v2.1.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v2.5.0 - name: Build and push - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v4.0.0 with: push: true tags: ${{ steps.meta.outputs.tags }} From 3b8bed5b0ad8c1c7e1107bba16db29fc18a45ed0 Mon Sep 17 00:00:00 2001 From: Tom Plant <21111317+pl4nty@users.noreply.github.com> Date: Sat, 22 Apr 2023 09:46:27 +1000 Subject: [PATCH 3/6] Allow manual CI/CD runs --- .github/workflows/push-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml index b09361a4..04ce9f7e 100644 --- a/.github/workflows/push-docker.yml +++ b/.github/workflows/push-docker.yml @@ -1,6 +1,7 @@ name: Push Docker Image with VersionNumber on: + workflow_dispatch: push: branches: - master From 4f35a8d79f4b4fe381669df085c802282e0d556c Mon Sep 17 00:00:00 2001 From: Tom Plant <21111317+pl4nty@users.noreply.github.com> Date: Sat, 22 Apr 2023 09:50:15 +1000 Subject: [PATCH 4/6] Enable caching for CI/CD container builds --- .github/workflows/push-docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml index 04ce9f7e..3066fb7d 100644 --- a/.github/workflows/push-docker.yml +++ b/.github/workflows/push-docker.yml @@ -66,6 +66,8 @@ jobs: uses: docker/build-push-action@v4.0.0 with: push: true + cache-from: type=gha + cache-to: type=gha,mode=max tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64/v8 From 96097d1cd36ae803acfa43d8c2e6a100e3e566fc Mon Sep 17 00:00:00 2001 From: Tom Plant <21111317+pl4nty@users.noreply.github.com> Date: Sat, 22 Apr 2023 10:10:02 +1000 Subject: [PATCH 5/6] Set buildx context in CI/CD --- .github/workflows/push-docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml index 3066fb7d..199d1add 100644 --- a/.github/workflows/push-docker.yml +++ b/.github/workflows/push-docker.yml @@ -65,6 +65,7 @@ jobs: - name: Build and push uses: docker/build-push-action@v4.0.0 with: + context: . push: true cache-from: type=gha cache-to: type=gha,mode=max From 42564e683b33d7874c7eaed055729b0a1233051b Mon Sep 17 00:00:00 2001 From: Tom Plant <21111317+pl4nty@users.noreply.github.com> Date: Sat, 22 Apr 2023 10:12:14 +1000 Subject: [PATCH 6/6] Create Docker Hub tag from secret --- .github/workflows/push-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml index 199d1add..d0d8d165 100644 --- a/.github/workflows/push-docker.yml +++ b/.github/workflows/push-docker.yml @@ -51,7 +51,7 @@ jobs: uses: docker/metadata-action@v4.4.0 with: images: | - frooodle/s-pdf + ${{ secrets.DOCKER_HUB_USERNAME }}/s-pdf ghcr.io/${{ github.repository_owner }}/s-pdf tags: | ${{ steps.versionNumber.outputs.versionNumber }}${{ github.ref == 'refs/heads/main' && '-alpha' || '' }}