@@ -11,6 +11,39 @@ RUN apt-get update && apt-get install -y python3 make g++ git curl openssh-serve
1111# This means users can run `npm install` without extra flags and still hit the cache.
1212RUN npm config set cache /npm-cache --global
1313
14+ # Install Claude Code CLI early so this layer is cached independently of crayon changes.
15+ # The _setup user is reused later by `crayon install` to register the plugin.
16+ RUN groupadd -f devs && \
17+ useradd -m -s /bin/bash -g devs _setup && \
18+ su -s /bin/bash _setup -c "curl -fsSL https://claude.ai/install.sh | bash" && \
19+ ln -sf /home/_setup/.local/bin/claude /usr/local/bin/claude
20+
21+ # Pre-install app template node_modules at /node_modules so Node.js finds them
22+ # via standard parent-directory resolution from /data/app (no NODE_PATH needed).
23+ # The template package.json has Handlebars placeholders (e.g. {{crayon_version}})
24+ # that must be resolved before npm install can parse it.
25+ #
26+ # Step 1: Get the template package.json into /tmp/cache-build/.
27+ # For local builds, build-dev.sh copies it into the build context.
28+ # For npm builds, download the tarball and extract just the template.
29+ COPY entrypoint.sh template-package.json* /tmp/
30+ RUN mkdir -p /tmp/cache-build && \
31+ if [ "$CRAYON_SOURCE" = "local" ]; then \
32+ mv /tmp/template-package.json /tmp/cache-build/package.json; \
33+ else \
34+ npm pack runcrayon@dev --pack-destination /tmp && \
35+ tar -xzf /tmp/runcrayon-*.tgz -C /tmp/cache-build --strip-components=3 package/templates/app/package.json && \
36+ rm -f /tmp/runcrayon-*.tgz; \
37+ fi
38+
39+ # Step 2: Install template deps. This layer caches when deps don't change.
40+ RUN cd /tmp/cache-build && \
41+ sed -i 's/{{crayon_version}}/dev/g' package.json && \
42+ sed -i 's/{{app_name}}/cache-app/g' package.json && \
43+ npm install && \
44+ mv node_modules / && \
45+ rm -rf /tmp/cache-build
46+
1447# runcrayon — install from local tarball or npm depending on build arg.
1548# In dev mode, run: npm pack --pack-destination docker/ (from packages/core)
1649# The wildcard COPY uses a dot file as fallback so it never fails when no .tgz exists.
@@ -23,36 +56,19 @@ RUN if [ "$CRAYON_SOURCE" = "local" ] && ls /tmp/build/runcrayon-*.tgz 1>/dev/nu
2356 else \
2457 npm install -g runcrayon@dev; \
2558 fi && \
26- rm -rf /tmp/build
27-
28- # Pre-install app template node_modules at /node_modules so Node.js finds them
29- # via standard parent-directory resolution from /data/app (no NODE_PATH needed).
30- # The template package.json has Handlebars placeholders (e.g. {{crayon_version}})
31- # that must be resolved before npm install can parse it.
32- RUN GLOBAL_MODULES="$(npm root -g)" && \
33- TEMPLATE_DIR="$GLOBAL_MODULES/runcrayon/templates/app" && \
34- mkdir -p /tmp/cache-build && cp "$TEMPLATE_DIR/package.json" /tmp/cache-build/ && \
35- cd /tmp/cache-build && sed -i 's/{{crayon_version}}/dev/g' package.json && \
36- sed -i 's/{{app_name}}/cache-app/g' package.json && \
37- npm install && \
38- mv node_modules / && \
39- rm -rf /tmp/cache-build && \
59+ rm -rf /tmp/build && \
4060 rm -rf /node_modules/runcrayon && \
41- ln -s "$GLOBAL_MODULES /runcrayon" /node_modules/runcrayon
61+ ln -s "$(npm root -g) /runcrayon" /node_modules/runcrayon
4262
4363# /node_modules found by Node.js via parent-directory resolution from /data/app.
4464# /npm-cache is pre-populated during build; world-writable so DEV_USER can use it.
4565RUN chmod -R a+rwx /npm-cache
4666ENV PATH=/node_modules/.bin:$PATH
4767
48- # Pre-run claude install + crayon install as a temp user, then save to /etc/skel.
68+ # Register crayon plugin with the _setup user created earlier , then bake into /etc/skel.
4969# useradd -m copies /etc/skel into new home dirs, so runtime users get Claude Code
5070# + plugin/marketplace registration without the slow setup on every boot.
51- RUN groupadd -f devs && \
52- useradd -m -s /bin/bash -g devs _setup && \
53- su -s /bin/bash _setup -c "curl -fsSL https://claude.ai/install.sh | bash" && \
54- ln -sf /home/_setup/.local/bin/claude /usr/local/bin/claude && \
55- CRAYON="$(npm prefix -g)/bin/crayon" && \
71+ RUN CRAYON="$(npm prefix -g)/bin/crayon" && \
5672 su -s /bin/bash _setup -c "$CRAYON install --force" && \
5773 test -f /home/_setup/.claude/settings.json || { echo "ERROR: crayon plugin not registered"; exit 1; } && \
5874 cp -a /home/_setup/. /etc/skel/ && \
0 commit comments