Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6caa7fdb3e | ||
|
|
53bcd4aa85 | ||
|
|
cc93936cfd | ||
| 5fb1c1dacc | |||
|
|
3ec00e6e64 | ||
| 177a04266d | |||
|
|
b75776827d | ||
|
|
ab4d5ee617 |
@@ -1 +0,0 @@
|
|||||||
npx lint-staged
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
bun run build
|
|
||||||
120
Dockerfile
120
Dockerfile
@@ -1,73 +1,109 @@
|
|||||||
# ============================================
|
|
||||||
# Stage 1: Install dependencies
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
ARG NODE_VERSION=22-slim
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
FROM node:${NODE_VERSION} AS dependencies
|
# =========================================================
|
||||||
|
# Base
|
||||||
|
# =========================================================
|
||||||
|
FROM node:20-bookworm-slim AS base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install bun to use bun.lock for dependency resolution
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
RUN npm install -g bun
|
ENV HUSKY=0
|
||||||
|
|
||||||
# Copy package-related files to leverage Docker cache
|
|
||||||
COPY package.json bun.lock* ./
|
|
||||||
|
|
||||||
# Install dependencies with frozen lockfile for reproducible builds
|
# =========================================================
|
||||||
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
# Dependencies
|
||||||
bun install --no-save --frozen-lockfile
|
# =========================================================
|
||||||
|
FROM base AS deps
|
||||||
|
|
||||||
# ============================================
|
COPY package.json ./
|
||||||
# Stage 2: Build the Next.js application
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
FROM node:${NODE_VERSION} AS builder
|
RUN npm i --no-audit --no-fund
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --from=dependencies /app/node_modules ./node_modules
|
# =========================================================
|
||||||
COPY . .
|
# Builder
|
||||||
|
# =========================================================
|
||||||
|
FROM base AS builder
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
|
||||||
|
|
||||||
# Build-time env vars — override these with --build-arg or in compose.yml
|
|
||||||
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
|
|
||||||
ARG NEXT_PUBLIC_CLERK_SIGN_IN_URL=/auth/sign-in
|
|
||||||
ARG NEXT_PUBLIC_CLERK_SIGN_UP_URL=/auth/sign-up
|
|
||||||
ARG NEXT_PUBLIC_SENTRY_DISABLED=true
|
|
||||||
|
|
||||||
ENV BUILD_STANDALONE=true
|
ENV BUILD_STANDALONE=true
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
ENV HUSKY=0
|
||||||
|
|
||||||
|
ARG NEXT_PUBLIC_SENTRY_DISABLED=true
|
||||||
|
ENV NEXT_PUBLIC_SENTRY_DISABLED=${NEXT_PUBLIC_SENTRY_DISABLED}
|
||||||
|
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# Stage 3: Production runner
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
FROM node:${NODE_VERSION} AS runner
|
# =========================================================
|
||||||
|
# Migration / Seed image
|
||||||
|
#
|
||||||
|
# ใช้ target นี้สำหรับ:
|
||||||
|
# - npm run migrate
|
||||||
|
# - npm run seed:master-data
|
||||||
|
# - npm run seed:super-admin
|
||||||
|
# =========================================================
|
||||||
|
FROM base AS migrator
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
ENV HUSKY=0
|
||||||
|
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY package.json ./
|
||||||
|
|
||||||
|
# Drizzle configuration
|
||||||
|
COPY drizzle.config.* ./
|
||||||
|
|
||||||
|
# Migration files
|
||||||
|
COPY drizzle ./drizzle
|
||||||
|
|
||||||
|
# Database source code ที่ migration/seed scripts อาจ import
|
||||||
|
COPY src ./src
|
||||||
|
COPY scripts ./scripts
|
||||||
|
|
||||||
|
# ถ้าโปรเจกต์ใช้ tsconfig path alias
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
|
# ถ้ามีไฟล์ config อื่นที่ scripts ใช้งาน ให้เปิดใช้ตามจริง
|
||||||
|
# COPY next.config.* ./
|
||||||
|
# COPY env.* ./
|
||||||
|
|
||||||
|
CMD ["npm", "run", "migrate"]
|
||||||
|
|
||||||
|
|
||||||
|
# =========================================================
|
||||||
|
# Production Runner
|
||||||
|
# =========================================================
|
||||||
|
FROM node:20-bookworm-slim AS runner
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PORT=3000
|
|
||||||
ENV HOSTNAME="0.0.0.0"
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV HOSTNAME=0.0.0.0
|
||||||
|
|
||||||
# Copy public assets
|
RUN groupadd --system --gid 1001 nodejs \
|
||||||
COPY --from=builder --chown=node:node /app/public ./public
|
&& useradd --system --uid 1001 --gid nodejs nextjs
|
||||||
|
|
||||||
# Create .next dir with correct permissions for prerender cache
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
RUN mkdir .next && chown node:node .next
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Copy standalone output and static files
|
# กรณีแอปมี persistent local storage
|
||||||
COPY --from=builder --chown=node:node /app/.next/standalone ./
|
RUN mkdir -p /app/storage \
|
||||||
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
|
&& chown -R nextjs:nodejs /app/storage
|
||||||
|
|
||||||
# Run as non-root user
|
USER nextjs
|
||||||
USER node
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
# ============================================
|
|
||||||
# Stage 1: Install dependencies
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
FROM oven/bun:1 AS dependencies
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package-related files to leverage Docker cache
|
|
||||||
COPY package.json bun.lock* ./
|
|
||||||
|
|
||||||
# Install dependencies with frozen lockfile for reproducible builds
|
|
||||||
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
|
||||||
bun install --no-save --frozen-lockfile
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# Stage 2: Build the Next.js application
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
FROM oven/bun:1 AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --from=dependencies /app/node_modules ./node_modules
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
|
||||||
|
|
||||||
# Build-time env vars — override these with --build-arg or in compose.yml
|
|
||||||
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
|
|
||||||
ARG NEXT_PUBLIC_CLERK_SIGN_IN_URL=/auth/sign-in
|
|
||||||
ARG NEXT_PUBLIC_CLERK_SIGN_UP_URL=/auth/sign-up
|
|
||||||
ARG NEXT_PUBLIC_SENTRY_DISABLED=true
|
|
||||||
|
|
||||||
ENV BUILD_STANDALONE=true
|
|
||||||
|
|
||||||
RUN bun run build
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# Stage 3: Production runner
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
FROM oven/bun:1 AS runner
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
ENV PORT=3000
|
|
||||||
ENV HOSTNAME="0.0.0.0"
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
|
||||||
|
|
||||||
# Copy public assets
|
|
||||||
COPY --from=builder --chown=bun:bun /app/public ./public
|
|
||||||
|
|
||||||
# Create .next dir with correct permissions for prerender cache
|
|
||||||
RUN mkdir .next && chown bun:bun .next
|
|
||||||
|
|
||||||
# Copy standalone output and static files
|
|
||||||
COPY --from=builder --chown=bun:bun /app/.next/standalone ./
|
|
||||||
COPY --from=builder --chown=bun:bun /app/.next/static ./.next/static
|
|
||||||
|
|
||||||
# Run as non-root user
|
|
||||||
USER bun
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
CMD ["bun", "server.js"]
|
|
||||||
BIN
docker-bun-build.log
Normal file
BIN
docker-bun-build.log
Normal file
Binary file not shown.
BIN
docker-node-build.log
Normal file
BIN
docker-node-build.log
Normal file
Binary file not shown.
@@ -1,37 +1,37 @@
|
|||||||
import type { NextConfig } from 'next';
|
import type { NextConfig } from "next";
|
||||||
import { withSentryConfig } from '@sentry/nextjs';
|
import { withSentryConfig } from "@sentry/nextjs";
|
||||||
|
|
||||||
// Define the base Next.js configuration
|
// Define the base Next.js configuration
|
||||||
const baseConfig: NextConfig = {
|
const baseConfig: NextConfig = {
|
||||||
output: process.env.BUILD_STANDALONE === 'true' ? 'standalone' : undefined,
|
output: "standalone",
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
protocol: 'https',
|
protocol: "https",
|
||||||
hostname: 'api.slingacademy.com',
|
hostname: "api.slingacademy.com",
|
||||||
port: ''
|
port: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
protocol: 'https',
|
protocol: "https",
|
||||||
hostname: 'placehold.co',
|
hostname: "placehold.co",
|
||||||
port: ''
|
port: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
protocol: 'https',
|
protocol: "https",
|
||||||
hostname: 'img.clerk.com',
|
hostname: "img.clerk.com",
|
||||||
port: ''
|
port: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
protocol: 'https',
|
protocol: "https",
|
||||||
hostname: 'clerk.com',
|
hostname: "clerk.com",
|
||||||
port: ''
|
port: "",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
transpilePackages: ['geist'],
|
transpilePackages: ["geist"],
|
||||||
compiler: {
|
compiler: {
|
||||||
removeConsole: process.env.NODE_ENV === 'production'
|
removeConsole: process.env.NODE_ENV === "production",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let configWithPlugins = baseConfig;
|
let configWithPlugins = baseConfig;
|
||||||
@@ -48,7 +48,7 @@ if (!process.env.NEXT_PUBLIC_SENTRY_DISABLED) {
|
|||||||
widenClientFileUpload: true,
|
widenClientFileUpload: true,
|
||||||
|
|
||||||
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
|
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
|
||||||
tunnelRoute: '/monitoring',
|
tunnelRoute: "/monitoring",
|
||||||
|
|
||||||
// Disable Sentry telemetry
|
// Disable Sentry telemetry
|
||||||
telemetry: false,
|
telemetry: false,
|
||||||
@@ -56,17 +56,19 @@ if (!process.env.NEXT_PUBLIC_SENTRY_DISABLED) {
|
|||||||
// Sentry v10: moved under webpack namespace
|
// Sentry v10: moved under webpack namespace
|
||||||
webpack: {
|
webpack: {
|
||||||
reactComponentAnnotation: {
|
reactComponentAnnotation: {
|
||||||
enabled: true
|
enabled: true,
|
||||||
},
|
},
|
||||||
treeshake: {
|
treeshake: {
|
||||||
removeDebugLogging: true
|
removeDebugLogging: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Disable source map upload when org/project are not configured
|
// Disable source map upload when org/project are not configured
|
||||||
sourcemaps: {
|
sourcemaps: {
|
||||||
disable: !process.env.NEXT_PUBLIC_SENTRY_ORG || !process.env.NEXT_PUBLIC_SENTRY_PROJECT
|
disable:
|
||||||
}
|
!process.env.NEXT_PUBLIC_SENTRY_ORG ||
|
||||||
|
!process.env.NEXT_PUBLIC_SENTRY_PROJECT,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user