Skip to content

Commit b8293bb

Browse files
authored
Merge pull request #2 from cbarreholm/tests
Tests
2 parents 8e70d9c + 18e02ec commit b8293bb

4 files changed

Lines changed: 89 additions & 6 deletions

File tree

.github/workflows/build-and-push.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
password: ${{ secrets.GITHUB_TOKEN }}
2727

2828
- name: Build Image with buildah script
29+
id: build
2930
env:
3031
STORAGE_DRIVER: vfs
3132
run: |
@@ -34,12 +35,19 @@ jobs:
3435
3536
# Run the build script
3637
VERSION=$(./devops/build-image.sh -repo-name $REPO_NAME | tail -n2 | head -n1 | cut -d: -f2)
37-
38+
3839
# Tag the image for GHCR
3940
buildah tag claude-code \
4041
"ghcr.io/$REPO_NAME/claude-code:$VERSION" \
4142
"ghcr.io/$REPO_NAME/claude-code:latest"
42-
43-
# Push to GitHub Container Registry
44-
buildah push "ghcr.io/$REPO_NAME/claude-code:$VERSION"
45-
buildah push "ghcr.io/$REPO_NAME/claude-code:latest"
43+
44+
echo "repo_name=$REPO_NAME" >> "$GITHUB_OUTPUT"
45+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
46+
47+
- name: Test image
48+
run: ./tests/test-image.sh "${{ steps.build.outputs.version }}"
49+
50+
- name: Push to GitHub Container Registry
51+
run: |
52+
buildah push "ghcr.io/${{ steps.build.outputs.repo_name }}/claude-code:${{ steps.build.outputs.version }}"
53+
buildah push "ghcr.io/${{ steps.build.outputs.repo_name }}/claude-code:latest"

bin/claude

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ while [[ $# -gt 0 ]]; do
2323
--init-script FILE Execute initialization script
2424
--apk-packages LIST Install additional Alpine packages (comma or space separated)
2525
--podman-arg ARG Pass additional argument to podman
26+
--version Show the Claude Code version in the image
2627
--help Display this help message
2728
EOT
2829
exit 0
@@ -52,6 +53,15 @@ while [[ $# -gt 0 ]]; do
5253
PODMAN_ARGS="$PODMAN_ARGS $2"
5354
shift 2
5455
;;
56+
--version)
57+
podman run \
58+
--rm \
59+
--user claude \
60+
--userns=keep-id:uid=1001,gid=1001 \
61+
$PODMAN_ARGS \
62+
"$IMAGE" --version
63+
exit 0
64+
;;
5565
*)
5666
break
5767
;;

devops/build-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ buildah commit \
6464
--rm \
6565
"$CONTAINER" "$IMAGE"
6666

67-
buildah tag "$IMAGE" "$CLAUDE_VERSION"
67+
buildah tag "$IMAGE" "$IMAGE:$CLAUDE_VERSION"
6868

6969
echo Done!
7070
echo ${IMAGE}:${CLAUDE_VERSION}

tests/test-image.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
IMAGE="localhost/claude-code:${1:-latest}"
5+
PASS=0
6+
FAIL=0
7+
8+
run_test() {
9+
local name="$1"
10+
shift
11+
printf "TEST: %s ... " "$name"
12+
if "$@"; then
13+
echo "PASS"
14+
PASS=$((PASS + 1))
15+
else
16+
echo "FAIL"
17+
FAIL=$((FAIL + 1))
18+
fi
19+
}
20+
21+
# 1. Image exists
22+
run_test "Image exists" \
23+
podman image exists "$IMAGE"
24+
25+
# 2. Claude binary runs and outputs a version
26+
test_claude_version() {
27+
local output
28+
output=$(podman run --rm --entrypoint "" "$IMAGE" \
29+
/home/claude/.local/bin/claude --version 2>&1)
30+
echo "$output" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'
31+
}
32+
run_test "Claude binary outputs version" \
33+
test_claude_version
34+
35+
# 3. Entrypoint is set correctly
36+
test_entrypoint() {
37+
local entrypoint
38+
entrypoint=$(podman inspect --format '{{range .Config.Entrypoint}}{{.}}{{end}}' "$IMAGE")
39+
[ "$entrypoint" = "/home/claude/.local/bin/claude" ]
40+
}
41+
run_test "Entrypoint is /home/claude/.local/bin/claude" \
42+
test_entrypoint
43+
44+
# 4. Claude user exists with UID 1000
45+
test_claude_uid() {
46+
local output
47+
output=$(podman run --rm --entrypoint "" "$IMAGE" id claude 2>&1)
48+
echo "$output" | grep -q "uid=1000"
49+
}
50+
run_test "Claude user has UID 1000" \
51+
test_claude_uid
52+
53+
# 5. Wrapper script starts claude and it responds
54+
test_wrapper() {
55+
local output
56+
output=$(timeout 30 ./bin/claude --local --version 2>&1)
57+
echo "$output" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'
58+
}
59+
run_test "Wrapper script starts claude" \
60+
test_wrapper
61+
62+
# Summary
63+
echo ""
64+
echo "Results: $PASS passed, $FAIL failed"
65+
[ "$FAIL" -eq 0 ]

0 commit comments

Comments
 (0)