|
| 1 | +name: Publish Application Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + matrix: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + matrix: ${{ steps.out.outputs.matrix }} |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - id: out |
| 17 | + name: Build publish matrix from apps-manifest.json |
| 18 | + run: | |
| 19 | + python3 - <<'PY' >>"${GITHUB_OUTPUT}" |
| 20 | + import json |
| 21 | + from pathlib import Path |
| 22 | +
|
| 23 | + manifest = json.loads(Path("apps-manifest.json").read_text(encoding="utf-8")) |
| 24 | + include = [] |
| 25 | + for app in manifest["apps"]: |
| 26 | + include.append( |
| 27 | + { |
| 28 | + "app_id": app["app_id"], |
| 29 | + "display_name": app["display_name"], |
| 30 | + "source_path": app["source_path"], |
| 31 | + "image_repo": app["image_repo"], |
| 32 | + "default_tag": app["default_tag"], |
| 33 | + } |
| 34 | + ) |
| 35 | + print(f"matrix={json.dumps({'include': include})}") |
| 36 | + PY |
| 37 | +
|
| 38 | + publish: |
| 39 | + needs: matrix |
| 40 | + runs-on: ubuntu-latest |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + packages: write |
| 44 | + strategy: |
| 45 | + fail-fast: false |
| 46 | + matrix: ${{ fromJson(needs.matrix.outputs.matrix) }} |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + - uses: docker/setup-buildx-action@v3 |
| 50 | + - uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ghcr.io |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + - id: build |
| 56 | + name: Build and publish ${{ matrix.display_name }} |
| 57 | + uses: docker/build-push-action@v6 |
| 58 | + with: |
| 59 | + context: ${{ matrix.source_path }} |
| 60 | + push: true |
| 61 | + tags: | |
| 62 | + ${{ matrix.image_repo }}:${{ matrix.default_tag }} |
| 63 | + ${{ matrix.image_repo }}:sha-${{ github.sha }} |
| 64 | + - name: Write publish record |
| 65 | + run: | |
| 66 | + mkdir -p dist |
| 67 | + python3 - <<'PY' |
| 68 | + import json |
| 69 | + import os |
| 70 | + from pathlib import Path |
| 71 | +
|
| 72 | + record = { |
| 73 | + "schema": 1, |
| 74 | + "kind": "ourbox-application-image-publish-record", |
| 75 | + "app_id": os.environ["APP_ID"], |
| 76 | + "display_name": os.environ["DISPLAY_NAME"], |
| 77 | + "image_repo": os.environ["IMAGE_REPO"], |
| 78 | + "default_tag": os.environ["DEFAULT_TAG"], |
| 79 | + "pinned_ref": f"{os.environ['IMAGE_REPO']}@{os.environ['DIGEST']}", |
| 80 | + "digest": os.environ["DIGEST"], |
| 81 | + "source_path": os.environ["SOURCE_PATH"], |
| 82 | + "github_sha": os.environ["GITHUB_SHA"], |
| 83 | + "github_run_id": os.environ["GITHUB_RUN_ID"], |
| 84 | + "github_run_attempt": os.environ["GITHUB_RUN_ATTEMPT"], |
| 85 | + } |
| 86 | + out = Path("dist") / f"{os.environ['APP_ID']}.publish-record.json" |
| 87 | + out.write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8") |
| 88 | + PY |
| 89 | + env: |
| 90 | + APP_ID: ${{ matrix.app_id }} |
| 91 | + DISPLAY_NAME: ${{ matrix.display_name }} |
| 92 | + SOURCE_PATH: ${{ matrix.source_path }} |
| 93 | + IMAGE_REPO: ${{ matrix.image_repo }} |
| 94 | + DEFAULT_TAG: ${{ matrix.default_tag }} |
| 95 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 96 | + - uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: ${{ matrix.app_id }}-publish-record |
| 99 | + path: dist/${{ matrix.app_id }}.publish-record.json |
0 commit comments