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