|
7 | 7 | tags: |
8 | 8 | - 'v*.*.*' |
9 | 9 |
|
| 10 | +env: |
| 11 | + GHCR_REPO: ghcr.io/${{ github.repository }} |
| 12 | + DOCKERFILE: Dockerfile |
| 13 | + |
10 | 14 | jobs: |
11 | | - build-and-push-image: |
| 15 | + meta: |
| 16 | + name: Compute tags and build info |
12 | 17 | runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + sha_short: ${{ steps.vars.outputs.sha_short }} |
| 20 | + tag_prefix: ${{ steps.vars.outputs.tag_prefix }} |
| 21 | + additional_tags: ${{ steps.vars.outputs.additional_tags }} |
| 22 | + version: ${{ steps.vars.outputs.version }} |
| 23 | + commit: ${{ steps.vars.outputs.commit }} |
| 24 | + date: ${{ steps.vars.outputs.date }} |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
13 | 29 |
|
| 30 | + - id: vars |
| 31 | + run: | |
| 32 | + SHA_SHORT=$(git rev-parse --short HEAD) |
| 33 | + echo "sha_short=$SHA_SHORT" >> $GITHUB_OUTPUT |
| 34 | + if [[ "${{ github.ref }}" == refs/tags/v*.*.* ]]; then |
| 35 | + VERSION_TAG="${GITHUB_REF#refs/tags/}" |
| 36 | + echo "tag_prefix=$VERSION_TAG" >> $GITHUB_OUTPUT |
| 37 | + echo "additional_tags=[\"$VERSION_TAG\",\"latest\"]" >> $GITHUB_OUTPUT |
| 38 | + else |
| 39 | + echo "tag_prefix=master" >> $GITHUB_OUTPUT |
| 40 | + echo "additional_tags=[\"master\",\"master-latest\"]" >> $GITHUB_OUTPUT |
| 41 | + fi |
| 42 | + VERSION=$(git describe --tags --always 2>/dev/null || echo "dev") |
| 43 | + DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 44 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 45 | + echo "commit=$SHA_SHORT" >> $GITHUB_OUTPUT |
| 46 | + echo "date=$DATE" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + build_amd64: |
| 49 | + name: Build amd64 image |
| 50 | + needs: meta |
| 51 | + runs-on: ubuntu-latest |
14 | 52 | permissions: |
15 | 53 | contents: read |
16 | 54 | packages: write |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 57 | + with: |
| 58 | + fetch-depth: 0 |
| 59 | + |
| 60 | + - name: Set up Docker Buildx |
| 61 | + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 |
17 | 62 |
|
| 63 | + - name: Log in to GHCR |
| 64 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 65 | + with: |
| 66 | + registry: ghcr.io |
| 67 | + username: ${{ github.actor }} |
| 68 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + |
| 70 | + - name: Build amd64 docker image |
| 71 | + env: |
| 72 | + PREFIX: ${{ needs.meta.outputs.tag_prefix }} |
| 73 | + SHA: ${{ needs.meta.outputs.sha_short }} |
| 74 | + VERSION: ${{ needs.meta.outputs.version }} |
| 75 | + COMMIT: ${{ needs.meta.outputs.commit }} |
| 76 | + DATE: ${{ needs.meta.outputs.date }} |
| 77 | + run: | |
| 78 | + docker build . --file "$DOCKERFILE" \ |
| 79 | + --tag "${GHCR_REPO}:${PREFIX}-amd64" \ |
| 80 | + --tag "${GHCR_REPO}:${PREFIX}-${SHA}-amd64" \ |
| 81 | + --platform=linux/amd64 \ |
| 82 | + --build-arg VERSION="$VERSION" \ |
| 83 | + --build-arg COMMIT="$COMMIT" \ |
| 84 | + --build-arg DATE="$DATE" |
| 85 | +
|
| 86 | + - name: Push amd64 docker images |
| 87 | + env: |
| 88 | + PREFIX: ${{ needs.meta.outputs.tag_prefix }} |
| 89 | + SHA: ${{ needs.meta.outputs.sha_short }} |
| 90 | + run: | |
| 91 | + docker push "${GHCR_REPO}:${PREFIX}-amd64" |
| 92 | + docker push "${GHCR_REPO}:${PREFIX}-${SHA}-amd64" |
| 93 | +
|
| 94 | + build_arm64: |
| 95 | + name: Build arm64 image |
| 96 | + needs: meta |
| 97 | + runs-on: ubuntu-24.04-arm |
| 98 | + permissions: |
| 99 | + contents: read |
| 100 | + packages: write |
18 | 101 | steps: |
19 | | - - name: Checkout repository |
20 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 102 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
21 | 103 | with: |
22 | 104 | fetch-depth: 0 |
23 | 105 |
|
24 | | - - name: Set build version info |
| 106 | + - name: Set up Docker Buildx |
| 107 | + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 |
| 108 | + |
| 109 | + - name: Log in to GHCR |
| 110 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 111 | + with: |
| 112 | + registry: ghcr.io |
| 113 | + username: ${{ github.actor }} |
| 114 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + |
| 116 | + - name: Build arm64 docker image |
| 117 | + env: |
| 118 | + PREFIX: ${{ needs.meta.outputs.tag_prefix }} |
| 119 | + SHA: ${{ needs.meta.outputs.sha_short }} |
| 120 | + VERSION: ${{ needs.meta.outputs.version }} |
| 121 | + COMMIT: ${{ needs.meta.outputs.commit }} |
| 122 | + DATE: ${{ needs.meta.outputs.date }} |
25 | 123 | run: | |
26 | | - VERSION=$(git describe --tags --always 2>/dev/null || echo "dev") |
27 | | - COMMIT=$(git rev-parse --short HEAD) |
28 | | - DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
29 | | - echo "VERSION=${VERSION}" >> "$GITHUB_ENV" |
30 | | - echo "COMMIT=${COMMIT}" >> "$GITHUB_ENV" |
31 | | - echo "DATE=${DATE}" >> "$GITHUB_ENV" |
32 | | - echo "Build version: VERSION=${VERSION} COMMIT=${COMMIT} DATE=${DATE}" |
| 124 | + docker build . --file "$DOCKERFILE" \ |
| 125 | + --tag "${GHCR_REPO}:${PREFIX}-arm64" \ |
| 126 | + --tag "${GHCR_REPO}:${PREFIX}-${SHA}-arm64" \ |
| 127 | + --platform=linux/arm64 \ |
| 128 | + --build-arg VERSION="$VERSION" \ |
| 129 | + --build-arg COMMIT="$COMMIT" \ |
| 130 | + --build-arg DATE="$DATE" |
33 | 131 |
|
34 | | - - name: Deploy docker images |
35 | | - uses: ethpandaops/actions/docker-build-push@99b48ca2b233a2eff93e6a6df76e46b718aca108 |
| 132 | + - name: Push arm64 docker images |
| 133 | + env: |
| 134 | + PREFIX: ${{ needs.meta.outputs.tag_prefix }} |
| 135 | + SHA: ${{ needs.meta.outputs.sha_short }} |
| 136 | + run: | |
| 137 | + docker push "${GHCR_REPO}:${PREFIX}-arm64" |
| 138 | + docker push "${GHCR_REPO}:${PREFIX}-${SHA}-arm64" |
| 139 | +
|
| 140 | + manifest_sha: |
| 141 | + name: Multi-arch sha manifest |
| 142 | + needs: [meta, build_amd64, build_arm64] |
| 143 | + runs-on: ubuntu-latest |
| 144 | + permissions: |
| 145 | + contents: read |
| 146 | + packages: write |
| 147 | + steps: |
| 148 | + - name: Set up Docker Buildx |
| 149 | + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 |
| 150 | + |
| 151 | + - name: Log in to GHCR |
| 152 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
36 | 153 | with: |
37 | 154 | registry: ghcr.io |
38 | | - registry_username: ${{ github.actor }} |
39 | | - registry_password: ${{ secrets.GITHUB_TOKEN }} |
40 | | - image_name: ${{ github.repository }} |
41 | | - push: true |
42 | | - platforms: linux/amd64,linux/arm64 |
43 | | - file: Dockerfile |
44 | | - build-args: | |
45 | | - VERSION=${{ env.VERSION }} |
46 | | - COMMIT=${{ env.COMMIT }} |
47 | | - DATE=${{ env.DATE }} |
| 155 | + username: ${{ github.actor }} |
| 156 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 157 | + |
| 158 | + - name: Create multi-arch sha manifest |
| 159 | + env: |
| 160 | + PREFIX: ${{ needs.meta.outputs.tag_prefix }} |
| 161 | + SHA: ${{ needs.meta.outputs.sha_short }} |
| 162 | + run: | |
| 163 | + docker buildx imagetools create -t "${GHCR_REPO}:${PREFIX}-${SHA}" \ |
| 164 | + "${GHCR_REPO}:${PREFIX}-${SHA}-amd64" \ |
| 165 | + "${GHCR_REPO}:${PREFIX}-${SHA}-arm64" |
| 166 | +
|
| 167 | + manifest_extra: |
| 168 | + name: Multi-arch additional manifests |
| 169 | + needs: [meta, build_amd64, build_arm64] |
| 170 | + if: ${{ needs.meta.outputs.additional_tags != '' }} |
| 171 | + runs-on: ubuntu-latest |
| 172 | + permissions: |
| 173 | + contents: read |
| 174 | + packages: write |
| 175 | + strategy: |
| 176 | + matrix: |
| 177 | + tag: ${{ fromJSON(needs.meta.outputs.additional_tags) }} |
| 178 | + steps: |
| 179 | + - name: Set up Docker Buildx |
| 180 | + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 |
| 181 | + |
| 182 | + - name: Log in to GHCR |
| 183 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 184 | + with: |
| 185 | + registry: ghcr.io |
| 186 | + username: ${{ github.actor }} |
| 187 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 188 | + |
| 189 | + - name: Create multi-arch manifest ${{ matrix.tag }} |
| 190 | + env: |
| 191 | + PREFIX: ${{ needs.meta.outputs.tag_prefix }} |
| 192 | + SHA: ${{ needs.meta.outputs.sha_short }} |
| 193 | + TAG: ${{ matrix.tag }} |
| 194 | + run: | |
| 195 | + docker buildx imagetools create -t "${GHCR_REPO}:${TAG}" \ |
| 196 | + "${GHCR_REPO}:${PREFIX}-${SHA}-amd64" \ |
| 197 | + "${GHCR_REPO}:${PREFIX}-${SHA}-arm64" |
0 commit comments