-
Notifications
You must be signed in to change notification settings - Fork 4
372 lines (280 loc) · 11.3 KB
/
Copy pathcontainer-image.yml
File metadata and controls
372 lines (280 loc) · 11.3 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
name: Container Image
on:
push:
branches: [develop]
tags: ['v*']
pull_request:
paths:
- 'crosslink/resources/container/**'
- '.github/workflows/container-image.yml'
- 'crosslink/Cargo.toml'
- 'crosslink/Cargo.lock'
workflow_dispatch:
permissions:
contents: read
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: crosslink-agent
jobs:
build-binary:
name: Build binary (${{ matrix.arch }})
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
include:
- arch: amd64
target: x86_64-unknown-linux-musl
use_cross: false
- arch: arm64
target: aarch64-unknown-linux-musl
use_cross: true
defaults:
run:
working-directory: crosslink
steps:
- uses: actions/checkout@v4
- name: Install musl-tools (amd64 native build)
if: matrix.use_cross == false
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (arm64 only)
if: matrix.use_cross == true
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
crosslink/target/
key: ${{ runner.os }}-cargo-container-${{ matrix.target }}-${{ hashFiles('crosslink/Cargo.lock') }}
- name: Build release binary (native)
if: matrix.use_cross == false
run: cargo build --locked --release --target ${{ matrix.target }}
- name: Build release binary (cross)
if: matrix.use_cross == true
run: cross build --locked --release --target ${{ matrix.target }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: crosslink-${{ matrix.arch }}
path: crosslink/target/${{ matrix.target }}/release/crosslink
if-no-files-found: error
retention-days: 1
publish-image:
name: Build & publish image
needs: build-binary
runs-on: ubuntu-latest
outputs:
primary_tag: ${{ steps.tags.outputs.primary_tag }}
version: ${{ steps.tags.outputs.version }}
pushed: ${{ steps.tags.outputs.pushed }}
steps:
- uses: actions/checkout@v4
- name: Download amd64 binary
uses: actions/download-artifact@v4
with:
name: crosslink-amd64
path: artifacts/amd64
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: crosslink-arm64
path: artifacts/arm64
- name: Stage binaries into build context
run: |
cp artifacts/amd64/crosslink crosslink/resources/container/crosslink-amd64
cp artifacts/arm64/crosslink crosslink/resources/container/crosslink-arm64
chmod +x crosslink/resources/container/crosslink-amd64
chmod +x crosslink/resources/container/crosslink-arm64
ls -lah crosslink/resources/container/
- name: Compute tags
id: tags
run: |
set -euo pipefail
REF="${GITHUB_REF}"
EVENT="${GITHUB_EVENT_NAME}"
SHORT_SHA="$(echo "${GITHUB_SHA}" | cut -c1-7)"
OWNER="$(printf '%s' "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')"
BASE="${REGISTRY}/${OWNER}/${IMAGE_NAME}"
TAGS=()
PUSH=false
PRIMARY=""
VERSION=""
if [ "$EVENT" = "pull_request" ]; then
TAGS=("${BASE}:pr-${{ github.event.pull_request.number }}")
PRIMARY="${BASE}:pr-${{ github.event.pull_request.number }}"
VERSION="pr-${{ github.event.pull_request.number }}"
elif [[ "$REF" == refs/tags/v* ]]; then
VERSION="${REF#refs/tags/v}"
TAGS=("${BASE}:${VERSION}" "${BASE}:latest")
PRIMARY="${BASE}:${VERSION}"
PUSH=true
elif [ "$REF" = "refs/heads/develop" ]; then
VERSION="nightly-${SHORT_SHA}"
TAGS=("${BASE}:nightly" "${BASE}:nightly-${SHORT_SHA}")
PRIMARY="${BASE}:nightly"
PUSH=true
elif [ "$EVENT" = "workflow_dispatch" ]; then
VERSION="manual-${SHORT_SHA}"
TAGS=("${BASE}:nightly" "${BASE}:manual-${SHORT_SHA}")
PRIMARY="${BASE}:nightly"
PUSH=true
else
echo "::error::Unexpected ref/event combination: ref=${REF} event=${EVENT}"
exit 1
fi
{
echo "tags<<EOF"
for t in "${TAGS[@]}"; do echo "$t"; done
echo "EOF"
echo "push=${PUSH}"
echo "primary_tag=${PRIMARY}"
echo "version=${VERSION}"
echo "pushed=${PUSH}"
echo "cache_ref=${BASE}:buildcache"
} >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: steps.tags.outputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: crosslink/resources/container
file: crosslink/resources/container/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ steps.tags.outputs.push == 'true' }}
tags: ${{ steps.tags.outputs.tags }}
provenance: false
cache-from: type=registry,ref=${{ steps.tags.outputs.cache_ref }}
cache-to: ${{ steps.tags.outputs.push == 'true' && format('type=registry,ref={0},mode=max', steps.tags.outputs.cache_ref) || '' }}
container-pr-smoke:
name: Provider smoke (PR)
needs: build-binary
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: crosslink-amd64
path: artifacts/amd64
- name: Stage amd64 binary
run: |
cp artifacts/amd64/crosslink crosslink/resources/container/crosslink-amd64
chmod +x crosslink/resources/container/crosslink-amd64
- name: Build native smoke image
run: docker build --build-arg TARGETARCH=amd64 -t crosslink-agent:pr-smoke crosslink/resources/container
- name: Verify both CLIs and non-root dispatch
run: |
set -euo pipefail
docker run --rm -e CROSSLINK_AGENT_PROVIDER=claude crosslink-agent:pr-smoke bash -c 'test "$(id -u)" != 0 && claude --version'
docker run --rm -e CROSSLINK_AGENT_PROVIDER=codex crosslink-agent:pr-smoke bash -c 'test "$(id -u)" != 0 && codex --version'
- name: Verify timeout parity and no key environment
run: |
set -euo pipefail
for provider in claude codex; do
status="$(docker run --rm -e CROSSLINK_AGENT_PROVIDER="$provider" crosslink-agent:pr-smoke bash -c 'timeout 1s sh -c "sleep 5"; printf "%s\n" "$?"' | tail -n 1)"
test "$status" = 124
done
if docker inspect crosslink-agent:pr-smoke --format '{{json .Config.Env}}' \
| grep -E 'ANTHROPIC_API_KEY|OPENAI_API_KEY|CODEX_API_KEY'; then
echo 'Container image unexpectedly contains an API-key environment variable.' >&2
exit 1
fi
- name: Verify isolated account volumes and redacted status
run: |
set -euo pipefail
for provider in claude codex; do
volume="crosslink-pr-auth-${provider}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
docker volume create "$volume" >/dev/null
docker run --rm -v "$volume:/home/agent/.${provider}" --entrypoint sh crosslink-agent:pr-smoke -c 'printf refreshed > "$1/session-state"' sh "/home/agent/.${provider}"
state="$(docker run --rm -v "$volume:/home/agent/.${provider}" --entrypoint sh crosslink-agent:pr-smoke -c 'cat "$1/session-state"' sh "/home/agent/.${provider}")"
test "$state" = refreshed
if [ "$provider" = codex ]; then
status_command='codex login status'
else
status_command='claude auth status'
fi
status="$(docker run --rm -v "$volume:/home/agent/.${provider}" crosslink-agent:pr-smoke sh -c "$status_command" 2>&1 || true)"
if printf '%s' "$status" | grep -E 'sk-[A-Za-z0-9]|ANTHROPIC_API_KEY|OPENAI_API_KEY|CODEX_API_KEY'; then
echo 'Provider status exposed key-shaped account data.' >&2
exit 1
fi
docker volume rm "$volume" >/dev/null
if docker volume inspect "$volume" >/dev/null 2>&1; then
echo "Provider volume was not removed: $volume" >&2
exit 1
fi
done
smoke-verify:
name: Smoke verify (${{ matrix.platform }})
needs: publish-image
if: needs.publish-image.outputs.pushed == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: Set up QEMU (for non-native arch)
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull image
run: docker pull --platform ${{ matrix.platform }} ${{ needs.publish-image.outputs.primary_tag }}
- name: Inspect manifest covers both arches (once per matrix is fine)
if: matrix.platform == 'linux/amd64'
run: |
docker manifest inspect ${{ needs.publish-image.outputs.primary_tag }} \
| jq -e '[.manifests[].platform | "\(.os)/\(.architecture)"] | sort | . == ["linux/amd64","linux/arm64"]'
- name: Run crosslink --version
id: version
run: |
set -euo pipefail
OUT=$(docker run --rm --platform ${{ matrix.platform }} \
--entrypoint /usr/local/bin/crosslink \
${{ needs.publish-image.outputs.primary_tag }} --version)
echo "version output: $OUT"
echo "out=$OUT" >> "$GITHUB_OUTPUT"
echo "$OUT" | grep -E '^crosslink [0-9]+\.[0-9]+\.[0-9]+'
- name: Verify version matches tag (release tags only)
if: startsWith(github.ref, 'refs/tags/v')
run: |
EXPECTED="${{ needs.publish-image.outputs.version }}"
ACTUAL=$(echo "${{ steps.version.outputs.out }}" | awk '{print $2}' | sed 's/+.*//')
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "::error::Tag version ($EXPECTED) does not match binary version ($ACTUAL)"
exit 1
fi
echo "Version match: $EXPECTED"