|
1 | | -name: nginx pull |
| 1 | +name: nginx preview deployment |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | | - branches: |
6 | | - - main |
| 5 | + branches: |
| 6 | + - main |
| 7 | +env: |
| 8 | + REGISTRY_IMAGE: ghcr.io/arxignis/nginx |
7 | 9 | jobs: |
8 | | - pull: |
9 | | - name: nginx pull |
10 | | - runs-on: ubicloud-standard-8-ubuntu-2404 |
| 10 | + prepare: |
| 11 | + runs-on: ubicloud-standard-16-ubuntu-2404 |
| 12 | + outputs: |
| 13 | + matrix: ${{ steps.platforms.outputs.matrix }} |
11 | 14 | steps: |
12 | | - - name: Login to Github Packages |
13 | | - uses: docker/login-action@v3 |
14 | | - with: |
15 | | - registry: ghcr.io |
16 | | - username: ${{ github.actor }} |
17 | | - password: ${{ secrets.GITHUB_TOKEN }} |
18 | | - |
19 | | - - name: Set up QEMU |
20 | | - id: qemu |
21 | | - uses: docker/setup-qemu-action@v3 |
22 | | - with: |
23 | | - image: tonistiigi/binfmt:latest |
24 | | - platforms: all |
25 | | - |
26 | | - - name: 🏗 Setup repo |
| 15 | + - name: Checkout |
27 | 16 | uses: actions/checkout@v4 |
28 | | - with: |
29 | | - token: ${{ secrets.GITHUB_TOKEN }} |
30 | | - submodules: recursive |
31 | 17 |
|
32 | | - - name: Set up Docker Context for Buildx |
33 | | - run: docker context create builders |
| 18 | + - name: Create matrix |
| 19 | + id: platforms |
| 20 | + run: | |
| 21 | + echo "matrix=$(docker buildx bake image-all --print | jq -cr '.target."image-all".platforms')" >>${GITHUB_OUTPUT} |
34 | 22 |
|
35 | | - - name: Set up Docker Buildx |
36 | | - uses: docker/setup-buildx-action@v3 |
37 | | - with: |
38 | | - version: latest |
39 | | - endpoint: builders |
| 23 | + - name: Show matrix |
| 24 | + run: | |
| 25 | + echo ${{ steps.platforms.outputs.matrix }} |
40 | 26 |
|
41 | 27 | - name: Docker meta |
42 | | - id: nginx |
| 28 | + id: meta |
43 | 29 | uses: docker/metadata-action@v5 |
44 | 30 | with: |
45 | | - images: ghcr.io/arxignis/nginx |
| 31 | + images: ${{ env.REGISTRY_IMAGE }} |
46 | 32 | tags: | |
47 | 33 | type=sha,format=short |
48 | 34 | type=match,pattern=v(\d+\.\d+\.\d+),group=1 |
49 | 35 | type=match,pattern=v(\d+\.\d+),group=1 |
50 | 36 | type=match,pattern=v(\d+),group=1 |
51 | 37 | type=raw,value=latest |
52 | 38 |
|
| 39 | + - name: Rename meta bake definition file |
| 40 | + run: | |
| 41 | + mv "${{ steps.meta.outputs.bake-file }}" "${{ runner.temp }}/bake-meta.json" |
| 42 | +
|
| 43 | + - name: Upload meta bake definition |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: bake-meta |
| 47 | + path: ${{ runner.temp }}/bake-meta.json |
| 48 | + if-no-files-found: error |
| 49 | + retention-days: 1 |
| 50 | + |
| 51 | + build: |
| 52 | + runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubicloud-standard-16-arm-ubuntu-2404' || 'ubicloud-standard-16-ubuntu-2404' }} |
| 53 | + needs: |
| 54 | + - prepare |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + platform: ${{ fromJson(needs.prepare.outputs.matrix) }} |
| 59 | + steps: |
| 60 | + - name: Prepare |
| 61 | + run: | |
| 62 | + platform=${{ matrix.platform }} |
| 63 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 64 | +
|
| 65 | + - name: Download meta bake definition |
| 66 | + uses: actions/download-artifact@v4 |
| 67 | + with: |
| 68 | + name: bake-meta |
| 69 | + path: ${{ runner.temp }} |
| 70 | + |
| 71 | + - name: Login to Github Packages |
| 72 | + uses: docker/login-action@v3 |
| 73 | + with: |
| 74 | + registry: ghcr.io |
| 75 | + username: ${{ github.actor }} |
| 76 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Set up QEMU |
| 79 | + uses: docker/setup-qemu-action@v3 |
| 80 | + |
| 81 | + - name: Set up Docker Buildx |
| 82 | + uses: docker/setup-buildx-action@v3 |
| 83 | + |
53 | 84 | - name: Build |
54 | | - uses: docker/build-push-action@v6 |
55 | | - id: build-image |
| 85 | + id: bake |
| 86 | + uses: docker/bake-action@v6 |
56 | 87 | with: |
57 | | - context: . |
58 | | - platforms: linux/arm64,linux/amd64 |
59 | | - push: false |
60 | | - tags: ${{ steps.nginx.outputs.tags }} |
61 | | - labels: ${{ steps.nginx.outputs.labels }} |
62 | | - cache-from: type=gha |
63 | | - cache-to: type=gha,mode=max |
| 88 | + files: | |
| 89 | + ./docker-bake.hcl |
| 90 | + cwd://${{ runner.temp }}/bake-meta.json |
| 91 | + targets: image |
| 92 | + set: | |
| 93 | + *.tags=${{ env.REGISTRY_IMAGE }} |
| 94 | + *.platform=${{ matrix.platform }} |
| 95 | + *.output=type=image,push-by-digest=true,name-canonical=true,push=true |
| 96 | +
|
| 97 | + - name: Export digest |
| 98 | + run: | |
| 99 | + mkdir -p ${{ runner.temp }}/digests |
| 100 | + digest="${{ fromJSON(steps.bake.outputs.metadata).image['containerimage.digest'] }}" |
| 101 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 102 | +
|
| 103 | + # - name: Upload digest |
| 104 | + # uses: actions/upload-artifact@v4 |
| 105 | + # with: |
| 106 | + # name: digests-${{ env.PLATFORM_PAIR }} |
| 107 | + # path: ${{ runner.temp }}/digests/* |
| 108 | + # if-no-files-found: error |
| 109 | + # retention-days: 1 |
| 110 | + |
| 111 | + # merge: |
| 112 | + # runs-on: ubicloud-standard-16-ubuntu-2404 |
| 113 | + # needs: |
| 114 | + # - build |
| 115 | + # steps: |
| 116 | + # - name: Download meta bake definition |
| 117 | + # uses: actions/download-artifact@v4 |
| 118 | + # with: |
| 119 | + # name: bake-meta |
| 120 | + # path: ${{ runner.temp }} |
| 121 | + |
| 122 | + # - name: Download digests |
| 123 | + # uses: actions/download-artifact@v4 |
| 124 | + # with: |
| 125 | + # path: ${{ runner.temp }}/digests |
| 126 | + # pattern: digests-* |
| 127 | + # merge-multiple: true |
| 128 | + |
| 129 | + # - name: Login to Github Packages |
| 130 | + # uses: docker/login-action@v3 |
| 131 | + # with: |
| 132 | + # registry: ghcr.io |
| 133 | + # username: ${{ github.actor }} |
| 134 | + # password: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + |
| 136 | + # - name: Set up Docker Buildx |
| 137 | + # uses: docker/setup-buildx-action@v3 |
| 138 | + |
| 139 | + # - name: Create manifest list and push |
| 140 | + # working-directory: ${{ runner.temp }}/digests |
| 141 | + # run: | |
| 142 | + # docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ env.REGISTRY_IMAGE }}")) | "-t " + .) | join(" ")' ${{ runner.temp }}/bake-meta.json) \ |
| 143 | + # $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 144 | + |
| 145 | + # - name: Inspect image |
| 146 | + # run: | |
| 147 | + # docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:$(jq -r '.target."docker-metadata-action".args.DOCKER_META_VERSION' ${{ runner.temp }}/bake-meta.json) |
0 commit comments