|
| 1 | +--- |
| 2 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 3 | +name: Build |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + variant: |
| 9 | + type: string |
| 10 | + description: Variant name (main, noml, cuda, openvino) |
| 11 | + required: true |
| 12 | + release: |
| 13 | + type: boolean |
| 14 | + description: Release |
| 15 | + required: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + plan: |
| 19 | + name: Plan |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + platforms: ${{ steps.opts.outputs.platforms }} |
| 23 | + version: ${{ steps.opts.outputs.version }} |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 27 | + with: |
| 28 | + persist-credentials: false |
| 29 | + |
| 30 | + - name: Get Bake Vars |
| 31 | + uses: ./.github/actions/bake-vars |
| 32 | + id: opts |
| 33 | + with: |
| 34 | + variant: ${{ inputs.variant }} |
| 35 | + |
| 36 | + - name: Build Variant Metadata |
| 37 | + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0 |
| 38 | + id: meta |
| 39 | + env: |
| 40 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 41 | + with: |
| 42 | + images: ghcr.io/${{ github.repository_owner }}/immich |
| 43 | + flavor: latest=false |
| 44 | + tags: | |
| 45 | + ${{ inputs.variant == 'main' && format( |
| 46 | + 'type=raw,value=latest,enable={0} |
| 47 | + type=semver,pattern={{{{version}}}},value={1},enable={0} |
| 48 | + type=semver,pattern={{{{major}}}}.{{{{minor}}}},value={1},enable={0} |
| 49 | + type=semver,pattern={{{{major}}}},value={1},enable={0}', |
| 50 | + inputs.release, steps.opts.outputs.version |
| 51 | + ) || format( |
| 52 | + 'type=raw,value={0},enable={1} |
| 53 | + type=semver,pattern={{{{version}}}}-{0},value={2},enable={1} |
| 54 | + type=semver,pattern={{{{major}}}}.{{{{minor}}}}-{0},value={2},enable={1} |
| 55 | + type=semver,pattern={{{{major}}}}-{0},value={2},enable={1}', |
| 56 | + inputs.variant, inputs.release, steps.opts.outputs.version |
| 57 | + ) }} |
| 58 | + type=raw,value=sandbox-${{ inputs.variant }},enable=${{ ! inputs.release }} |
| 59 | +
|
| 60 | + - name: Upload Bake Metadata |
| 61 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 62 | + with: |
| 63 | + name: ${{ inputs.variant }}-bake-metadata |
| 64 | + path: ${{ steps.meta.outputs.bake-file }} |
| 65 | + if-no-files-found: error |
| 66 | + retention-days: 1 |
| 67 | + |
| 68 | + build: |
| 69 | + name: Build (${{ matrix.platform }}) |
| 70 | + needs: |
| 71 | + - plan |
| 72 | + strategy: |
| 73 | + fail-fast: false |
| 74 | + matrix: |
| 75 | + platform: ${{ fromJson(needs.plan.outputs.platforms) }} |
| 76 | + runs-on: ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-latest' }} |
| 77 | + steps: |
| 78 | + - name: Checkout |
| 79 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 80 | + with: |
| 81 | + persist-credentials: false |
| 82 | + |
| 83 | + - name: Get Target Architecture |
| 84 | + uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0 |
| 85 | + id: target |
| 86 | + with: |
| 87 | + script: |- |
| 88 | + core.setOutput('arch', '${{ matrix.platform }}'.split('/').pop()); |
| 89 | +
|
| 90 | + - name: Login to GitHub Container Registry |
| 91 | + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 |
| 92 | + with: |
| 93 | + registry: ghcr.io |
| 94 | + username: ${{ github.actor }} |
| 95 | + password: ${{ github.token }} |
| 96 | + |
| 97 | + - name: Download Bake Metadata |
| 98 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 99 | + with: |
| 100 | + name: ${{ inputs.variant }}-bake-metadata |
| 101 | + path: ${{ runner.temp }} |
| 102 | + |
| 103 | + - name: Setup Docker Buildx |
| 104 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 105 | + |
| 106 | + - name: Build Variant |
| 107 | + uses: docker/bake-action@a66e1c87e2eca0503c343edf1d208c716d54b8a8 # v7.1.0 |
| 108 | + id: bake |
| 109 | + with: |
| 110 | + files: | |
| 111 | + ./docker-bake.hcl |
| 112 | + cwd://${{ runner.temp }}/docker-metadata-action-bake.json |
| 113 | + targets: image-${{ inputs.variant }} |
| 114 | + set: | |
| 115 | + *.platform=${{ matrix.platform }} |
| 116 | + *.cache-from=${{ format('type=registry,ref=ghcr.io/{0}/immich-cache:{1}-{2}', github.repository_owner, inputs.variant, steps.target.outputs.arch) }} |
| 117 | + *.cache-to=${{ inputs.release && format('type=registry,ref=ghcr.io/{0}/immich-cache:{1}-{2},mode=max,compression=zstd,force-compression=true', github.repository_owner, inputs.variant, steps.target.outputs.arch) || '' }} |
| 118 | + *.labels.org.opencontainers.image.title=immich-${{ inputs.variant }} |
| 119 | + *.labels.org.opencontainers.image.version=${{ needs.plan.outputs.version }} |
| 120 | + *.labels.org.opencontainers.image.revision=${{ github.sha }} |
| 121 | + *.labels.org.opencontainers.image.vendor=${{ github.repository_owner }} |
| 122 | + *.output=type=image,name=ghcr.io/${{ github.repository_owner }}/immich,push-by-digest=true,name-canonical=true,push=true,compression=zstd,force-compression=true |
| 123 | + *.tags= |
| 124 | +
|
| 125 | + - name: Export Digest |
| 126 | + env: |
| 127 | + METADATA: ${{ steps.bake.outputs.metadata }} |
| 128 | + TARGET: image-${{ inputs.variant }} |
| 129 | + run: |- |
| 130 | + mkdir -p ${{ runner.temp }}/digests |
| 131 | + DIGEST=$(jq -r --arg t "$TARGET" '.[$t]["containerimage.digest"]' <<<"$METADATA") |
| 132 | + test -n "$DIGEST" || { echo "::error::bake metadata had no digest for target $TARGET"; jq . <<<"$METADATA"; exit 1; } |
| 133 | + touch "${{ runner.temp }}/digests/${DIGEST#sha256:}" |
| 134 | +
|
| 135 | + - name: Upload Digest |
| 136 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 137 | + with: |
| 138 | + name: ${{ inputs.variant }}-digests-${{ steps.target.outputs.arch }} |
| 139 | + path: ${{ runner.temp }}/digests/* |
| 140 | + if-no-files-found: error |
| 141 | + retention-days: 1 |
| 142 | + |
| 143 | + merge: |
| 144 | + name: Merge |
| 145 | + runs-on: ubuntu-latest |
| 146 | + needs: |
| 147 | + - build |
| 148 | + outputs: |
| 149 | + digest: ${{ steps.digest.outputs.digest }} |
| 150 | + steps: |
| 151 | + - name: Download Bake Metadata |
| 152 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 153 | + with: |
| 154 | + name: ${{ inputs.variant }}-bake-metadata |
| 155 | + path: ${{ runner.temp }} |
| 156 | + |
| 157 | + - name: Download Digests |
| 158 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 159 | + with: |
| 160 | + path: ${{ runner.temp }}/digests |
| 161 | + pattern: ${{ inputs.variant }}-digests-* |
| 162 | + merge-multiple: true |
| 163 | + |
| 164 | + - name: Login to GitHub Container Registry |
| 165 | + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 |
| 166 | + with: |
| 167 | + registry: ghcr.io |
| 168 | + username: ${{ github.actor }} |
| 169 | + password: ${{ github.token }} |
| 170 | + |
| 171 | + - name: Create Manifest List and Push |
| 172 | + working-directory: ${{ runner.temp }}/digests |
| 173 | + env: |
| 174 | + OWNER: ${{ github.repository_owner }} |
| 175 | + META: ${{ runner.temp }}/docker-metadata-action-bake.json |
| 176 | + run: |- |
| 177 | + docker buildx imagetools create \ |
| 178 | + $(jq --raw-output --compact-output ".target.\"docker-metadata-action\".tags | map(select(startswith(\"ghcr.io/$OWNER/immich\")) | \"-t \" + .) | join(\" \")" "$META") \ |
| 179 | + $(printf "ghcr.io/$OWNER/immich@sha256:%s " *) |
| 180 | +
|
| 181 | + - name: Inspect Image |
| 182 | + env: |
| 183 | + OWNER: ${{ github.repository_owner }} |
| 184 | + META: ${{ runner.temp }}/docker-metadata-action-bake.json |
| 185 | + run: |- |
| 186 | + TAG=$(jq --raw-output '.target."docker-metadata-action".args.DOCKER_META_VERSION' "$META") |
| 187 | + docker buildx imagetools inspect "ghcr.io/$OWNER/immich:$TAG" |
| 188 | +
|
| 189 | + - name: Export Digest |
| 190 | + id: digest |
| 191 | + env: |
| 192 | + OWNER: ${{ github.repository_owner }} |
| 193 | + META: ${{ runner.temp }}/docker-metadata-action-bake.json |
| 194 | + run: |- |
| 195 | + TAG=$(jq --raw-output '.target."docker-metadata-action".args.DOCKER_META_VERSION' "$META") |
| 196 | + DIGEST=$(docker buildx imagetools inspect "ghcr.io/$OWNER/immich:$TAG" --format '{{ json . }}' | jq --raw-output '.manifest.digest') |
| 197 | + echo "digest=$DIGEST" >>"$GITHUB_OUTPUT" |
| 198 | +
|
| 199 | + attest: |
| 200 | + name: Attest |
| 201 | + needs: |
| 202 | + - merge |
| 203 | + runs-on: ubuntu-latest |
| 204 | + steps: |
| 205 | + - name: Login to GitHub Container Registry |
| 206 | + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 |
| 207 | + with: |
| 208 | + registry: ghcr.io |
| 209 | + username: ${{ github.actor }} |
| 210 | + password: ${{ github.token }} |
| 211 | + |
| 212 | + - name: Upload Dependency Snapshot |
| 213 | + uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0 |
| 214 | + with: |
| 215 | + dependency-snapshot: true |
| 216 | + image: ghcr.io/${{ github.repository_owner }}/immich@${{ needs.merge.outputs.digest }} |
| 217 | + |
| 218 | + - name: Attestation |
| 219 | + uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0 |
| 220 | + with: |
| 221 | + push-to-registry: true |
| 222 | + subject-name: ghcr.io/${{ github.repository_owner }}/immich |
| 223 | + subject-digest: ${{ needs.merge.outputs.digest }} |
| 224 | + |
| 225 | + - name: Verify Attestation |
| 226 | + env: |
| 227 | + GITHUB_TOKEN: ${{ github.token }} |
| 228 | + run: |- |
| 229 | + gh attestation verify \ |
| 230 | + --repo ${{ github.repository }} \ |
| 231 | + oci://ghcr.io/${{ github.repository_owner }}/immich@${{ needs.merge.outputs.digest }} |
| 232 | +
|
| 233 | + test: |
| 234 | + if: ${{ ! inputs.release }} |
| 235 | + name: Test |
| 236 | + needs: |
| 237 | + - merge |
| 238 | + - attest |
| 239 | + runs-on: ubuntu-latest |
| 240 | + steps: |
| 241 | + - name: Checkout |
| 242 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 243 | + with: |
| 244 | + persist-credentials: false |
| 245 | + |
| 246 | + - name: Setup Go |
| 247 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 248 | + with: |
| 249 | + go-version-file: go.mod |
| 250 | + |
| 251 | + - name: Run Tests |
| 252 | + env: |
| 253 | + TEST_IMAGE: ghcr.io/${{ github.repository_owner }}/immich@${{ needs.merge.outputs.digest }} |
| 254 | + VARIANT: ${{ inputs.variant }} |
| 255 | + run: |- |
| 256 | + go test -v -timeout 15m ./tests/... |
0 commit comments