|
1 |
| -name: Build Service |
| 1 | +name: Build container |
| 2 | + |
2 | 3 | on:
|
3 | 4 | push:
|
4 |
| - branches: |
5 |
| - - main |
6 | 5 | workflow_dispatch:
|
7 | 6 |
|
| 7 | +env: |
| 8 | + REGISTRY_IMAGE: ghcr.io/randomairborne/tinylevel |
| 9 | + |
8 | 10 | permissions:
|
9 |
| - contents: read |
10 | 11 | packages: write
|
| 12 | + contents: read |
11 | 13 |
|
12 | 14 | jobs:
|
13 | 15 | check:
|
14 | 16 | uses: ./.github/workflows/check.yml
|
| 17 | + |
15 | 18 | build:
|
16 |
| - needs: [check] |
| 19 | + needs: [ check ] |
17 | 20 | runs-on: ubuntu-latest
|
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + platform: |
| 25 | + - docker: linux/amd64 |
| 26 | + llvm: x86_64 |
| 27 | + - docker: linux/arm64 |
| 28 | + llvm: aarch64 |
18 | 29 | steps:
|
19 |
| - - name: Correct env |
20 |
| - run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} |
21 |
| - |
22 |
| - - name: Check out code into the proper directory |
| 30 | + - name: Check out code |
23 | 31 | uses: actions/checkout@v4
|
24 | 32 |
|
25 | 33 | - name: Set up Docker Buildx
|
26 |
| - id: buildx |
27 | 34 | uses: docker/setup-buildx-action@v3
|
28 | 35 |
|
29 |
| - - name: Login to GitHub Container Registry |
| 36 | + - name: Log in to GitHub Container Registry |
30 | 37 | uses: docker/login-action@v3
|
31 | 38 | with:
|
32 | 39 | registry: ghcr.io
|
33 | 40 | username: ${{ github.repository_owner }}
|
34 | 41 | password: ${{ secrets.GITHUB_TOKEN }}
|
35 | 42 |
|
36 |
| - - name: Build container |
37 |
| - uses: docker/build-push-action@v5 |
| 43 | + - name: Build and push by digest |
| 44 | + id: build |
| 45 | + uses: docker/build-push-action@v6 |
38 | 46 | with:
|
39 | 47 | context: .
|
40 |
| - push: true |
41 |
| - tags: ghcr.io/${{ env.REPO }}:latest,ghcr.io/${{ env.REPO }}:git-${{ github.sha }} |
42 |
| - platforms: linux/amd64 |
43 |
| - cache-from: type=gha |
44 |
| - cache-to: type=gha,mode=max |
| 48 | + platforms: ${{ matrix.platform.docker }} |
| 49 | + build-args: | |
| 50 | + LLVMTARGETARCH=${{ matrix.platform.llvm }} |
| 51 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 52 | + |
| 53 | + - name: Export digest |
| 54 | + run: | |
| 55 | + mkdir -p /tmp/digests |
| 56 | + digest="${{ steps.build.outputs.digest }}" |
| 57 | + touch "/tmp/digests/${digest#sha256:}" |
| 58 | +
|
| 59 | + - name: Upload digest |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: digests-${{ matrix.platform.llvm }} |
| 63 | + path: /tmp/digests/* |
| 64 | + if-no-files-found: error |
| 65 | + retention-days: 1 |
| 66 | + |
| 67 | + merge: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: [ build ] |
| 70 | + steps: |
| 71 | + - name: Download digests |
| 72 | + uses: actions/download-artifact@v4 |
| 73 | + with: |
| 74 | + path: /tmp/digests |
| 75 | + pattern: digests-* |
| 76 | + merge-multiple: true |
| 77 | + |
| 78 | + - name: Set up Docker Buildx |
| 79 | + uses: docker/setup-buildx-action@v3 |
| 80 | + |
| 81 | + - name: Log in to GitHub Container Registry |
| 82 | + uses: docker/login-action@v3 |
| 83 | + with: |
| 84 | + registry: ghcr.io |
| 85 | + username: ${{ github.repository_owner }} |
| 86 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + |
| 88 | + - name: Create manifest list and push |
| 89 | + working-directory: /tmp/digests |
| 90 | + run: | |
| 91 | + docker buildx imagetools create --tag ${{ env.REGISTRY_IMAGE }}:latest --tag ${{ env.REGISTRY_IMAGE }}:git-${{ github.sha }} $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 92 | +
|
45 | 93 | deploy:
|
46 |
| - needs: [build] |
| 94 | + needs: [ merge ] |
47 | 95 | runs-on: ubuntu-latest
|
48 | 96 | steps:
|
49 | 97 | - name: Correct env
|
|
0 commit comments