|
| 1 | +name: Publish Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + packages: write |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY_IMAGE: ghcr.io/misskey-dev/sensitive-detector |
| 13 | + TAGS: | |
| 14 | + type=semver,pattern={{version}} |
| 15 | + type=semver,pattern={{major}}.{{minor}} |
| 16 | + type=semver,pattern={{major}} |
| 17 | +
|
| 18 | +jobs: |
| 19 | + # see https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners |
| 20 | + build: |
| 21 | + name: Build |
| 22 | + runs-on: ubuntu-latest |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + platform: |
| 27 | + - linux/amd64 |
| 28 | + # TODO: Re-enable after @tensorflow/tfjs-node supports Linux arm64 |
| 29 | + # Docker images for this runtime stack. |
| 30 | + # - linux/arm64 |
| 31 | + if: github.repository == 'misskey-dev/sensitive-detector' |
| 32 | + steps: |
| 33 | + - name: Prepare |
| 34 | + run: | |
| 35 | + platform=${{ matrix.platform }} |
| 36 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 37 | + - name: Check out the repo |
| 38 | + uses: actions/checkout@v6.0.2 |
| 39 | + - name: Set up Docker Buildx |
| 40 | + uses: docker/setup-buildx-action@v4 |
| 41 | + - name: Docker meta |
| 42 | + id: meta |
| 43 | + uses: docker/metadata-action@v6 |
| 44 | + with: |
| 45 | + images: ${{ env.REGISTRY_IMAGE }} |
| 46 | + tags: ${{ env.TAGS }} |
| 47 | + - name: Log in to GitHub Container Registry |
| 48 | + uses: docker/login-action@v4 |
| 49 | + with: |
| 50 | + registry: ghcr.io |
| 51 | + username: ${{ github.actor }} |
| 52 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + - name: Build and push by digest |
| 54 | + id: build |
| 55 | + uses: docker/build-push-action@v7 |
| 56 | + with: |
| 57 | + context: . |
| 58 | + push: true |
| 59 | + platforms: ${{ matrix.platform }} |
| 60 | + provenance: false |
| 61 | + labels: ${{ steps.meta.outputs.labels }} |
| 62 | + cache-from: type=gha |
| 63 | + cache-to: type=gha,mode=max |
| 64 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 65 | + - name: Export digest |
| 66 | + run: | |
| 67 | + mkdir -p /tmp/digests |
| 68 | + digest="${{ steps.build.outputs.digest }}" |
| 69 | + touch "/tmp/digests/${digest#sha256:}" |
| 70 | + - name: Upload digest |
| 71 | + uses: actions/upload-artifact@v7 |
| 72 | + with: |
| 73 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 74 | + path: /tmp/digests/* |
| 75 | + if-no-files-found: error |
| 76 | + retention-days: 1 |
| 77 | + |
| 78 | + merge: |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: |
| 81 | + - build |
| 82 | + steps: |
| 83 | + - name: Download digests |
| 84 | + uses: actions/download-artifact@v8 |
| 85 | + with: |
| 86 | + path: /tmp/digests |
| 87 | + pattern: digests-* |
| 88 | + merge-multiple: true |
| 89 | + - name: Set up Docker Buildx |
| 90 | + uses: docker/setup-buildx-action@v4 |
| 91 | + - name: Docker meta |
| 92 | + id: meta |
| 93 | + uses: docker/metadata-action@v6 |
| 94 | + with: |
| 95 | + images: ${{ env.REGISTRY_IMAGE }} |
| 96 | + tags: ${{ env.TAGS }} |
| 97 | + - name: Login to GitHub Container Registry |
| 98 | + uses: docker/login-action@v4 |
| 99 | + with: |
| 100 | + registry: ghcr.io |
| 101 | + username: ${{ github.actor }} |
| 102 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + - name: Create manifest list and push |
| 104 | + working-directory: /tmp/digests |
| 105 | + run: | |
| 106 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 107 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 108 | + - name: Inspect image |
| 109 | + run: | |
| 110 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments