diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..193b26c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# === Étape 1 : Build === +FROM node:20-alpine AS builder + +WORKDIR /app + +# Copier les fichiers de dépendances pour profiter du cache Docker +COPY package*.json ./ + +# Installer uniquement ce qu'il faut pour le build +RUN npm ci + +# Copier tout le code +COPY . . + +# Build Next.js pour la production +RUN npm run build + +# === Étape 2 : Runner léger === +FROM node:20-alpine AS runner + +WORKDIR /app + +# Copier uniquement ce qui est nécessaire pour la prod +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public + +# Mode production +ENV NODE_ENV=production +EXPOSE 3000 + +# Lancer le serveur Next.js +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2f10945..a47d63b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,39 +1,11 @@ services: - qrcode: - image: node:22-alpine - container_name: qrcode-generator - working_dir: /app + web: + build: . ports: - - "3001:3000" - environment: - - NODE_ENV=production - - HOSTNAME=0.0.0.0 - - PORT=3000 + - "3000:3000" volumes: - - .:/app - - node_modules:/app/node_modules - - nextjs_cache:/app/.next/cache - command: > - sh -c " - if [ ! -d .next/standalone ]; then - echo '📦 Installing dependencies...' && - npm ci && - echo '🔨 Building application...' && - NODE_OPTIONS='--max-old-space-size=1536' npm run build; - fi && - echo '🚀 Starting QR Code Generator...' && - cp -r .next/static .next/standalone/.next/static 2>/dev/null || true && - cp -r public .next/standalone/public 2>/dev/null || true && - node .next/standalone/server.js - " - restart: unless-stopped - healthcheck: - test: ["CMD-SHELL", "wget -q --spider http://localhost:3000 || exit 1"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 120s - -volumes: - node_modules: - nextjs_cache: + - ./:/app + - /app/node_modules + environment: + - NODE_ENV=development + command: npm run dev \ No newline at end of file