From 4b21254c7d67c1c42df21a0a477ac7f9b8beea89 Mon Sep 17 00:00:00 2001 From: Puechberty Arthur Date: Fri, 12 Jun 2026 01:06:17 +0200 Subject: [PATCH] add runner --- .dockerignore | 6 ++++++ .env.example | 6 ++++++ .github/workflows/deploy.yml | 27 +++++++++++++++++++++++++ .gitignore | 1 + Dockerfile | 30 ++++++++++++++------------- docker-compose.yml | 39 ++++++++++++++---------------------- next.config.ts | 2 ++ package.json | 3 ++- 8 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .github/workflows/deploy.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3c1eda2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +.next +npm-debug.log +Dockerfile +docker-compose.yml +.git \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..99ea6aa --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# Docker / Next.js +NEXT_TELEMETRY_DISABLED=1 +NODE_ENV=production +HOSTNAME=0.0.0.0 +PORT=3000 +APP_PORT=3000 \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..c045ec7 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,27 @@ +name: Deploy Docker + +on: + push: + branches: ["main"] + +jobs: + deploy: + runs-on: self-hosted + + steps: + - name: Deploy on server + run: | + set -e + + echo "Go to app folder" + cd /opt/apps/hub + + echo "Pull latest code" + git pull origin main + + echo "Build & restart containers" + docker compose down || true + docker compose build + docker compose up -d + + echo "Deploy finished" \ No newline at end of file diff --git a/.gitignore b/.gitignore index cdd314c..8feb335 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ yarn-error.log* # env files (can opt-in for committing if needed) .env* +!.env.example # vercel .vercel diff --git a/Dockerfile b/Dockerfile index 124b2b3..79184ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,28 @@ -FROM node:22-alpine AS base -WORKDIR /app -ENV NEXT_TELEMETRY_DISABLED=1 +# ===== BUILD ===== +FROM node:20-alpine AS builder -FROM base AS deps -COPY package.json package-lock.json ./ +WORKDIR /app + +COPY package*.json ./ RUN npm ci -FROM deps AS dev COPY . . -EXPOSE 3000 -CMD ["npm", "run", "dev", "--", "--hostname", "0.0.0.0", "--port", "3000"] -FROM deps AS builder -COPY . . RUN npm run build -FROM base AS runner + +# ===== RUN ===== +FROM node:20-alpine AS runner + +WORKDIR /app + ENV NODE_ENV=production -ENV HOSTNAME=0.0.0.0 -ENV PORT=3000 + +# Standalone output +COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static -COPY --from=builder /app/public ./public + EXPOSE 3000 + CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7495d37..87540f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,22 @@ services: - hub-dev: - profiles: ["dev"] + visio: build: context: . - target: dev - container_name: hub-dev - ports: - - "3000:3000" - volumes: - - .:/app - - /app/node_modules - - /app/.next - environment: - NEXT_TELEMETRY_DISABLED: "1" - NODE_ENV: development + dockerfile: Dockerfile + + container_name: visio - hub-prod: - profiles: ["prod"] - build: - context: . - target: runner - container_name: hub-prod - restart: unless-stopped ports: - - "3004:3000" + - "${APP_PORT}:3000" + env_file: - .env - environment: - NEXT_TELEMETRY_DISABLED: "1" - NODE_ENV: production \ No newline at end of file + + restart: unless-stopped + + 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..f0555b7 100644 --- a/next.config.ts +++ b/next.config.ts @@ -9,6 +9,8 @@ const nextConfig: NextConfig = { // Compression des pages côté serveur (gzip/brotli) compress: true, + + poweredByHeader: false, }; export default nextConfig; diff --git a/package.json b/package.json index 4b637f3..4d0dfb2 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "next start", + "start": "node .next/standalone/server.js", + "docker": "docker compose up --build", "lint": "eslint" }, "dependencies": {