Browse Source

build: add production Dockerfile, docker-compose, .env.prod, and standalone next config

master
Ali Alavi 2 weeks ago
parent
commit
bcd360dc33
  1. 11
      .dockerignore
  2. 3
      .env.prod
  3. 1
      .gitignore
  4. 54
      Dockerfile
  5. 18
      docker-compose.yml
  6. 2
      next.config.ts
  7. 3
      runner.sh

11
.dockerignore

@ -0,0 +1,11 @@
Dockerfile
docker-compose.yml
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
.gitignore
.env*.local
.env.development

3
.env.prod

@ -0,0 +1,3 @@
PORT=3000
NODE_ENV=production
NEXT_TELEMETRY_DISABLED=1

1
.gitignore

@ -32,6 +32,7 @@ yarn-error.log*
# env files (can opt-in for committing if needed) # env files (can opt-in for committing if needed)
.env* .env*
!.env.prod
# vercel # vercel
.vercel .vercel

54
Dockerfile

@ -0,0 +1,54 @@
# syntax=docker/dockerfile:1.7
# ──────────────────────────────────────────────────────────────────────────
# مرحلهٔ ۱ — deps: آماده‌سازی وابستگی‌ها با کش npm
# ──────────────────────────────────────────────────────────────────────────
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN --mount=type=cache,target=/root/.npm npm ci --prefer-offline --no-audit --fund=false
# ──────────────────────────────────────────────────────────────────────────
# مرحلهٔ ۲ — builder: ساخت خروجی بهینه‌شده standalone برای Next.js
# ──────────────────────────────────────────────────────────────────────────
FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
RUN npm run build
# ──────────────────────────────────────────────────────────────────────────
# مرحلهٔ ۳ — runner: سرور مینیمال، سبک و امن standalone در محیط پروداکشن
# ──────────────────────────────────────────────────────────────────────────
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# ایجاد کاربر غیر روت برای امنیت کانتینر
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
# هلث‌چک کانتینر
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD wget -qO- http://127.0.0.1:3000/ || exit 1
CMD ["node", "server.js"]

18
docker-compose.yml

@ -0,0 +1,18 @@
services:
web:
build:
context: .
dockerfile: Dockerfile
image: teamby-landing:latest
container_name: teamby_landing
restart: unless-stopped
env_file:
- .env.prod
ports:
- "8065:3000"
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/ || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 15s

2
next.config.ts

@ -1,7 +1,7 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */
output: "standalone",
}; };
export default nextConfig; export default nextConfig;

3
runner.sh

@ -0,0 +1,3 @@
#!/bin/bash
set -e
git pull origin master --rebase && docker compose up -d --build
Loading…
Cancel
Save