Skip to content

Commit 70f12fc

Browse files
feat(devcontainer): pre-cache npm and maven dependencies in image
- npm dependencies (root + frontend) now cached in docker image - maven dependencies downloaded during image build - post-create.sh restores from cache for faster startup - reduces new developer setup time significantly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5e09235 commit 70f12fc

2 files changed

Lines changed: 67 additions & 14 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,47 @@ ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
4040
# Install global npm packages
4141
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g npm@latest" 2>&1
4242

43-
# Pre-cache Maven dependencies (optional - speeds up first build)
44-
# Uncomment if you want to pre-download Maven dependencies
45-
# COPY apps/backend/pom.xml /tmp/pom.xml
46-
# RUN cd /tmp && mvn dependency:go-offline -B
43+
# ============================================
44+
# PRE-CACHE DEPENDENCIES FOR FASTER STARTUP
45+
# ============================================
46+
47+
# Create cache directories
48+
RUN mkdir -p /home/vscode/.npm-cache /home/vscode/.m2-cache \
49+
&& chown -R vscode:vscode /home/vscode/.npm-cache /home/vscode/.m2-cache
50+
51+
# --- NPM Dependencies ---
52+
# Copy package files for dependency caching
53+
COPY --chown=vscode:vscode package*.json /tmp/deps/
54+
COPY --chown=vscode:vscode apps/frontend/package*.json /tmp/deps/apps/frontend/
55+
56+
# Install root npm dependencies
57+
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && cd /tmp/deps && npm install" 2>&1
58+
59+
# Install frontend npm dependencies
60+
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && cd /tmp/deps/apps/frontend && npm install --legacy-peer-deps" 2>&1
61+
62+
# --- Maven Dependencies ---
63+
# Copy pom.xml for Maven dependency caching
64+
COPY --chown=vscode:vscode apps/backend/pom.xml /tmp/deps/apps/backend/
65+
COPY --chown=vscode:vscode apps/backend/.mvn /tmp/deps/apps/backend/.mvn/
66+
COPY --chown=vscode:vscode apps/backend/mvnw /tmp/deps/apps/backend/
67+
68+
# Download Maven dependencies
69+
RUN cd /tmp/deps/apps/backend \
70+
&& chmod +x mvnw \
71+
&& ./mvnw dependency:go-offline -B -q || true
72+
73+
# Move cached dependencies to persistent locations
74+
RUN cp -r /tmp/deps/node_modules /home/vscode/.npm-cache/root-node_modules 2>/dev/null || true \
75+
&& cp -r /tmp/deps/apps/frontend/node_modules /home/vscode/.npm-cache/frontend-node_modules 2>/dev/null || true \
76+
&& chown -R vscode:vscode /home/vscode/.npm-cache /home/vscode/.m2
77+
78+
# Cleanup temp files
79+
RUN rm -rf /tmp/deps
80+
81+
# ============================================
82+
# END DEPENDENCY CACHING
83+
# ============================================
4784

4885
# Set working directory
4986
WORKDIR /workspaces/SimpleAccounts-UAE

.devcontainer/post-create.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,40 @@ set -e
55

66
echo "🚀 Setting up SimpleAccounts-UAE development environment..."
77

8-
# Install root dependencies
9-
echo "📦 Installing root npm dependencies..."
10-
npm install
8+
# --- Use cached npm dependencies if available ---
9+
if [ -d "/home/vscode/.npm-cache/root-node_modules" ]; then
10+
echo "📦 Restoring cached root npm dependencies..."
11+
cp -r /home/vscode/.npm-cache/root-node_modules ./node_modules
12+
# Quick install to sync any new packages
13+
npm install --prefer-offline 2>/dev/null || npm install
14+
else
15+
echo "📦 Installing root npm dependencies..."
16+
npm install
17+
fi
1118

12-
# Install frontend dependencies
13-
echo "📦 Installing frontend dependencies..."
14-
cd apps/frontend
15-
npm install --legacy-peer-deps
16-
cd ../..
19+
if [ -d "/home/vscode/.npm-cache/frontend-node_modules" ]; then
20+
echo "📦 Restoring cached frontend npm dependencies..."
21+
cp -r /home/vscode/.npm-cache/frontend-node_modules ./apps/frontend/node_modules
22+
# Quick install to sync any new packages
23+
cd apps/frontend
24+
npm install --legacy-peer-deps --prefer-offline 2>/dev/null || npm install --legacy-peer-deps
25+
cd ../..
26+
else
27+
echo "📦 Installing frontend dependencies..."
28+
cd apps/frontend
29+
npm install --legacy-peer-deps
30+
cd ../..
31+
fi
1732

1833
# Install Playwright browsers (using system Chromium)
1934
echo "🎭 Setting up Playwright..."
2035
cd apps/frontend
2136
npx playwright install-deps 2>/dev/null || true
2237
cd ../..
2338

24-
# Download Maven dependencies (this can take a while on first run)
25-
echo "☕ Downloading Maven dependencies..."
39+
# Maven dependencies are cached in ~/.m2 which is a named volume
40+
# Just ensure any new dependencies are downloaded
41+
echo "☕ Syncing Maven dependencies..."
2642
cd apps/backend
2743
if [ -f "./mvnw" ]; then
2844
chmod +x ./mvnw

0 commit comments

Comments
 (0)