This commit is contained in:
Thanakarn Klangkasame
2025-09-30 14:24:39 +07:00
parent 30f57dd5c2
commit 1d87c4cc91
4 changed files with 182 additions and 32 deletions

View File

@@ -0,0 +1,48 @@
# VCS / meta
.git
.github
.gitignore
LICENSE
README.md
*.md
# Node / Next artifacts (ไม่ต้องใส่ลง build context)
node_modules
.npm
.pnpm-store
.cache
.next
.next/cache
out
dist
coverage
.vercel
.turbo
.eslintcache
.sass-cache
# IDE / OS
.vscode
.idea
.DS_Store
*.swp
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Env (กันความลับรั่วเข้า image; ให้ผ่านเป็น ARG/ENV ตอน build/run แทน)
.env
.env.*
.env.local
.env.development.local
.env.test.local
.env.production.local
# Misc
Dockerfile
docker-compose*.yml

64
.gitignore vendored
View File

@@ -1,41 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# Dependencies
node_modules/
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# Build outputs
.next/
.next/cache/
out/
dist/
coverage/
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# Caches
.npm/
.pnpm-store/
.cache/
.turbo/
.vercel/
.eslintcache
# vercel
.vercel
# Env files (เก็บแยก .env.example ไว้ commit ได้)
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# typescript
# Editors / OS
.vscode/
.idea/
.DS_Store
*.swp
# TypeScript
*.tsbuildinfo
next-env.d.ts

View File

@@ -0,0 +1,96 @@
# syntax=docker/dockerfile:1
############################
# Base
############################
FROM node:20-alpine AS base
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# สำหรับ next/image (sharp) และไลบรารีบางตัวบน Alpine
RUN apk add --no-cache libc6-compat
############################
# Dependencies (dev)
# - ติดตั้ง deps ตาม lockfile เพื่อใช้ตอน build
############################
FROM base AS deps
# เปิดใช้ corepack เพื่อรองรับ yarn/pnpm โดยไม่ต้อง npm i -g
RUN corepack enable
COPY package.json ./
# รองรับทุกแพ็กเกจแมเนเจอร์โดยดูจาก lockfile
COPY pnpm-lock.yaml* ./
COPY yarn.lock* ./
COPY package-lock.json* ./
# ติดตั้ง dependencies (รวม dev deps สำหรับขั้น build)
RUN set -eux; \
if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile; \
elif [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
else npm install; \
fi
############################
# Build
############################
FROM base AS builder
RUN corepack enable
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# ถ้ามี .env.production.local ที่ต้องใช้ตอน build ให้ COPY เพิ่มเองตามต้องการ
# สร้างโปรดักชันบิลด์
RUN set -eux; \
if [ -f pnpm-lock.yaml ]; then pnpm run build; \
elif [ -f yarn.lock ]; then yarn build; \
else npm run build; \
fi
############################
# Dependencies (prod only)
# - ติดตั้งเฉพาะ production deps เพื่อลดขนาดอิมเมจสุดท้าย
############################
FROM base AS prod-deps
RUN corepack enable
COPY package.json ./
COPY pnpm-lock.yaml* ./
COPY yarn.lock* ./
COPY package-lock.json* ./
RUN set -eux; \
if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile --prod --no-optional; \
elif [ -f yarn.lock ]; then \
# yarn modern: โฟกัสโปรดักชัน ถ้าใช้ v1 จะ fallback เป็น install --production
(yarn workspaces focus --all --production || yarn install --frozen-lockfile --production=true); \
elif [ -f package-lock.json ]; then npm ci --omit=dev; \
else npm install --omit=dev; \
fi
############################
# Runner
############################
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
ENV NEXT_TELEMETRY_DISABLED=1
# เพิ่มผู้ใช้แบบ non-root เพื่อความปลอดภัย
RUN apk add --no-cache libc6-compat && \
addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001 -G nodejs
# คัดลอกไฟล์ที่จำเป็นต่อการรัน
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
# ไม่จำเป็นเสมอไป แต่บางโปรเจ็กต์อ้างอิง config ตอน runtime
COPY --from=builder /app/next.config.js ./next.config.js
COPY --from=builder /app/package.json ./package.json
# ใช้เฉพาะ production node_modules ที่ prune แล้ว
COPY --from=prod-deps /app/node_modules ./node_modules
USER nextjs
EXPOSE 3000
# ใช้สคริปต์ "start" (ควรเป็น "next start")
CMD ["npm", "run", "start"]

6
next-env.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.