|
1 | 1 | name: build-and-push-bsky-ghcr |
2 | 2 | on: |
| 3 | + workflow_dispatch: |
3 | 4 | push: |
4 | 5 | branches: |
5 | 6 | - main |
6 | | - - msi/pds-lexification |
| 7 | + - flashes-appview |
7 | 8 |
|
8 | 9 | env: |
9 | 10 | REGISTRY: ghcr.io |
10 | 11 | USERNAME: ${{ github.actor }} |
11 | 12 | PASSWORD: ${{ secrets.GITHUB_TOKEN }} |
12 | | - |
13 | | - # github.repository as <account>/<repo> |
14 | 13 | IMAGE_NAME: ${{ github.repository }} |
15 | 14 |
|
16 | 15 | jobs: |
17 | | - bsky-container-ghcr: |
18 | | - if: github.repository == 'bluesky-social/atproto' |
19 | | - runs-on: ubuntu-22.04 |
| 16 | + build-platforms: |
| 17 | + runs-on: ${{ matrix.runner }} |
| 18 | + timeout-minutes: 60 |
20 | 19 | permissions: |
21 | 20 | contents: read |
22 | 21 | packages: write |
| 22 | + attestations: write |
23 | 23 | id-token: write |
24 | | - |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + - platform: linux/amd64 |
| 29 | + runner: ubuntu-latest |
| 30 | + - platform: linux/arm64 |
| 31 | + runner: ubuntu-24.04-arm |
25 | 32 | steps: |
26 | 33 | - name: Checkout repository |
27 | | - uses: actions/checkout@v3 |
| 34 | + uses: actions/checkout@v5 |
28 | 35 |
|
29 | 36 | - name: Setup Docker buildx |
30 | | - uses: docker/setup-buildx-action@v2 |
| 37 | + uses: docker/setup-buildx-action@v3 |
| 38 | + |
| 39 | + - name: Sanitize platform name |
| 40 | + id: platform |
| 41 | + run: | |
| 42 | + platform=${{ matrix.platform }} |
| 43 | + echo "safe=${platform//\//-}" >> $GITHUB_OUTPUT |
31 | 44 |
|
32 | 45 | - name: Log into registry ${{ env.REGISTRY }} |
33 | | - uses: docker/login-action@v2 |
| 46 | + uses: docker/login-action@v3 |
34 | 47 | with: |
35 | 48 | registry: ${{ env.REGISTRY }} |
36 | 49 | username: ${{ env.USERNAME }} |
37 | 50 | password: ${{ env.PASSWORD }} |
38 | 51 |
|
39 | 52 | - name: Extract Docker metadata |
40 | 53 | id: meta |
41 | | - uses: docker/metadata-action@v4 |
| 54 | + uses: docker/metadata-action@v5 |
42 | 55 | with: |
43 | 56 | images: | |
44 | 57 | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
45 | 58 | tags: | |
46 | | - type=sha,enable=true,priority=100,prefix=bsky:,suffix=,format=long |
| 59 | + type=sha,enable=true,priority=100,prefix=bsky-${{ github.ref_name != 'main' && format('{0}-', github.ref_name) || '' }},suffix=,format=long |
| 60 | + type=raw,value=bsky-${{ github.ref_name != 'main' && format('{0}-', github.ref_name) || '' }}{{date 'YYYY-MM-DDTHH-mm-ssZ'}} |
| 61 | + type=raw,value=bsky-${{ github.ref_name != 'main' && format('{0}-', github.ref_name) || '' }}latest |
47 | 62 |
|
48 | | - - name: Build and push Docker image |
49 | | - id: build-and-push |
50 | | - uses: docker/build-push-action@v4 |
| 63 | + - name: Build and push by digest |
| 64 | + id: build |
| 65 | + uses: docker/build-push-action@v6 |
51 | 66 | with: |
52 | 67 | context: . |
53 | | - push: ${{ github.event_name != 'pull_request' }} |
| 68 | + platforms: ${{ matrix.platform }} |
54 | 69 | file: ./services/bsky/Dockerfile |
55 | | - tags: ${{ steps.meta.outputs.tags }} |
56 | 70 | labels: ${{ steps.meta.outputs.labels }} |
57 | | - cache-from: type=gha |
58 | | - cache-to: type=gha,mode=max |
| 71 | + cache-from: type=gha,scope=bsky-${{ steps.platform.outputs.safe }} |
| 72 | + cache-to: type=gha,mode=max,scope=bsky-${{ steps.platform.outputs.safe }} |
| 73 | + build-args: | |
| 74 | + BUILDKIT_INLINE_CACHE=1 |
| 75 | + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 76 | + |
| 77 | + - name: Export digest |
| 78 | + run: | |
| 79 | + mkdir -p /tmp/digests |
| 80 | + digest="${{ steps.build.outputs.digest }}" |
| 81 | + touch "/tmp/digests/${digest#sha256:}" |
| 82 | +
|
| 83 | + - name: Upload digest |
| 84 | + uses: actions/upload-artifact@v4 |
| 85 | + with: |
| 86 | + name: digests-${{ steps.platform.outputs.safe }} |
| 87 | + path: /tmp/digests/* |
| 88 | + if-no-files-found: error |
| 89 | + retention-days: 1 |
| 90 | + |
| 91 | + merge-manifests: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: build-platforms |
| 94 | + permissions: |
| 95 | + contents: write |
| 96 | + packages: write |
| 97 | + attestations: write |
| 98 | + id-token: write |
| 99 | + steps: |
| 100 | + - name: Download digests |
| 101 | + uses: actions/download-artifact@v4 |
| 102 | + with: |
| 103 | + pattern: digests-* |
| 104 | + merge-multiple: true |
| 105 | + path: /tmp/digests |
| 106 | + |
| 107 | + - name: Setup Docker buildx |
| 108 | + uses: docker/setup-buildx-action@v3 |
| 109 | + with: |
| 110 | + driver-opts: | |
| 111 | + network=host |
| 112 | +
|
| 113 | + - name: Log into registry ${{ env.REGISTRY }} |
| 114 | + uses: docker/login-action@v3 |
| 115 | + with: |
| 116 | + registry: ${{ env.REGISTRY }} |
| 117 | + username: ${{ env.USERNAME }} |
| 118 | + password: ${{ env.PASSWORD }} |
| 119 | + |
| 120 | + - name: Extract Docker metadata |
| 121 | + id: meta |
| 122 | + uses: docker/metadata-action@v5 |
| 123 | + with: |
| 124 | + images: | |
| 125 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 126 | + tags: | |
| 127 | + type=sha,enable=true,priority=100,prefix=bsky-${{ github.ref_name != 'main' && format('{0}-', github.ref_name) || '' }},suffix=,format=long |
| 128 | + type=raw,value=bsky-${{ github.ref_name != 'main' && format('{0}-', github.ref_name) || '' }}{{date 'YYYY-MM-DDTHH-mm-ssZ'}} |
| 129 | + type=raw,value=bsky-${{ github.ref_name != 'main' && format('{0}-', github.ref_name) || '' }}latest |
| 130 | +
|
| 131 | + - name: Create manifest list and push |
| 132 | + id: merge |
| 133 | + working-directory: /tmp/digests |
| 134 | + run: | |
| 135 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 136 | + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) |
| 137 | +
|
| 138 | + - name: Inspect image and get digest |
| 139 | + id: inspect |
| 140 | + run: | |
| 141 | + digest=$(docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$(echo '${{ steps.meta.outputs.tags }}' | head -1 | cut -d':' -f2) | grep "^Digest:" | awk '{print $2}') |
| 142 | + echo "digest=$digest" >> $GITHUB_OUTPUT |
| 143 | +
|
| 144 | + - name: Generate artifact attestation |
| 145 | + uses: actions/attest-build-provenance@v1 |
| 146 | + with: |
| 147 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 148 | + subject-digest: ${{ steps.inspect.outputs.digest }} |
| 149 | + push-to-registry: true |
| 150 | + |
| 151 | + - name: Checkout repository for tagging |
| 152 | + uses: actions/checkout@v5 |
| 153 | + with: |
| 154 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 155 | + |
| 156 | + - name: Tag repository with datetime |
| 157 | + run: | |
| 158 | + DATETIME_TAG=$(date -u +"%Y-%m-%dT%H-%M-%SZ") |
| 159 | + git config user.name "github-actions[bot]" |
| 160 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 161 | + git tag -a "bsky-$DATETIME_TAG" -m "Release bsky-$DATETIME_TAG" |
| 162 | + git push origin "bsky-$DATETIME_TAG" |
0 commit comments