From 9411333865c5143f0bc47adc2b281e7a2568041a Mon Sep 17 00:00:00 2001 From: Edward Cheng Date: Fri, 30 Aug 2024 01:21:13 +1000 Subject: [PATCH] test docker build and merge --- .../workflows/build-and-publish-develop.yml | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-develop.yml b/.github/workflows/build-and-publish-develop.yml index 7c6a2bf..11f7e71 100644 --- a/.github/workflows/build-and-publish-develop.yml +++ b/.github/workflows/build-and-publish-develop.yml @@ -34,4 +34,104 @@ jobs: run: | mvn -B deploy \ -P homelab \ - --settings=${{ github.workspace }}/.mvn/settings.xml \ No newline at end of file + --settings=${{ github.workspace }}/.mvn/settings.xml + build-docker: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-java@v4.2.2 + with: + distribution: zulu + java-version: 17 + - name: Maven Package + env: + NEXUS_USERNAME: 'edward' + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + SNAPSHOT_DEPLOYMENT_REPOSITORY_URL: ${{ secrets.SNAPSHOT_DEPLOYMENT_REPOSITORY_URL }} + RELEASE_DEPLOYMENT_REPOSITORY_URL: ${{ secrets.RELEASE_DEPLOYMENT_REPOSITORY_URL }} + run: | + mvn -B package \ + -P homelab \ + --settings=${{ github.workspace }}/.mvn/settings.xml + - name: Docker meta + - id: Setup Docker Metadata + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6 + with: + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + merge-docker: + runs-on: ubuntu-latest + needs: + - build-docker + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + # generate Docker tags based on the following events/attributes + tags: | + type=schedule,{{date 'YYYYMMDD'}} + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file