diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8266df8..05ecc18 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,45 +1,27 @@ -name: Deploy Production +name: Deploy Docker on: push: - branches: [main] - -concurrency: - group: production-deploy - cancel-in-progress: true + branches: ["main"] jobs: deploy: runs-on: self-hosted steps: - - name: Deploy portfolio Production - shell: bash + - name: Deploy on server run: | - set -euo pipefail + set -e - echo "============================" - echo " Starting deployment" - echo "============================" + echo "Go to app folder" + cd /opt/apps/portfolio - APP_DIR="/srv/apps/portfolio" + echo "Pull latest code" + git pull origin main - cd "$APP_DIR" + echo "Build & restart containers" + docker compose down || true + docker compose build + docker compose up -d - echo "Fetching latest code..." - git fetch origin main - - echo "Resetting local state..." - git reset --hard origin/main - - echo "Cleaning untracked files (keeping .env)" - git clean -fd -e .env - - echo "Pulling/building containers..." - docker compose pull || true - docker compose up -d --build --remove-orphans - - echo "Cleaning unused Docker images..." - docker image prune -f - - echo "Deployment finished successfully" + echo "Deploy finished" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 34cb63c..79184ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,44 +1,28 @@ -# ====== 1. Dependencies ====== -FROM node:20-alpine AS deps - -WORKDIR /app - -COPY package.json package-lock.json* ./ -RUN npm ci - - -# ====== 2. Build ====== +# ===== BUILD ===== FROM node:20-alpine AS builder WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . +COPY package*.json ./ +RUN npm ci -# Variables build-time -ENV NEXT_TELEMETRY_DISABLED=1 +COPY . . RUN npm run build -# ====== 3. Runner (prod minimal) ====== +# ===== RUN ===== FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production -ENV NEXT_TELEMETRY_DISABLED=1 -# user non-root (bonne pratique) -RUN addgroup -S nextjs && adduser -S nextjs -G nextjs - -# Copy standalone output +# Standalone output COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static -USER nextjs - EXPOSE 3000 CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9327066..dd7cdc6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,22 @@ services: - next-app: + visio: build: context: . dockerfile: Dockerfile - container_name: portfolio-app + container_name: portfolio ports: - - "${WEB_PORT}:3000" + - "${APP_PORT}:3000" env_file: - .env restart: unless-stopped - environment: - - PORT=3000 - - NODE_ENV=production - - HOSTNAME=0.0.0.0 \ No newline at end of file + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 20s \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 6007e2e..3950ecc 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,14 +1,9 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - // Mode production strict pour React (détecte les erreurs tôt) - reactStrictMode: true, - - // Build standalone pour Docker → image finale légère et indépendante output: "standalone", - - // Compression des pages côté serveur (gzip/brotli) compress: true, + poweredByHeader: false, }; export default nextConfig; diff --git a/package.json b/package.json index bf4df6b..b467f85 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "next start", + "start": "node .next/standalone/server.js", + "docker": "docker compose up --build", "lint": "eslint .", "lint:fix": "eslint . --fix" },