Skip to content

Commit 601164a

Browse files
committed
fix(core): normalize box image home environment
1 parent bc9bf4c commit 601164a

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

packages/app/src/lib/core/templates/dockerfile.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ const renderDockerfileBun = (config: TemplateConfig): string =>
198198
.filter((chunk) => chunk.trim().length > 0)
199199
.join("\n")
200200

201+
// CHANGE: normalize inherited box image HOME/PATH/WORKDIR after the SSH user rewrite
202+
// WHY: box-js publishes HOME=/home/box; docker exec -u dev inherits image env, so user-relative paths must be re-bound to the mounted /home/dev volume
203+
// QUOTE(ТЗ): "юзать готовый репозиторий"
204+
// REF: issue-267
205+
// SOURCE: n/a
206+
// FORMAT THEOREM: forall u = config.sshUser: HOME(rendered) = /home/u and WORKDIR(rendered) = /home/u
207+
// PURITY: CORE
208+
// INVARIANT: tilde-expanded runtime paths for the SSH user resolve inside the configured home volume
209+
// COMPLEXITY: O(1)/O(1)
201210
const renderDockerfileUsers = (config: TemplateConfig): string =>
202211
`# Create non-root user for SSH (align UID/GID with host user 1000)
203212
RUN for BASE_USER in box ubuntu; do \
@@ -216,6 +225,9 @@ RUN if id -u ${config.sshUser} >/dev/null 2>&1; then \
216225
groupadd -g 1000 ${config.sshUser} || true; \
217226
useradd -m -s /usr/bin/zsh -u 1000 -g 1000 -o ${config.sshUser}; \
218227
fi
228+
ENV HOME=/home/${config.sshUser}
229+
ENV PATH=/usr/local/bun/bin:/home/${config.sshUser}/.deno/bin:/home/${config.sshUser}/.bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
230+
WORKDIR /home/${config.sshUser}
219231
RUN printf "%s\\n" "${config.sshUser} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${config.sshUser} \
220232
&& chmod 0440 /etc/sudoers.d/${config.sshUser}
221233

packages/lib/src/core/templates/dockerfile.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ const renderDockerfileBun = (config: TemplateConfig): string =>
198198
.filter((chunk) => chunk.trim().length > 0)
199199
.join("\n")
200200

201+
// CHANGE: normalize inherited box image HOME/PATH/WORKDIR after the SSH user rewrite
202+
// WHY: box-js publishes HOME=/home/box; docker exec -u dev inherits image env, so user-relative paths must be re-bound to the mounted /home/dev volume
203+
// QUOTE(ТЗ): "юзать готовый репозиторий"
204+
// REF: issue-267
205+
// SOURCE: n/a
206+
// FORMAT THEOREM: forall u = config.sshUser: HOME(rendered) = /home/u and WORKDIR(rendered) = /home/u
207+
// PURITY: CORE
208+
// INVARIANT: tilde-expanded runtime paths for the SSH user resolve inside the configured home volume
209+
// COMPLEXITY: O(1)/O(1)
201210
const renderDockerfileUsers = (config: TemplateConfig): string =>
202211
`# Create non-root user for SSH (align UID/GID with host user 1000)
203212
RUN for BASE_USER in box ubuntu; do \
@@ -216,6 +225,9 @@ RUN if id -u ${config.sshUser} >/dev/null 2>&1; then \
216225
groupadd -g 1000 ${config.sshUser} || true; \
217226
useradd -m -s /usr/bin/zsh -u 1000 -g 1000 -o ${config.sshUser}; \
218227
fi
228+
ENV HOME=/home/${config.sshUser}
229+
ENV PATH=/usr/local/bun/bin:/home/${config.sshUser}/.deno/bin:/home/${config.sshUser}/.bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
230+
WORKDIR /home/${config.sshUser}
219231
RUN printf "%s\\n" "${config.sshUser} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${config.sshUser} \
220232
&& chmod 0440 /etc/sudoers.d/${config.sshUser}
221233

packages/lib/tests/core/templates.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ describe("renderDockerfile", () => {
7575
expect(dockerfile).toContain('usermod -l dev -d /home/dev -m -s /usr/bin/zsh "$BASE_USER" || true')
7676
})
7777

78+
it("normalizes inherited box image HOME and workdir to the configured SSH user", () => {
79+
const dockerfile = renderDockerfile(makeTemplateConfig())
80+
81+
expectContainsAll(dockerfile, [
82+
"ENV HOME=/home/dev",
83+
"ENV PATH=/usr/local/bun/bin:/home/dev/.deno/bin:/home/dev/.bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
84+
"WORKDIR /home/dev"
85+
])
86+
})
87+
7888
it("installs session sync from npmjs with a local fallback", () => {
7989
const dockerfile = renderDockerfile(makeTemplateConfig())
8090

0 commit comments

Comments
 (0)