@@ -197,31 +197,22 @@ WORKDIR /home/agent
197197COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
198198COPY --chmod=644 .bashrc /etc/skel/.bashrc
199199
200- # -----------------------------------------------------------------------------
201- # Create and configure /opt/next-template directory with proper permissions
202- # Must be done as root before switching to agent user
203- # -----------------------------------------------------------------------------
204- RUN mkdir -p /opt/next-template \
205- && chown -R agent:agent /opt/next-template
206-
207200# =============================================================================
208201# Stage 2: Next.js project template preparation
209202# =============================================================================
210203
211- # Switch to non-root user for security and proper file ownership
212- USER agent
204+ # Create Next.js template directly in /opt/next-template as root, then chown to agent
205+ # This is simpler and faster than creating in /tmp and moving
206+ # Root can safely run npm commands during image build (not runtime)
213207
214208# -----------------------------------------------------------------------------
215- # Create Next.js project template at /opt/next-template
216- # This template will be copied to /home/agent/next by InitContainer on first run
217- # Reason: /home/agent will be mounted by PVC, so we need to store template elsewhere
209+ # Step 1: Create Next.js project directly in final location
218210# -----------------------------------------------------------------------------
219211RUN set -eux; \
220- # Create template directory (accessible by agent user)
221- mkdir -p /opt/next-template; \
222- cd /opt/next-template; \
223- # Initialize Next.js with all recommended settings
224- # IMPORTANT: --yes flag is required for non-interactive build (skips React Compiler, Turbopack prompts)
212+ TEMPLATE_DIR="/opt/next-template" ; \
213+ mkdir -p "$TEMPLATE_DIR" ; \
214+ cd "$TEMPLATE_DIR" ; \
215+ echo "=== Creating Next.js project in $TEMPLATE_DIR ===" ; \
225216 npx --yes create-next-app@latest . \
226217 --typescript \
227218 --tailwind \
@@ -232,24 +223,43 @@ RUN set -eux; \
232223 --use-pnpm \
233224 --disable-git \
234225 --yes; \
235- # Verify Next.js project was created successfully
236- if [ ! -f /opt/next-template/package.json ]; then \
237- echo "ERROR: Next.js creation failed - package.json not found" ; \
238- ls -la /opt/next-template ; \
226+ echo "=== Verifying Next.js project ===" ; \
227+ ls -la "$TEMPLATE_DIR" ; \
228+ if [ ! -f "$TEMPLATE_DIR/ package.json" ]; then \
229+ echo "ERROR: package.json not found" ; \
239230 exit 1; \
240231 fi; \
241- echo "✓ Next.js project created successfully" ; \
242- # Initialize shadcn/ui with default configuration
232+ echo "✓ Next.js project created successfully"
233+
234+ # -----------------------------------------------------------------------------
235+ # Step 2: Install shadcn/ui components
236+ # -----------------------------------------------------------------------------
237+ RUN set -eux; \
238+ TEMPLATE_DIR="/opt/next-template" ; \
239+ cd "$TEMPLATE_DIR" ; \
240+ echo "=== Initializing shadcn/ui ===" ; \
243241 pnpm dlx shadcn@latest init -d -y; \
244- # Install all available shadcn/ui components
242+ echo "=== Installing shadcn/ui components ===" ; \
245243 pnpm dlx shadcn@latest add --all --yes; \
246- echo "✓ shadcn/ui components installed" ; \
247- # Clean pnpm cache to reduce layer size
244+ echo "✓ shadcn/ui installed"
245+
246+ # -----------------------------------------------------------------------------
247+ # Step 3: Clean up and set ownership
248+ # -----------------------------------------------------------------------------
249+ RUN set -eux; \
250+ TEMPLATE_DIR="/opt/next-template" ; \
251+ cd "$TEMPLATE_DIR" ; \
252+ echo "=== Cleaning up pnpm cache ===" ; \
248253 pnpm store prune; \
249- # Final verification
250- echo "Verifying template contents:" ; \
251- ls -la /opt/next-template; \
252- echo "✓ Next.js template created at /opt/next-template"
254+ echo "=== Setting ownership to agent user (1001:1001) ===" ; \
255+ chown -R agent:agent "$TEMPLATE_DIR" ; \
256+ echo "=== Final verification ===" ; \
257+ ls -la "$TEMPLATE_DIR" ; \
258+ if [ ! -f "$TEMPLATE_DIR/package.json" ]; then \
259+ echo "ERROR: Template verification failed" ; \
260+ exit 1; \
261+ fi; \
262+ echo "✓ Template ready at $TEMPLATE_DIR (owned by agent:agent)"
253263
254264# =============================================================================
255265# Container Runtime Configuration
0 commit comments