Repository navigation
Expand file tree
/
Copy pathContainerfile
More file actions
218 lines (198 loc) · 10.4 KB
/
Copy pathContainerfile
File metadata and controls
218 lines (198 loc) · 10.4 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
# ---- Stage 1: binary downloads with SHA256 verification ----
FROM registry.access.redhat.com/ubi9/ubi:9.9-1795197514 AS builder
ARG TARGETARCH
ARG GH_VERSION=2.104.0
ARG GOLANGCI_LINT_VERSION=2.14.0
ARG STATICCHECK_VERSION=2026.2.2
ARG SHELLCHECK_VERSION=0.10.0
ARG GLAB_VERSION=1.128.0
ARG OPENSHELLCTL_VERSION=0.1.5
RUN set -eux; \
dnf -y install --setopt=install_weak_deps=False --nodocs \
curl-minimal ca-certificates tar gzip xz; \
ARCH="${TARGETARCH:-amd64}"; \
# --- gh (GitHub CLI) ---
curl -fsSLo /tmp/gh.tar.gz \
"https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${ARCH}.tar.gz"; \
tar -C /tmp -xzf /tmp/gh.tar.gz; \
install -m0755 "/tmp/gh_${GH_VERSION}_linux_${ARCH}/bin/gh" /usr/local/bin/gh; \
# --- golangci-lint ---
curl -fsSLo /tmp/golangci-lint.tar.gz \
"https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-${ARCH}.tar.gz"; \
tar -C /tmp -xzf /tmp/golangci-lint.tar.gz; \
install -m0755 "/tmp/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-${ARCH}/golangci-lint" /usr/local/bin/golangci-lint; \
# --- staticcheck ---
curl -fsSLo /tmp/staticcheck.tar.gz \
"https://github.com/dominikh/go-tools/releases/download/${STATICCHECK_VERSION}/staticcheck_linux_${ARCH}.tar.gz"; \
tar -C /tmp -xzf /tmp/staticcheck.tar.gz; \
install -m0755 /tmp/staticcheck/staticcheck /usr/local/bin/staticcheck; \
# --- shellcheck ---
SC_ARCH="${ARCH}"; \
if [ "${SC_ARCH}" = "amd64" ]; then SC_ARCH="x86_64"; fi; \
if [ "${SC_ARCH}" = "arm64" ]; then SC_ARCH="aarch64"; fi; \
curl -fsSLo /tmp/shellcheck.tar.xz \
"https://github.com/koalaman/ShellCheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.${SC_ARCH}.tar.xz"; \
tar -C /tmp -xJf /tmp/shellcheck.tar.xz; \
install -m0755 "/tmp/shellcheck-v${SHELLCHECK_VERSION}/shellcheck" /usr/local/bin/shellcheck; \
# --- glab (GitLab CLI) ---
# No UBI/EPEL rpm exists for glab; install the same way as the other
# GitHub-hosted tools above, from GitLab's own release tarballs.
curl -fsSLo /tmp/glab.tar.gz \
"https://gitlab.com/gitlab-org/cli/-/releases/v${GLAB_VERSION}/downloads/glab_${GLAB_VERSION}_linux_${ARCH}.tar.gz"; \
tar -C /tmp -xzf /tmp/glab.tar.gz; \
install -m0755 /tmp/bin/glab /usr/local/bin/glab; \
# --- openshellctl ---
OCTL_ARCH="${ARCH}"; \
if [ "${OCTL_ARCH}" = "amd64" ]; then OCTL_ARCH="x86_64"; fi; \
curl -fsSLo /tmp/openshellctl.tar.gz \
"https://github.com/openshift-online/openshellctl/releases/download/v${OPENSHELLCTL_VERSION}/openshellctl_Linux_${OCTL_ARCH}.tar.gz"; \
tar --no-same-owner -C /tmp -xzf /tmp/openshellctl.tar.gz openshellctl; \
install -m0755 /tmp/openshellctl /usr/local/bin/openshellctl; \
# --- cleanup ---
rm -rf /tmp/*
# --- Claude Code signed repo ---
RUN set -eux; \
dnf -y install --nodocs 'dnf-command(config-manager)'; \
printf '%s\n' \
'[claude-code]' \
'name=Claude Code' \
'baseurl=https://downloads.claude.ai/claude-code/rpm/stable' \
'enabled=1' \
'gpgcheck=1' \
'gpgkey=https://downloads.claude.ai/keys/claude-code.asc' \
> /etc/yum.repos.d/claude-code.repo
RUN set -eux; \
dnf -y install --nodocs claude-code
# ---- Stage 2: final sandbox image ----
FROM registry.access.redhat.com/ubi9/ubi:9.9-1795197514
LABEL org.opencontainers.image.title="openshell-sandbox-go" \
org.opencontainers.image.description="Go operator development sandbox for OpenShell gateway" \
org.opencontainers.image.base.name="registry.access.redhat.com/ubi9/ubi:9.8"
# --- system packages + Go toolset + Claude Code ---
RUN set -eux; \
dnf -y install --setopt=install_weak_deps=False --nodocs \
git openssh-clients ca-certificates \
go-toolset \
python3 \
jq make gcc findutils which tar gzip diffutils \
curl-minimal rsync procps-ng \
npm skopeo; \
dnf clean all; rm -rf /var/cache/dnf
# --- markdownlint (for documentation review by sub-agents) ---
RUN npm install --global markdownlint-cli2@0.17.2 \
&& npm cache clean --force
# --- binaries from builder stage ---
COPY --from=builder /usr/local/bin/gh /usr/local/bin/gh
COPY --from=builder /usr/local/bin/golangci-lint /usr/local/bin/golangci-lint
COPY --from=builder /usr/local/bin/staticcheck /usr/local/bin/staticcheck
COPY --from=builder /usr/local/bin/shellcheck /usr/local/bin/shellcheck
COPY --from=builder /usr/local/bin/glab /usr/local/bin/glab
COPY --from=builder /usr/local/bin/openshellctl /usr/local/bin/openshellctl
COPY --from=builder /usr/bin/claude /usr/bin/claude
# --- user model (mirrors NVIDIA OpenShell-Community base sandbox) ---
# HOME=/sandbox matches the NVIDIA base image pattern. The workspace-init
# init container seeds /sandbox from the image into the PVC on first use,
# so files baked here (including .claude.json) are available at runtime.
RUN set -eux; \
groupadd -r supervisor; \
useradd -r -g supervisor -s /usr/sbin/nologin supervisor; \
groupadd -r sandbox; \
useradd -r -g sandbox -d /sandbox -s /bin/bash sandbox; \
mkdir -p /sandbox /tmp/sandbox-cache; \
chown -R sandbox:sandbox /sandbox /tmp/sandbox-cache
# --- directory structure ---
RUN set -eux; \
mkdir -p /etc/openshell \
/sandbox/.claude \
/sandbox/.config \
/sandbox/.cache/go-build; \
chown -R sandbox:sandbox /sandbox
# --- agent skills ---
# Copy NVIDIA base image skills (e.g. github/SKILL.md) then add our own.
# Skills are discovered from /sandbox/.agents/skills/ and symlinked into
# /sandbox/.claude/skills/ for Claude Code discovery. The NVIDIA base image
# ships the github skill teaching agents to use gh api REST-only (GraphQL
# is blocked by the sandbox network policy).
COPY --from="ghcr.io/nvidia/openshell-community/sandboxes/base:latest" /sandbox/.agents/skills/ /sandbox/.agents/skills/
COPY sandbox/skills/ /sandbox/.agents/skills/
COPY sandbox/templates/ /sandbox/templates/
RUN set -eux; \
rm -rf /sandbox/.claude/skills; \
ln -sf /sandbox/.agents/skills /sandbox/.claude/skills; \
chown -R sandbox:sandbox /sandbox/.agents/skills
# --- sandbox operating constraints (always-loaded agent instructions) ---
# Read from HOME=/sandbox on every turn. This is the forcing layer: skills are
# advisory (the model may skip them), so these instructions make skill use
# mandatory and prohibit guessing Jira/GitHub auth, hosts, or emails. AGENTS.md
# holds the content (tool-neutral); CLAUDE.md is a thin @AGENTS.md include,
# mirroring the repository root convention so Claude Code auto-discovers it.
COPY sandbox/AGENTS.md /sandbox/AGENTS.md
COPY sandbox/CLAUDE.md /sandbox/CLAUDE.md
RUN chown sandbox:sandbox /sandbox/AGENTS.md /sandbox/CLAUDE.md
# --- neutralize credential-placeholder literals in baked content ---
# Doc files that mention the openshell:resolve:env: prefix by name trip the
# supervisor's request-body marker guard when Claude Code loads them into the
# system prompt. Breaking the prefix with a space defuses the guard without
# affecting readability. Applied at build time so upstream base-image
# refreshes are covered automatically.
RUN grep -rl 'openshell:resolve:env:\|OPENSHELL-RESOLVE-ENV-' /sandbox/.agents/skills /sandbox/AGENTS.md /sandbox/CLAUDE.md 2>/dev/null \
| xargs -r sed -i -e 's/openshell:resolve:env:/openshell:resolve:env :/g' -e 's/OPENSHELL-RESOLVE-ENV-/OPENSHELL-RESOLVE-ENV -/g'
# --- default sandbox policy ---
# Baked at the OpenShell-standard path so it applies automatically when
# --policy is not passed at sandbox create time. Precedence (lowest to highest):
# /etc/openshell/policy.yaml (this file) < OPENSHELL_SANDBOX_POLICY < --policy flag
# Operators override per-sandbox with --policy. OPENSHELL_SANDBOX_POLICY is read
# by the CLI at sandbox-create time (openshell-cli/src/run.rs), not by the gateway.
COPY policies/default.yaml /etc/openshell/policy.yaml
# --- pre-seed Claude Code trust state ---
# Baked into /sandbox/.claude.json — the workspace-init init container seeds
# /sandbox from the image into the PVC on first use. Claude Code reads
# ~/.claude.json (HOME=/sandbox) so this path is correct. On first sandbox
# creation with a given name the PVC gets seeded from the image including this
# file. On subsequent runs the PVC already contains it.
#
# Pre-approves everything that would otherwise block a non-interactive
# `--dangerously-skip-permissions --print` run:
# - bypassPermissionsModeAccepted: enables --dangerously-skip-permissions
# - projects./sandbox trust + hooks: accepts the workspace trust dialogs
RUN printf '%s\n' \
'{' \
' "hasCompletedOnboarding": true,' \
' "bypassPermissionsModeAccepted": true,' \
' "theme": "dark",' \
' "projects": {' \
' "/sandbox": {' \
' "hasTrustDialogAccepted": true,' \
' "hasTrustDialogHooksAccepted": true' \
' }' \
' }' \
'}' > /sandbox/.claude.json \
&& chown sandbox:sandbox /sandbox/.claude.json
# --- environment ---
# GOPATH/GOMODCACHE are left at Go's defaults ($HOME/go, $HOME/go/pkg/mod):
# /sandbox is the sandbox user's, PVC-backed home, so the module cache lives
# next to GOCACHE and persists across runs without a root-owned /go.
# GOTOOLCHAIN=auto downloads a newer toolchain when go.mod requires one.
# GODEBUG=gotoolchainexec=0 prevents go from exec-replacing itself with the
# downloaded toolchain (keeps /usr/bin/go as the process ancestor for the
# go-modules provider's binary-ancestry rule; see provider-profiles/go-modules.yaml).
ENV PATH="/sandbox/go/bin:/sandbox/.local/bin:/usr/local/bin:/usr/bin:/bin" \
GOCACHE=/sandbox/.cache/go-build \
GOTOOLCHAIN=auto \
GODEBUG=gotoolchainexec=0 \
XDG_CACHE_HOME=/tmp/sandbox-cache \
HOME=/sandbox \
DISABLE_AUTOUPDATER=1 \
DISABLE_UPDATES=1
# --- Vertex AI credential + config via Claude Code settings ---
# The supervisor injects GOOGLE_VERTEX_AI_SERVICE_ACCOUNT_TOKEN via the
# attached google-vertex-ai provider. Claude Code's apiKeyHelper reads
# that sentinel at runtime (not bake time); the env block sets the static
# Vertex config. This avoids a wrapper binary on PATH.
COPY sandbox/settings.json /sandbox/.claude/settings.json
RUN chown sandbox:sandbox /sandbox/.claude/settings.json
# --- agent runtime defaults ---
ENV JIRA_EMAIL="sd-sre-platform+rosa-agent@redhat.com" \
JIRA_BASE_URL="https://redhat.atlassian.net"
USER sandbox
WORKDIR /sandbox