From 25b194ad41ffa4fbec1f4bdd7bfee531867c73de Mon Sep 17 00:00:00 2001 From: ivannoskov Date: Mon, 29 Dec 2025 12:17:47 +0300 Subject: [PATCH] feat: dockerfiles --- .dockerignore | 36 ++++++++++++++++++++++++ Dockerfile | 69 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 14 ++++++++++ next.config.ts | 2 +- 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5ec6cac --- /dev/null +++ b/.dockerignore @@ -0,0 +1,36 @@ +# Dependencies +node_modules +.pnpm-store + +# Build outputs +.next +out +build +dist + +# Development +.git +.gitignore +*.md +README.md +LICENSE + +# IDE +.vscode +.idea +*.swp +*.swo + +# Logs +*.log +npm-debug.log* +pnpm-debug.log* + +# Environment files (will be passed at runtime) +.env*.local + +# Docker +Dockerfile +.dockerignore +docker-compose*.yml + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0893875 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +# ============================================================================ +# Next.js Production Dockerfile +# ============================================================================ + +# Stage 1: Install dependencies +FROM node:20-alpine AS deps +WORKDIR /app + +# Install pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate + +# Copy package files +COPY package.json pnpm-lock.yaml ./ + +# Install dependencies +RUN pnpm install --frozen-lockfile + +# Stage 2: Build the application +FROM node:20-alpine AS builder +WORKDIR /app + +# Install pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate + +# Copy dependencies from deps stage +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Set environment variables for build +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NODE_ENV=production + +# Build the application +RUN pnpm build + +# Stage 3: Production runner +FROM node:20-alpine AS runner +WORKDIR /app + +# Install pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +# Create non-root user for security +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +# Copy necessary files from builder +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static + +# Set correct permissions +RUN chown -R nextjs:nodejs /app + +# Switch to non-root user +USER nextjs + +# Expose port +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +# Start the application +CMD ["node", "server.js"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5f0b29e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.8" + +services: + frontend: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:8000} + - NEXT_PUBLIC_BOT_USERNAME=${NEXT_PUBLIC_BOT_USERNAME:-tgexchage_bot} + restart: unless-stopped + diff --git a/next.config.ts b/next.config.ts index e9ffa30..68a6c64 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", }; export default nextConfig;