From 1d87c4cc915eb99db1c5fc6a2f88bb137cf9a0f9 Mon Sep 17 00:00:00 2001
From: Thanakarn Klangkasame <77600906+Simulationable@users.noreply.github.com>
Date: Tue, 30 Sep 2025 14:24:39 +0700
Subject: [PATCH] Git Init
---
.dockerignore | 48 ++++++++++++++++++++++++++
.gitignore | 64 +++++++++++++++++-----------------
Dockerfile | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++
next-env.d.ts | 6 ++++
4 files changed, 182 insertions(+), 32 deletions(-)
create mode 100644 next-env.d.ts
diff --git a/.dockerignore b/.dockerignore
index e69de29..203f1d2 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -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
diff --git a/.gitignore b/.gitignore
index 5ef6a52..cec66b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Dockerfile b/Dockerfile
index e69de29..835c39f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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"]
diff --git a/next-env.d.ts b/next-env.d.ts
new file mode 100644
index 0000000..830fb59
--- /dev/null
+++ b/next-env.d.ts
@@ -0,0 +1,6 @@
+///
+///
+///
+
+// NOTE: This file should not be edited
+// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.