11#! /bin/sh
2+ set -eu
23
3- CONTAINER=$( buildah from docker.io/alpine:latest)
4- IMAGE=claude-code
5- REPO_NAME=" EvanCarroll/claude-podman"
4+ # opencode release pin. To upgrade: bump the version, then update both
5+ # checksums from the new release assets (compute with sha256sum after
6+ # downloading from https://github.com/anomalyco/opencode/releases).
7+ OPENCODE_VERSION=" 1.18.13"
8+ OPENCODE_SHA256_X86_64=" 93f1506f26ad8b6e867754d144bea43e6c707ec518bac227fdf959048d020d74"
9+ OPENCODE_SHA256_AARCH64=" a5b90d6111d2d826fe14952c769d0d4bcf00db7810c0c92d9f4541d3768f03ef"
10+
11+ IMAGE=opencode
12+ REPO_NAME=" ingby/opencode-podman"
613
714# Process arguments
815while [ " $# " -gt 0 ]; do
@@ -11,7 +18,7 @@ while [ "$#" -gt 0 ]; do
1118 cat << -'EOT '
1219 Usage: $0 [OPTIONS]
1320
14- Build image to run Claude Code in a Podman container
21+ Build image to run opencode in a Podman container
1522
1623 Options:
1724 --repo-name REPO_NAME Use the specified repo name instead of the default "REPO_NAME"
@@ -29,30 +36,70 @@ while [ "$#" -gt 0 ]; do
2936 esac
3037done
3138
39+ case " $( uname -m) " in
40+ x86_64)
41+ OPENCODE_ASSET=" opencode-linux-x64-musl.tar.gz"
42+ OPENCODE_SHA256=" $OPENCODE_SHA256_X86_64 "
43+ ;;
44+ aarch64 | arm64)
45+ OPENCODE_ASSET=" opencode-linux-arm64-musl.tar.gz"
46+ OPENCODE_SHA256=" $OPENCODE_SHA256_AARCH64 "
47+ ;;
48+ * )
49+ echo " Unsupported architecture: $( uname -m) " >&2
50+ exit 1
51+ ;;
52+ esac
53+
54+ CONTAINER=$( buildah from docker.io/alpine:latest)
55+
3256# Install dependencies and create user
3357buildah run " $CONTAINER " sh << EOT
34- apk add --no-cache bash curl libgcc libstdc++ ripgrep
35- adduser -D claude
58+ set -eu
59+ apk add --no-cache bash curl git libgcc libstdc++ ripgrep
60+ adduser -D opencode
3661EOT
3762
38- # Install Claude Code using native installer as the claude user
39- buildah run --user claude " $CONTAINER " bash -c ' curl -fsSL https://claude.ai/install.sh | bash'
63+ # Install opencode from a pinned GitHub release tarball, verifying its
64+ # sha256 against the checksum committed in this repo. The binary is
65+ # installed root-owned outside the user's home so opencode cannot
66+ # replace itself even if an update were attempted.
67+ buildah run " $CONTAINER " sh << EOT
68+ set -eu
69+ cd /tmp
70+ curl --proto '=https' --tlsv1.2 -fsSLo "$OPENCODE_ASSET " \
71+ "https://github.com/anomalyco/opencode/releases/download/v${OPENCODE_VERSION} /${OPENCODE_ASSET} "
72+ echo "$OPENCODE_SHA256 $OPENCODE_ASSET " | sha256sum -c -
73+ tar -xzf "$OPENCODE_ASSET " -C /usr/local/bin opencode
74+ chown root:root /usr/local/bin/opencode
75+ chmod 755 /usr/local/bin/opencode
76+ rm -f "$OPENCODE_ASSET "
77+ EOT
4078
41- # Get the installed version
42- CLAUDE_VERSION=$( buildah run --user claude " $CONTAINER " /home/claude/.local/bin/claude --version 2> /dev/null | head -1 | awk ' {print $1}' )
79+ # Bake a default config that disables autoupdate. If the config dir is
80+ # bind-mounted at runtime this file is shadowed, so the
81+ # OPENCODE_DISABLE_AUTOUPDATE env var below is the authoritative switch.
82+ buildah run --user opencode " $CONTAINER " sh << 'EOT '
83+ set -eu
84+ mkdir -p /home/opencode/.config/opencode
85+ cat > /home/opencode/.config/opencode/opencode.json <<'JSON'
86+ {
87+ "$schema": "https://opencode.ai/config.json",
88+ "autoupdate": false
89+ }
90+ JSON
91+ EOT
4392
4493buildah config \
45- --author " Evan Carroll " \
46- --env " PATH=/home/claude/.local/bin:/ usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
94+ --author " Christer Barreholm " \
95+ --env " PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
4796 --env " SHELL=/bin/bash" \
48- --env " DISABLE_TELEMETRY=1" \
49- --env " DISABLE_AUTOUPDATER=1" \
50- --env " USE_BUILTIN_RIPGREP=0" \
97+ --env " OPENCODE_DISABLE_AUTOUPDATE=true" \
5198 --cmd " " \
52- --entrypoint ' [ "/home/claude/. local/bin/claude " ]' \
53- --annotation " org.anthropic.claudecode. version=$CLAUDE_VERSION " \
54- --annotation " org.opencontainers.image.title=claude-code " \
55- --annotation " org.opencontainers.image.description=Claude Code on Alpine ready for rootless podman" \
99+ --entrypoint ' [ "/usr/ local/bin/opencode " ]' \
100+ --annotation " ai.opencode. version=$OPENCODE_VERSION " \
101+ --annotation " org.opencontainers.image.title=opencode " \
102+ --annotation " org.opencontainers.image.description=opencode on Alpine ready for rootless podman" \
56103 --annotation " org.opencontainers.image.url=https://github.com/$REPO_NAME " \
57104 --annotation " org.opencontainers.image.source=https://github.com/$REPO_NAME " \
58105 --annotation " org.opencontainers.image.documentation=https://github.com/$REPO_NAME /blob/main/README.md" \
@@ -64,8 +111,8 @@ buildah commit \
64111 --rm \
65112 " $CONTAINER " " $IMAGE "
66113
67- buildah tag " $IMAGE " " $IMAGE :$CLAUDE_VERSION "
114+ buildah tag " $IMAGE " " $IMAGE :$OPENCODE_VERSION "
68115
69116echo Done!
70- echo ${IMAGE} :${CLAUDE_VERSION }
71- echo To use this image run /bin/claude
117+ echo ${IMAGE} :${OPENCODE_VERSION }
118+ echo To use this image run /bin/opencode
0 commit comments