|
11 | 11 | required: false |
12 | 12 |
|
13 | 13 | jobs: |
14 | | - push_to_registries: |
15 | | - name: Push Docker image to multiple registries |
16 | | - runs-on: ubuntu-latest |
| 14 | + build_single_arch: |
| 15 | + name: Build & push (${{ matrix.arch }}) [native] |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - arch: amd64 |
| 21 | + platform: linux/amd64 |
| 22 | + runner: ubuntu-latest |
| 23 | + - arch: arm64 |
| 24 | + platform: linux/arm64 |
| 25 | + runner: ubuntu-24.04-arm |
| 26 | + runs-on: ${{ matrix.runner }} |
17 | 27 | permissions: |
18 | 28 | packages: write |
19 | 29 | contents: read |
20 | 30 | steps: |
21 | | - - name: Check out the repo |
| 31 | + - name: Check out (shallow) |
22 | 32 | uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 1 |
23 | 35 |
|
24 | | - - name: Save version info |
| 36 | + - name: Determine alpha version |
| 37 | + id: version |
25 | 38 | run: | |
26 | | - echo "alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" > VERSION |
| 39 | + VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" |
| 40 | + echo "$VERSION" > VERSION |
| 41 | + echo "value=$VERSION" >> $GITHUB_OUTPUT |
| 42 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 43 | + echo "Publishing version: $VERSION for ${{ matrix.arch }}" |
| 44 | +
|
| 45 | + - name: Normalize GHCR repository |
| 46 | + run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV |
| 47 | + |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
27 | 50 |
|
28 | 51 | - name: Log in to Docker Hub |
29 | 52 | uses: docker/login-action@v3 |
30 | 53 | with: |
31 | 54 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
32 | 55 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
33 | 56 |
|
34 | | - - name: Log in to the Container registry |
| 57 | + - name: Log in to GHCR |
35 | 58 | uses: docker/login-action@v3 |
36 | 59 | with: |
37 | 60 | registry: ghcr.io |
38 | 61 | username: ${{ github.actor }} |
39 | 62 | password: ${{ secrets.GITHUB_TOKEN }} |
40 | 63 |
|
41 | | - - name: Set up Docker Buildx |
42 | | - uses: docker/setup-buildx-action@v3 |
43 | | - |
44 | | - - name: Extract metadata (tags, labels) for Docker |
| 64 | + - name: Extract metadata (labels) |
45 | 65 | id: meta |
46 | 66 | uses: docker/metadata-action@v5 |
47 | 67 | with: |
48 | 68 | images: | |
49 | 69 | calciumion/new-api |
50 | | - ghcr.io/${{ github.repository }} |
51 | | - tags: | |
52 | | - type=raw,value=alpha |
53 | | - type=raw,value=alpha-{{date 'YYYYMMDD'}}-{{sha}} |
| 70 | + ghcr.io/${{ env.GHCR_REPOSITORY }} |
54 | 71 |
|
55 | | - - name: Build and push Docker images |
56 | | - uses: docker/build-push-action@v5 |
| 72 | + - name: Build & push single-arch (to both registries) |
| 73 | + uses: docker/build-push-action@v6 |
57 | 74 | with: |
58 | 75 | context: . |
59 | | - platforms: linux/amd64,linux/arm64 |
| 76 | + platforms: ${{ matrix.platform }} |
60 | 77 | push: true |
61 | | - tags: ${{ steps.meta.outputs.tags }} |
| 78 | + tags: | |
| 79 | + calciumion/new-api:alpha-${{ matrix.arch }} |
| 80 | + calciumion/new-api:${{ steps.version.outputs.value }}-${{ matrix.arch }} |
| 81 | + ghcr.io/${{ env.GHCR_REPOSITORY }}:alpha-${{ matrix.arch }} |
| 82 | + ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ steps.version.outputs.value }}-${{ matrix.arch }} |
62 | 83 | labels: ${{ steps.meta.outputs.labels }} |
| 84 | + cache-from: type=gha |
| 85 | + cache-to: type=gha,mode=max |
| 86 | + provenance: false |
| 87 | + sbom: false |
| 88 | + |
| 89 | + create_manifests: |
| 90 | + name: Create multi-arch manifests (Docker Hub + GHCR) |
| 91 | + needs: [build_single_arch] |
| 92 | + runs-on: ubuntu-latest |
| 93 | + permissions: |
| 94 | + packages: write |
| 95 | + contents: read |
| 96 | + steps: |
| 97 | + - name: Check out (shallow) |
| 98 | + uses: actions/checkout@v4 |
| 99 | + with: |
| 100 | + fetch-depth: 1 |
| 101 | + |
| 102 | + - name: Normalize GHCR repository |
| 103 | + run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV |
| 104 | + |
| 105 | + - name: Determine alpha version |
| 106 | + id: version |
| 107 | + run: | |
| 108 | + VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" |
| 109 | + echo "value=$VERSION" >> $GITHUB_OUTPUT |
| 110 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 111 | +
|
| 112 | + - name: Log in to Docker Hub |
| 113 | + uses: docker/login-action@v3 |
| 114 | + with: |
| 115 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 116 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 117 | + |
| 118 | + - name: Create & push manifest (Docker Hub - alpha) |
| 119 | + run: | |
| 120 | + docker buildx imagetools create \ |
| 121 | + -t calciumion/new-api:alpha \ |
| 122 | + calciumion/new-api:alpha-amd64 \ |
| 123 | + calciumion/new-api:alpha-arm64 |
| 124 | +
|
| 125 | + - name: Create & push manifest (Docker Hub - versioned alpha) |
| 126 | + run: | |
| 127 | + docker buildx imagetools create \ |
| 128 | + -t calciumion/new-api:${VERSION} \ |
| 129 | + calciumion/new-api:${VERSION}-amd64 \ |
| 130 | + calciumion/new-api:${VERSION}-arm64 |
| 131 | +
|
| 132 | + - name: Log in to GHCR |
| 133 | + uses: docker/login-action@v3 |
| 134 | + with: |
| 135 | + registry: ghcr.io |
| 136 | + username: ${{ github.actor }} |
| 137 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + |
| 139 | + - name: Create & push manifest (GHCR - alpha) |
| 140 | + run: | |
| 141 | + docker buildx imagetools create \ |
| 142 | + -t ghcr.io/${GHCR_REPOSITORY}:alpha \ |
| 143 | + ghcr.io/${GHCR_REPOSITORY}:alpha-amd64 \ |
| 144 | + ghcr.io/${GHCR_REPOSITORY}:alpha-arm64 |
| 145 | +
|
| 146 | + - name: Create & push manifest (GHCR - versioned alpha) |
| 147 | + run: | |
| 148 | + docker buildx imagetools create \ |
| 149 | + -t ghcr.io/${GHCR_REPOSITORY}:${VERSION} \ |
| 150 | + ghcr.io/${GHCR_REPOSITORY}:${VERSION}-amd64 \ |
| 151 | + ghcr.io/${GHCR_REPOSITORY}:${VERSION}-arm64 |
0 commit comments