|
| 1 | +name: Build and push image |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + runtime: |
| 9 | + description: 'Runtime image' |
| 10 | + required: true |
| 11 | + default: 'hackmdio/runtime:16.20.2-35fe7e39' |
| 12 | + buildpack: |
| 13 | + description: 'Buildpack image' |
| 14 | + required: true |
| 15 | + default: 'hackmdio/buildpack:16.20.2-35fe7e39' |
| 16 | + |
| 17 | +env: |
| 18 | + REGISTRY_IMAGE: hackmdio/hackmd |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + platform: |
| 27 | + - linux/amd64 |
| 28 | + - linux/arm64 |
| 29 | + steps: |
| 30 | + - |
| 31 | + name: Prepare |
| 32 | + run: | |
| 33 | + platform=${{ matrix.platform }} |
| 34 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 35 | + - |
| 36 | + name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + - |
| 39 | + name: Docker meta |
| 40 | + id: meta |
| 41 | + uses: docker/metadata-action@v5 |
| 42 | + with: |
| 43 | + images: ${{ env.REGISTRY_IMAGE }} |
| 44 | + - |
| 45 | + name: Set up QEMU |
| 46 | + uses: docker/setup-qemu-action@v3 |
| 47 | + - |
| 48 | + name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + - |
| 51 | + name: Login to Docker Hub |
| 52 | + uses: docker/login-action@v3 |
| 53 | + with: |
| 54 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 55 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 56 | + - |
| 57 | + name: Build and push by digest |
| 58 | + id: build |
| 59 | + uses: docker/build-push-action@v5 |
| 60 | + with: |
| 61 | + context: . |
| 62 | + file: ./deployments/Dockerfile |
| 63 | + platforms: ${{ matrix.platform }} |
| 64 | + labels: ${{ steps.meta.outputs.labels }} |
| 65 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 66 | + build-args: | |
| 67 | + RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-35fe7e39' }} |
| 68 | + BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-35fe7e39' }} |
| 69 | + - |
| 70 | + name: Export digest |
| 71 | + run: | |
| 72 | + mkdir -p /tmp/digests |
| 73 | + digest="${{ steps.build.outputs.digest }}" |
| 74 | + touch "/tmp/digests/${digest#sha256:}" |
| 75 | + - |
| 76 | + name: Upload digest |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 80 | + path: /tmp/digests/* |
| 81 | + if-no-files-found: error |
| 82 | + retention-days: 1 |
| 83 | + |
| 84 | + merge: |
| 85 | + runs-on: ubuntu-latest |
| 86 | + needs: |
| 87 | + - build |
| 88 | + steps: |
| 89 | + - |
| 90 | + name: Download digests |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + path: /tmp/digests |
| 94 | + pattern: digests-* |
| 95 | + merge-multiple: true |
| 96 | + - |
| 97 | + name: Set up Docker Buildx |
| 98 | + uses: docker/setup-buildx-action@v3 |
| 99 | + - |
| 100 | + name: Docker meta |
| 101 | + id: meta |
| 102 | + uses: docker/metadata-action@v5 |
| 103 | + with: |
| 104 | + images: ${{ env.REGISTRY_IMAGE }} |
| 105 | + tags: | |
| 106 | + type=match,pattern=\d.\d.\d |
| 107 | + type=sha,prefix= |
| 108 | + - |
| 109 | + name: Login to Docker Hub |
| 110 | + uses: docker/login-action@v3 |
| 111 | + with: |
| 112 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 113 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 114 | + - |
| 115 | + name: Create manifest list and push |
| 116 | + working-directory: /tmp/digests |
| 117 | + run: | |
| 118 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 119 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 120 | + - |
| 121 | + name: Inspect image |
| 122 | + run: | |
| 123 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments