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/Dockerfile b/Dockerfile new file mode 100644 index 0000000..79184ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# ===== BUILD ===== +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . + +RUN npm run build + + +# ===== RUN ===== +FROM node:20-alpine AS runner + +WORKDIR /app + +ENV NODE_ENV=production + +# Standalone output +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static + +EXPOSE 3000 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5a67c7f..87540f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,22 @@ services: visio: - image: node:20-alpine - container_name: visio-app - working_dir: /app - volumes: - - ./:/app - - /app/node_modules + build: + context: . + dockerfile: Dockerfile + + container_name: visio + ports: - - "3010:3000" - environment: - - PORT=3000 - command: sh -c "npm install && npm run build && npm start" + - "${APP_PORT}:3000" + + env_file: + - .env + restart: unless-stopped + healthcheck: - test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000"] + test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/"] interval: 30s timeout: 10s retries: 3 - start_period: 40s + start_period: 20s \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index e9ffa30..3950ecc 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,9 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", + compress: true, + poweredByHeader: false, }; export default nextConfig; diff --git a/package.json b/package.json index 3612463..887309d 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "node server.js", + "dev": "next dev", "build": "next build", - "start": "NODE_ENV=production node server.js", + "start": "node .next/standalone/server.js", + "docker": "docker compose up --build", "lint": "eslint" }, "dependencies": {