|
| 1 | +name: Framework Build Base Image |
| 2 | + |
| 3 | +# Builds and pushes ghcr.io/objectstack-ai/framework-build-base:<sha> from |
| 4 | +# docker/framework-build-base/Dockerfile: ONE framework commit on `main`, its |
| 5 | +# workspace dependencies installed, every package built, and the Console built |
| 6 | +# into packages/console/dist. It is a builder stage for downstream images that |
| 7 | +# link the framework by path and pin it by commit, so they can start FROM it |
| 8 | +# instead of installing and building the whole framework on every cold cache. |
| 9 | +# It is NOT the runtime image; that one is docker-publish.yml. |
| 10 | +# |
| 11 | +# On demand only, never per commit: |
| 12 | +# - workflow_dispatch, from main, with `sha` = a full commit on main; |
| 13 | +# - repository_dispatch, event type `framework-build-base`, with |
| 14 | +# client_payload {"sha": "<40 hex>"}: the hook a downstream pin move can call; |
| 15 | +# - pull_request touching this file or docker/framework-build-base/: the dry |
| 16 | +# run of a change to the image definition. It builds the PR's base commit |
| 17 | +# with the PR's Dockerfile and pushes nothing; its job has no packages grant. |
| 18 | +# |
| 19 | +# A tag is written once. A request for a commit whose tag already exists reports |
| 20 | +# the existing digest and builds nothing (dispatch with `rebuild: true` to |
| 21 | +# replace it), so a downstream can ask on every pin move at no cost. |
| 22 | +# |
| 23 | +# The image definition always comes from THIS run's checkout of main; only the |
| 24 | +# build context is the requested commit. So a commit that predates this file can |
| 25 | +# be packaged, and a commit cannot bring its own Dockerfile into a published image. |
| 26 | +# |
| 27 | +# Visibility: GitHub creates a new container package private on its first push, |
| 28 | +# and no API changes that. The maintainer sets it Public once, in the package's |
| 29 | +# settings (Danger Zone, Change visibility; it cannot be made private again). |
| 30 | +# Until then the anonymous-pull step below is red and names that fix. |
| 31 | + |
| 32 | +on: |
| 33 | + workflow_dispatch: |
| 34 | + inputs: |
| 35 | + sha: |
| 36 | + description: 'Full 40-hex framework commit on main to package (e.g. a downstream .objectstack-sha)' |
| 37 | + required: true |
| 38 | + type: string |
| 39 | + rebuild: |
| 40 | + description: 'Rebuild and re-push even when the tag already exists (the digest changes)' |
| 41 | + required: false |
| 42 | + type: boolean |
| 43 | + default: false |
| 44 | + repository_dispatch: |
| 45 | + types: [framework-build-base] |
| 46 | + pull_request: |
| 47 | + paths: |
| 48 | + - '.github/workflows/framework-build-base.yml' |
| 49 | + - 'docker/framework-build-base/**' |
| 50 | + |
| 51 | +permissions: |
| 52 | + contents: read |
| 53 | + |
| 54 | +# One build per commit at a time; a second request for the same commit waits, |
| 55 | +# then finds the tag and builds nothing. A PR's dry run is superseded by its |
| 56 | +# next push. |
| 57 | +concurrency: |
| 58 | + group: framework-build-base-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.event.client_payload.sha || inputs.sha }} |
| 59 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 60 | + |
| 61 | +env: |
| 62 | + IMAGE: ghcr.io/objectstack-ai/framework-build-base |
| 63 | + |
| 64 | +jobs: |
| 65 | + verify: |
| 66 | + name: Build framework build base (dry run, no push) |
| 67 | + if: github.event_name == 'pull_request' |
| 68 | + runs-on: ubuntu-latest |
| 69 | + # The same build as `publish` below; see its budget note. |
| 70 | + timeout-minutes: 60 |
| 71 | + permissions: |
| 72 | + contents: read |
| 73 | + steps: |
| 74 | + - name: Free runner disk |
| 75 | + run: | |
| 76 | + set -euxo pipefail |
| 77 | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL |
| 78 | + sudo docker image prune -af || true |
| 79 | + df -h / |
| 80 | +
|
| 81 | + - name: Check out the image definition (this pull request) |
| 82 | + uses: actions/checkout@v7 |
| 83 | + with: |
| 84 | + ref: ${{ github.event.pull_request.head.sha }} |
| 85 | + path: builder |
| 86 | + persist-credentials: false |
| 87 | + sparse-checkout: docker/framework-build-base |
| 88 | + |
| 89 | + - name: Check out the framework commit (the pull request's base) |
| 90 | + uses: actions/checkout@v7 |
| 91 | + with: |
| 92 | + ref: ${{ github.event.pull_request.base.sha }} |
| 93 | + path: objectstack |
| 94 | + persist-credentials: false |
| 95 | + |
| 96 | + - name: Set up Docker Buildx |
| 97 | + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 |
| 98 | + |
| 99 | + - name: Note the build start |
| 100 | + id: clock |
| 101 | + run: echo "start=$(date +%s)" >> "$GITHUB_OUTPUT" |
| 102 | + |
| 103 | + - name: Build (load into the runner, never push) |
| 104 | + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 |
| 105 | + with: |
| 106 | + context: objectstack |
| 107 | + file: builder/docker/framework-build-base/Dockerfile |
| 108 | + platforms: linux/amd64 |
| 109 | + push: false |
| 110 | + load: true |
| 111 | + provenance: false |
| 112 | + sbom: false |
| 113 | + build-args: | |
| 114 | + FRAMEWORK_SHA=${{ github.event.pull_request.base.sha }} |
| 115 | + tags: framework-build-base:dry-run |
| 116 | + |
| 117 | + - name: Look inside the image |
| 118 | + env: |
| 119 | + SHA: ${{ github.event.pull_request.base.sha }} |
| 120 | + START: ${{ steps.clock.outputs.start }} |
| 121 | + run: | |
| 122 | + set -euo pipefail |
| 123 | + BUILD_S=$(( $(date +%s) - START )) |
| 124 | + READINGS="$(bash builder/docker/framework-build-base/check-image.sh framework-build-base:dry-run "$SHA")" |
| 125 | + echo "$READINGS" |
| 126 | + { |
| 127 | + echo "### Framework build base, dry run (nothing pushed)" |
| 128 | + echo |
| 129 | + echo "- framework commit (PR base): \`$SHA\`" |
| 130 | + echo "- build wall: ${BUILD_S} s" |
| 131 | + echo "$READINGS" | sed 's/^/- /' |
| 132 | + } >> "$GITHUB_STEP_SUMMARY" |
| 133 | +
|
| 134 | + publish: |
| 135 | + name: Build & push ghcr.io/objectstack-ai/framework-build-base |
| 136 | + # Trusted runs only: a dispatch from main, or a repository_dispatch (which |
| 137 | + # always runs main's copy of this file). This `if` is the policy, not a |
| 138 | + # security boundary: anyone who can push a branch can also edit it there. |
| 139 | + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' |
| 140 | + runs-on: ubuntu-latest |
| 141 | + # No reading of this workflow is on record yet. The same build, as a stage |
| 142 | + # of downstream image builds on this runner class, runs about 20 minutes |
| 143 | + # cold; the budget leaves room for a slow npm and the anonymous pull. |
| 144 | + timeout-minutes: 60 |
| 145 | + permissions: |
| 146 | + contents: read |
| 147 | + packages: write |
| 148 | + steps: |
| 149 | + - name: Resolve the framework commit |
| 150 | + id: sha |
| 151 | + env: |
| 152 | + REQUESTED: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.sha || inputs.sha }} |
| 153 | + GH_TOKEN: ${{ github.token }} |
| 154 | + REPO: ${{ github.repository }} |
| 155 | + run: | |
| 156 | + set -euo pipefail |
| 157 | + SHA="$(printf '%s' "$REQUESTED" | tr -d '[:space:]')" |
| 158 | + if ! printf '%s' "$SHA" | grep -Eq '^[0-9a-f]{40}$'; then |
| 159 | + echo "::error::the requested commit is not a full 40-hex lowercase sha" |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | + # Only commits on main are packaged: main must be ahead of the commit, |
| 163 | + # or be it. Anything else (a branch head, a fork's pull ref) is refused. |
| 164 | + if ! STATUS="$(gh api "repos/$REPO/compare/$SHA...main" --jq .status)"; then |
| 165 | + echo "::error::cannot compare $SHA with main (is it a commit of $REPO?)" |
| 166 | + exit 1 |
| 167 | + fi |
| 168 | + case "$STATUS" in |
| 169 | + ahead|identical) ;; |
| 170 | + *) echo "::error::$SHA is not on main (compare status: $STATUS); only commits on main are packaged"; exit 1 ;; |
| 171 | + esac |
| 172 | + echo "sha=$SHA" >> "$GITHUB_OUTPUT" |
| 173 | +
|
| 174 | + - name: Set up Docker Buildx |
| 175 | + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 |
| 176 | + |
| 177 | + - name: Log in to ghcr.io |
| 178 | + uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 |
| 179 | + with: |
| 180 | + registry: ghcr.io |
| 181 | + username: ${{ github.actor }} |
| 182 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 183 | + |
| 184 | + - name: Is this commit already packaged |
| 185 | + id: existing |
| 186 | + env: |
| 187 | + REF: ${{ env.IMAGE }}:${{ steps.sha.outputs.sha }} |
| 188 | + REBUILD: ${{ inputs.rebuild && 'true' || 'false' }} |
| 189 | + run: | |
| 190 | + set -euo pipefail |
| 191 | + DIGEST="$(docker buildx imagetools inspect "$REF" --format '{{json .Manifest}}' 2>/dev/null | jq -r '.digest // empty' || true)" |
| 192 | + if [ -n "$DIGEST" ] && [ "$REBUILD" != true ]; then |
| 193 | + echo "$REF already exists at $DIGEST; nothing to build (dispatch with rebuild: true to replace it)." |
| 194 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 195 | + echo "digest=$DIGEST" >> "$GITHUB_OUTPUT" |
| 196 | + else |
| 197 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 198 | + fi |
| 199 | +
|
| 200 | + - name: Free runner disk |
| 201 | + if: steps.existing.outputs.skip != 'true' |
| 202 | + run: | |
| 203 | + set -euxo pipefail |
| 204 | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL |
| 205 | + sudo docker image prune -af || true |
| 206 | + df -h / |
| 207 | +
|
| 208 | + - name: Check out the image definition (this run's main) |
| 209 | + if: steps.existing.outputs.skip != 'true' |
| 210 | + uses: actions/checkout@v7 |
| 211 | + with: |
| 212 | + path: builder |
| 213 | + persist-credentials: false |
| 214 | + sparse-checkout: docker/framework-build-base |
| 215 | + |
| 216 | + - name: Check out the framework commit (the build context) |
| 217 | + if: steps.existing.outputs.skip != 'true' |
| 218 | + uses: actions/checkout@v7 |
| 219 | + with: |
| 220 | + ref: ${{ steps.sha.outputs.sha }} |
| 221 | + path: objectstack |
| 222 | + persist-credentials: false |
| 223 | + |
| 224 | + - name: Note the build start |
| 225 | + if: steps.existing.outputs.skip != 'true' |
| 226 | + id: clock |
| 227 | + env: |
| 228 | + SHA: ${{ steps.sha.outputs.sha }} |
| 229 | + run: | |
| 230 | + set -euo pipefail |
| 231 | + [ "$(git -C objectstack rev-parse HEAD)" = "$SHA" ] || { echo "::error::the context checkout is not $SHA"; exit 1; } |
| 232 | + echo "start=$(date +%s)" >> "$GITHUB_OUTPUT" |
| 233 | +
|
| 234 | + - name: Build and push |
| 235 | + if: steps.existing.outputs.skip != 'true' |
| 236 | + id: build |
| 237 | + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 |
| 238 | + with: |
| 239 | + context: objectstack |
| 240 | + file: builder/docker/framework-build-base/Dockerfile |
| 241 | + platforms: linux/amd64 |
| 242 | + push: true |
| 243 | + provenance: false |
| 244 | + sbom: false |
| 245 | + build-args: | |
| 246 | + FRAMEWORK_SHA=${{ steps.sha.outputs.sha }} |
| 247 | + tags: ${{ env.IMAGE }}:${{ steps.sha.outputs.sha }} |
| 248 | + |
| 249 | + - name: Note the build wall |
| 250 | + if: steps.existing.outputs.skip != 'true' |
| 251 | + id: wall |
| 252 | + env: |
| 253 | + START: ${{ steps.clock.outputs.start }} |
| 254 | + run: echo "seconds=$(( $(date +%s) - START ))" >> "$GITHUB_OUTPUT" |
| 255 | + |
| 256 | + # The image is for anyone to pull, so it is read back the way a stranger |
| 257 | + # would: logged out. A fresh build is pulled whole and looked inside; an |
| 258 | + # existing tag only has its manifest read, anonymously. |
| 259 | + - name: Pull the image anonymously |
| 260 | + id: pull |
| 261 | + env: |
| 262 | + SHA: ${{ steps.sha.outputs.sha }} |
| 263 | + DIGEST: ${{ steps.build.outputs.digest || steps.existing.outputs.digest }} |
| 264 | + FRESH: ${{ steps.existing.outputs.skip != 'true' }} |
| 265 | + run: | |
| 266 | + set -euo pipefail |
| 267 | + docker logout ghcr.io |
| 268 | + REF="$IMAGE@$DIGEST" |
| 269 | + PRIVATE="::error::$IMAGE cannot be read anonymously. A new container package is private: the maintainer sets it Public once, in the package's settings (Danger Zone, Change visibility)." |
| 270 | + if [ "$FRESH" = true ]; then |
| 271 | + docker pull "$REF" || { echo "$PRIVATE"; exit 1; } |
| 272 | + bash builder/docker/framework-build-base/check-image.sh "$REF" "$SHA" | tee "$RUNNER_TEMP/readings.txt" |
| 273 | + else |
| 274 | + TOKEN="$(curl -fsS "https://ghcr.io/token?scope=repository:objectstack-ai/framework-build-base:pull&service=ghcr.io" | jq -r .token)" \ |
| 275 | + && curl -fsS -o /dev/null -H "Authorization: Bearer $TOKEN" \ |
| 276 | + -H 'Accept: application/vnd.oci.image.manifest.v1+json' \ |
| 277 | + -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \ |
| 278 | + "https://ghcr.io/v2/objectstack-ai/framework-build-base/manifests/$DIGEST" \ |
| 279 | + || { echo "$PRIVATE"; exit 1; } |
| 280 | + echo "manifest readable anonymously" > "$RUNNER_TEMP/readings.txt" |
| 281 | + fi |
| 282 | +
|
| 283 | + - name: Summary |
| 284 | + if: always() && steps.sha.outputs.sha != '' |
| 285 | + env: |
| 286 | + SHA: ${{ steps.sha.outputs.sha }} |
| 287 | + DIGEST: ${{ steps.build.outputs.digest || steps.existing.outputs.digest }} |
| 288 | + SKIPPED: ${{ steps.existing.outputs.skip }} |
| 289 | + WALL: ${{ steps.wall.outputs.seconds }} |
| 290 | + PULL: ${{ steps.pull.outcome }} |
| 291 | + run: | |
| 292 | + { |
| 293 | + echo "### $IMAGE" |
| 294 | + echo |
| 295 | + echo "- framework commit: \`$SHA\`" |
| 296 | + echo "- tag: \`$IMAGE:$SHA\`" |
| 297 | + echo "- digest: \`${DIGEST:-none}\`" |
| 298 | + if [ "$SKIPPED" = true ]; then |
| 299 | + echo "- build: skipped, the tag already existed" |
| 300 | + else |
| 301 | + echo "- build wall: ${WALL:-not reached} s" |
| 302 | + fi |
| 303 | + echo "- anonymous read: ${PULL:-not reached}" |
| 304 | + if [ -f "$RUNNER_TEMP/readings.txt" ]; then sed 's/^/- /' "$RUNNER_TEMP/readings.txt"; fi |
| 305 | + if [ -n "$DIGEST" ]; then |
| 306 | + echo |
| 307 | + echo "Pin it by digest: \`FROM $IMAGE:$SHA@$DIGEST\`" |
| 308 | + fi |
| 309 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments