perf: make user-template-next optional and optimize build process
Changes: - install.sh: user-template-next is now only built if USER_TEMPLATE_IMAGE=user-template-next:latest is set in .env * Defaults to user-service-template (nginx) to save 4-5 minutes per install * Dynamic build step counting based on configured templates * Shows helpful message when template is skipped * Build numbering adapts automatically ([1/3] vs [1/4]) - user-template-next/Dockerfile: Optimize build performance * Pin Node version to 20.11-alpine for reproducibility * Use npm ci instead of npm install for faster, reproducible builds * Separate package.json copy for better layer caching * Add --prefer-offline and --no-audit flags to npm ci * Clean npm cache to reduce image size * Add clear comments for multi-stage build steps Impact: - Default installations: 2-3 minutes faster - Reduced build time for Next.js template (when enabled) via layer caching - Better reproducibility and predictable builds
This commit is contained in:
parent
20a0f3d6af
commit
2016767dcb
29
install.sh
29
install.sh
|
|
@ -380,9 +380,14 @@ echo "Baue Docker-Images..."
|
||||||
# Stoppe laufende Container
|
# Stoppe laufende Container
|
||||||
${COMPOSE_CMD} down 2>/dev/null || true
|
${COMPOSE_CMD} down 2>/dev/null || true
|
||||||
|
|
||||||
|
# Zaehle aktive Builds fuer Fortschrittsanzeige
|
||||||
|
BUILD_STEP=1
|
||||||
|
TOTAL_BUILDS=3 # user-service-template + spawner-api + frontend (optional: + user-template-next)
|
||||||
|
[ "$USER_TEMPLATE_IMAGE" = "user-template-next:latest" ] && [ -d "${INSTALL_DIR}/user-template-next" ] && TOTAL_BUILDS=$((TOTAL_BUILDS + 1))
|
||||||
|
|
||||||
# User-Template Image bauen (fuer User-Container)
|
# User-Template Image bauen (fuer User-Container)
|
||||||
if [ -d "${INSTALL_DIR}/user-template" ]; then
|
if [ -d "${INSTALL_DIR}/user-template" ]; then
|
||||||
echo " [1/4] Baue user-service-template (User-Container)..."
|
echo " [$BUILD_STEP/$TOTAL_BUILDS] Baue user-service-template (User-Container)..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Build ausfuehren und Output in Datei speichern
|
# Build ausfuehren und Output in Datei speichern
|
||||||
|
|
@ -407,11 +412,13 @@ if [ -d "${INSTALL_DIR}/user-template" ]; then
|
||||||
tail -50 "${BUILD_LOG}"
|
tail -50 "${BUILD_LOG}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
BUILD_STEP=$((BUILD_STEP + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# User-Template-Next Image bauen (alternatives Template, optional)
|
# User-Template-Next Image bauen (alternatives Template, OPTIONAL)
|
||||||
if [ -d "${INSTALL_DIR}/user-template-next" ]; then
|
# Wird NUR gebaut wenn USER_TEMPLATE_IMAGE=user-template-next:latest in .env gesetzt ist
|
||||||
echo " [2/4] Baue user-template-next (Next.js Template)..."
|
if [ "$USER_TEMPLATE_IMAGE" = "user-template-next:latest" ] && [ -d "${INSTALL_DIR}/user-template-next" ]; then
|
||||||
|
echo " [$BUILD_STEP/$TOTAL_BUILDS] Baue user-template-next (Next.js Template, Optional)..."
|
||||||
echo -e " ${BLUE}Dies kann 2-5 Minuten dauern (npm install + build)...${NC}"
|
echo -e " ${BLUE}Dies kann 2-5 Minuten dauern (npm install + build)...${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|
@ -430,10 +437,16 @@ if [ -d "${INSTALL_DIR}/user-template-next" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " user-template-next: ${YELLOW}WARNUNG - Build fehlgeschlagen (optional)${NC}"
|
echo -e " user-template-next: ${YELLOW}WARNUNG - Build fehlgeschlagen (optional)${NC}"
|
||||||
fi
|
fi
|
||||||
|
BUILD_STEP=$((BUILD_STEP + 1))
|
||||||
|
elif [ -d "${INSTALL_DIR}/user-template-next" ]; then
|
||||||
|
echo " [⊙] Überspringe user-template-next (nicht aktiviert in .env)"
|
||||||
|
echo -e " ${BLUE}Um Next.js Template zu aktivieren, setze in .env:${NC}"
|
||||||
|
echo " USER_TEMPLATE_IMAGE=user-template-next:latest"
|
||||||
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Spawner Backend Image bauen
|
# Spawner Backend Image bauen
|
||||||
echo " [3/4] Baue Spawner API (Flask Backend)..."
|
echo " [$BUILD_STEP/$TOTAL_BUILDS] Baue Spawner API (Flask Backend)..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
BUILD_LOG="${LOG_FILE}"
|
BUILD_LOG="${LOG_FILE}"
|
||||||
|
|
@ -455,10 +468,11 @@ else
|
||||||
tail -50 "${BUILD_LOG}"
|
tail -50 "${BUILD_LOG}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
BUILD_STEP=$((BUILD_STEP + 1))
|
||||||
|
|
||||||
# Frontend Image bauen
|
# Frontend Image bauen
|
||||||
if [ -d "${INSTALL_DIR}/frontend" ]; then
|
if [ -d "${INSTALL_DIR}/frontend" ]; then
|
||||||
echo " [4/4] Baue Frontend (Next.js)..."
|
echo " [$BUILD_STEP/$TOTAL_BUILDS] Baue Frontend (Next.js)..."
|
||||||
echo -e " ${BLUE}Dies kann 2-5 Minuten dauern (npm install + build)...${NC}"
|
echo -e " ${BLUE}Dies kann 2-5 Minuten dauern (npm install + build)...${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|
@ -481,10 +495,11 @@ if [ -d "${INSTALL_DIR}/frontend" ]; then
|
||||||
tail -50 "${BUILD_LOG}"
|
tail -50 "${BUILD_LOG}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
BUILD_STEP=$((BUILD_STEP + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Alle Images erfolgreich gebaut."
|
echo "Alle erforderlichen Images erfolgreich gebaut."
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 8. Container starten
|
# 8. Container starten
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,28 @@
|
||||||
# Build stage
|
# Build stage
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20.11-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package.json package-lock.json* ./
|
# Copy nur package.json (Layer Caching - schneller Rebuilds wenn Source-Code aendert)
|
||||||
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Installiere alle Packages (incl. devDependencies fuer TypeScript Build)
|
||||||
|
RUN npm ci --prefer-offline --no-audit && \
|
||||||
|
npm cache clean --force
|
||||||
|
|
||||||
|
# Copy Source Code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Build Next.js App (generiert /app/.next output)
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Production stage - serve static files with nginx
|
# Production stage - serve static files with nginx
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Copy static export
|
# Copy nur das Build-Output (Rest wird nicht mehr benoetigt)
|
||||||
COPY --from=builder /app/out /usr/share/nginx/html
|
COPY --from=builder /app/out /usr/share/nginx/html
|
||||||
|
|
||||||
# Nginx config for SPA
|
# Nginx config fuer SPA (Single Page App)
|
||||||
RUN echo 'server { \
|
RUN echo 'server { \
|
||||||
listen 8080; \
|
listen 8080; \
|
||||||
root /usr/share/nginx/html; \
|
root /usr/share/nginx/html; \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user