Skip to content

Commit 1bc3e2d

Browse files
authored
Fix the next template build (#50)
1 parent 2be484b commit 1bc3e2d

3 files changed

Lines changed: 60 additions & 42 deletions

File tree

lib/k8s/sandbox-manager.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ export class SandboxManager {
598598
memory: '512Mi',
599599
},
600600
limits: {
601-
cpu: '1000m',
602-
memory: '1024Mi',
601+
cpu: '2000m',
602+
memory: '4096Mi',
603603
},
604604
},
605605
},
@@ -738,29 +738,37 @@ fi
738738
739739
# Copy Next.js project template
740740
echo "→ Copying Next.js project template from /opt/next-template..."
741-
echo " Source: /opt/next-template"
741+
echo " Source: /opt/next-template (agent:agent)"
742742
echo " Target: /home/agent/next"
743-
echo " This may take 30-60 seconds (copying ~200-300MB)..."
743+
echo " This may take 10-30 seconds..."
744744
mkdir -p /home/agent/next
745-
cp -r /opt/next-template/. /home/agent/next
746745
747-
# Verify copy was successful
748-
if [ ! -d /home/agent/next ]; then
749-
echo "✗ ERROR: Project copy failed - target directory not created"
746+
# Copy with progress indicator and preserve timestamps
747+
# Using cp instead of rsync for simplicity (rsync is available but cp is sufficient)
748+
cp -rp /opt/next-template/. /home/agent/next 2>&1 || {
749+
echo "✗ ERROR: Failed to copy template"
750750
exit 1
751-
fi
751+
}
752752
753+
# Verify copy was successful
753754
if [ ! -f /home/agent/next/package.json ]; then
754755
echo "✗ ERROR: Project copy incomplete - package.json not found"
756+
ls -la /home/agent/next 2>&1 || true
755757
exit 1
756758
fi
757759
758760
echo "✓ Next.js project template copied successfully"
759761
760762
# Set ownership and permissions for copied files
763+
# Note: Even though source files are agent:agent in the image,
764+
# cp creates new files owned by the current user (root in init container)
761765
echo "→ Setting ownership (agent:1001) and permissions..."
762-
chown -R 1001:1001 /home/agent/next
763-
chmod -R u+rwX,g+rX,o+rX /home/agent/next
766+
chown -R 1001:1001 /home/agent/next 2>&1 || {
767+
echo "⚠ Warning: Failed to set ownership, but continuing..."
768+
}
769+
chmod -R u+rwX,g+rX,o+rX /home/agent/next 2>&1 || {
770+
echo "⚠ Warning: Failed to set permissions, but continuing..."
771+
}
764772
765773
# Count files for verification
766774
FILE_COUNT=$(find /home/agent/next -type f | wc -l)

lib/k8s/versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const VERSIONS = {
3939
// Storage configuration
4040
STORAGE: {
4141
DATABASE_SIZE: '3Gi',
42-
SANDBOX_SIZE: '5Gi',
42+
SANDBOX_SIZE: '10Gi',
4343
STORAGE_CLASS: 'openebs-backup',
4444
},
4545
} as const

sandbox/Dockerfile

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -197,31 +197,22 @@ WORKDIR /home/agent
197197
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
198198
COPY --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
# -----------------------------------------------------------------------------
219211
RUN 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

Comments
 (0)