Repository navigation
166 lines (161 loc) · 6.81 KB
/
Copy pathci-image-cache.yml
File metadata and controls
166 lines (161 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: CI Image Cache
# Writes main's BuildKit cache for the controller and runtime images that the CI
# image lanes restore; it is the only writer. This run starts on every image
# input change (and on a schedule, from main's newest commit) and is never
# cancelled once started. Queued runs wait for the writer; their source commits
# need not be chronological.
# GitHub scopes cache writes to the run's ref: pull_request runs read main's
# entries but write only their own merge ref.
on:
push:
branches:
- main
# Inputs of the two image builds (both Dockerfiles' COPY and bind sources),
# the lane's Node base image pin, the build code and this workflow. Other
# changes leave the cache keys unchanged. A conformance test keeps this list
# covering the Dockerfiles.
paths:
- .dockerignore
- .github/workflows/ci-image-cache.yml
- Dockerfile
- LICENSE
- apps/controller/**
- deploy/presets/**
- deploy/runtime/**
- migrations/**
- package.json
- packages/**
- pnpm-lock.yaml
- pnpm-workspace.yaml
- scripts/*.mjs
- scripts/migrate-production.ts
- scripts/auth-maintain.ts
- scripts/build-repository-credentials.ts
- scripts/build-runtime-assets.ts
- scripts/ci/download-pinned.sh
- scripts/ci/prepare.ts
- scripts/ci/prepare-inputs.ts
- scripts/ci/warm-image-cache.ts
- scripts/ci/prepare-command.ts
- scripts/ci/command-supervision.ts
- scripts/ci/image-build-cache.ts
- scripts/ci/fixture-support-images.ts
- scripts/ci/k3d-preparation.ts
- scripts/ci/k3d-image-admission.ts
- scripts/ci/test-suites.ts
- scripts/ci/openshell-full-integration.ts
- scripts/ci/resource-names.ts
- scripts/ci/test-suites/images-packaging.json
- scripts/lib/**
- scripts/migration-catalog.ts
- scripts/migration-history-preflight.ts
- scripts/production-healthcheck.ts
- scripts/write-inspected-workspace-image-pin.ts
- tsconfig.base.json
- tsconfig.json
# The kept runtime image reaches Blacksmith's shared Docker store only if this
# job's store commit wins against concurrent jobs' commits from the same
# snapshot, and on 10-14 one of five did. A run whose store already holds
# main's image builds from cache and commits nothing, so retrying on a
# schedule costs about two minutes.
schedule:
- cron: "7,27,47 * * * *"
workflow_dispatch:
workflow_call:
inputs:
source_sha:
type: string
default: ""
description: Approved Release OCE checkout.
require-export:
type: boolean
default: false
node-base-image:
type: string
default: ""
outputs:
source-sha:
description: Processed source; required exports fail the job if either export fails.
value: ${{ jobs.warm.outputs.source-sha }}
permissions:
contents: read
# One writer at a time; timer runs must not replace a waiting prerequisite.
concurrency:
group: ci-image-cache-${{ github.ref }}
cancel-in-progress: false
queue: max
env:
CI: "1"
NODE_VERSION: "24.22.1"
jobs:
warm:
name: Warm Image Cache
if: ${{ github.ref == 'refs/heads/main' && (!inputs.require-export || github.repository == 'openclaw/openclaw-enterprise') }}
outputs:
source-sha: ${{ steps.export.outputs.source-sha }}
# The image lanes' runner, so the cache is written where they read it.
runs-on: blacksmith-8vcpu-ubuntu-2404
# Each image build and cache export can take 20 min. Builds run side by side.
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Verify checkout source
run: test "$(git rev-parse --verify 'HEAD^{commit}')" = "$GITHUB_SHA"
- name: Select the approved release checkout
if: inputs.source_sha != '' || github.workflow_ref == 'openclaw/openclaw-enterprise/.github/workflows/release-oce.yml@refs/heads/main'
uses: ./.github/actions/select-integration-source
with:
source-sha: ${{ inputs.source_sha }}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Validate required cache input
if: ${{ inputs.require-export }}
env:
CACHE_NODE_BASE_IMAGE: ${{ inputs.node-base-image }}
run: |
node scripts/ci/warm-image-cache.ts --validate-node-base-image "$CACHE_NODE_BASE_IMAGE"
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Expose image cache credentials
id: image-cache
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const token = process.env.ACTIONS_RUNTIME_TOKEN;
const url = process.env.ACTIONS_RESULTS_URL;
if (!token || !url) {
throw new Error('GitHub Actions cache credentials are unavailable');
}
core.setSecret(token);
// The cache service grants this token the scopes in its "ac" claim
// (Permission bit 2 is write). Export only if main is the sole writable scope.
const claims = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString('utf8'));
const scopes = JSON.parse(claims.ac ?? '[]');
core.info(`Cache scopes: ${scopes.map(({ Scope, Permission }) => `${Scope} (${Permission})`).join(', ')}`);
const writable = scopes.filter(({ Permission }) => (Permission & 2) !== 0).map(({ Scope }) => Scope);
if (writable.length !== 1 || writable[0] !== 'refs/heads/main') {
throw new Error(`The image cache warms only main's scope; this token's scopes: ${JSON.stringify(scopes)}`);
}
core.setOutput('token', token);
core.setOutput('url', url);
- name: Build images and export their cache
id: export
env:
OCC_CI_IMAGE_CACHE: "1"
REQUIRE_CACHE_EXPORT: ${{ inputs.require-export }}
CACHE_NODE_BASE_IMAGE: ${{ inputs.node-base-image }}
ACTIONS_RUNTIME_TOKEN: ${{ steps.image-cache.outputs.token }}
ACTIONS_RESULTS_URL: ${{ steps.image-cache.outputs.url }}
run: |
args=()
if [[ "$REQUIRE_CACHE_EXPORT" == "true" ]]; then
args+=(--require-cache-export --node-base-image "$CACHE_NODE_BASE_IMAGE")
fi
node scripts/ci/warm-image-cache.ts --state "$RUNNER_TEMP/state/image-cache-warm.json" "${args[@]}"
echo "source-sha=$GITHUB_SHA" >> "$GITHUB_OUTPUT"
- name: Cleanup
if: always()
run: node scripts/ci/cleanup.ts --state "$RUNNER_TEMP/state/image-cache-warm.json"