fix: change from static execute to dynamic execute #19
@@ -4,7 +4,10 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev-*
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release:
|
||||
|
||||
+34
-18
@@ -1,32 +1,48 @@
|
||||
# --- Giai đoạn 1: Build ---
|
||||
FROM node:25-alpine AS builder
|
||||
# --- Giai đoạn 1: Dependencies ---
|
||||
FROM node:25-alpine AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Cài đặt pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy file định nghĩa package
|
||||
# Copy file định nghĩa package để tận dụng cache của Docker
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Cài đặt dependencies (sử dụng --frozen-lockfile để đảm bảo đúng phiên bản)
|
||||
RUN pnpm install --prod --frozen-lockfile
|
||||
|
||||
# Copy toàn bộ code
|
||||
# --- Giai đoạn 2: Builder ---
|
||||
FROM node:25-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Build Next.js (Yêu cầu next.config.js có output: 'export')
|
||||
# Tắt dữ liệu thu thập của Next.js trong quá trình build
|
||||
ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
RUN npm install -g pnpm
|
||||
RUN pnpm run build
|
||||
|
||||
# --- Giai đoạn 2: Run (Sản phẩm cuối) ---
|
||||
FROM nginx:alpine
|
||||
# --- Giai đoạn 3: Runner (Sản phẩm cuối) ---
|
||||
FROM node:25-alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Xóa file mặc định của nginx (tùy chọn nhưng nên làm)
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
ENV NODE_ENV production
|
||||
ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
# Copy folder out từ giai đoạn builder
|
||||
COPY --from=builder /app/out /usr/share/nginx/html
|
||||
# Tạo user để chạy app (bảo mật hơn chạy root)
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
EXPOSE 80
|
||||
# Copy các file cần thiết từ builder
|
||||
# Standalone chỉ copy code cần chạy, bỏ qua devDependencies và file thừa
|
||||
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
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
ENV PORT 3000
|
||||
|
||||
# Chạy bằng server.js được sinh ra bởi output: 'standalone'
|
||||
CMD ["node", "server.js"]
|
||||
@@ -17,13 +17,18 @@ spec:
|
||||
containers:
|
||||
- name: frontend-container
|
||||
image: git.demonkernel.io.vn/foodsurf/frontend:latest
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
resources:
|
||||
limits:
|
||||
cpu: "50m"
|
||||
memory: "32Mi"
|
||||
cpu: "200m"
|
||||
memory: "256Mi"
|
||||
requests:
|
||||
cpu: "10m"
|
||||
memory: "16Mi"
|
||||
cpu: "50m"
|
||||
memory: "128Mi"
|
||||
env:
|
||||
- name: NODE_ENV
|
||||
value: "production"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
@@ -36,5 +41,5 @@ spec:
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 80
|
||||
targetPort: 3000
|
||||
nodePort: 30080
|
||||
+1
-1
@@ -10,7 +10,7 @@ import type { NextConfig } from "next";
|
||||
* Docs: https://nextjs.org/docs/app/api-reference/next-config-js
|
||||
*/
|
||||
const nextConfig: NextConfig = {
|
||||
output: "export",
|
||||
output: 'standalone',
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
|
||||
+40
-7
@@ -1,4 +1,5 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
|
||||
const version = process.argv[2];
|
||||
if (!version) {
|
||||
@@ -6,14 +7,46 @@ if (!version) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const zipPath = "release.zip";
|
||||
const zipPath = `release-v${version}.zip`; // Thêm version vào tên file cho dễ quản lý
|
||||
|
||||
console.log(`📦 Đang nén file cho version: ${version}...`);
|
||||
console.log(`📦 Đang chuẩn bị đóng gói App Router Standalone cho version: ${version}...`);
|
||||
|
||||
execSync(`cd out && zip -r ../${zipPath} .`, {
|
||||
stdio: "inherit",
|
||||
});
|
||||
// Kiểm tra xem đã build chưa
|
||||
if (!fs.existsSync(".next/standalone")) {
|
||||
console.error("❌ Thư mục .next/standalone không tồn tại. Hãy chạy 'pnpm build' trước!");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`✅ Đã tạo file zip: ${zipPath}`);
|
||||
/**
|
||||
* Với Next.js Standalone, ta cần:
|
||||
* 1. Nội dung trong .next/standalone (copy ra ngoài hoặc nén trực tiếp)
|
||||
* 2. .next/static (phải nằm trong .next/static của gói release)
|
||||
* 3. public (phải nằm trong public của gói release)
|
||||
*/
|
||||
|
||||
execSync("pnpm format");
|
||||
try {
|
||||
// Tạo thư mục tạm để cấu trúc lại file trước khi nén
|
||||
execSync("rm -rf temp_release && mkdir -p temp_release");
|
||||
|
||||
console.log("🚚 Đang sao chép các file standalone...");
|
||||
execSync("cp -r .next/standalone/. temp_release/");
|
||||
|
||||
console.log("🚚 Đang sao chép static và public...");
|
||||
execSync("mkdir -p temp_release/.next/static");
|
||||
execSync("cp -r .next/static/. temp_release/.next/static/");
|
||||
execSync("cp -r public temp_release/ 2>/dev/null || : "); // Bỏ qua nếu không có thư mục public
|
||||
|
||||
console.log("🗜️ Đang nén thành file zip...");
|
||||
// Di chuyển vào temp_release để nén các file bên trong nó
|
||||
execSync(`cd temp_release && zip -r ../${zipPath} .`, { stdio: "inherit" });
|
||||
|
||||
// Xóa thư mục tạm
|
||||
execSync("rm -rf temp_release");
|
||||
|
||||
console.log(`✅ Đã tạo file thành công: ${zipPath}`);
|
||||
|
||||
execSync("pnpm format");
|
||||
} catch (error) {
|
||||
console.error("❌ Có lỗi xảy ra trong quá trình nén:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
+1
-1
@@ -31,5 +31,5 @@
|
||||
".next/dev/types/**/*.ts",
|
||||
"types/**/*.d.ts"
|
||||
],
|
||||
"exclude": ["node_modules", "script", "*.ts"]
|
||||
"exclude": ["node_modules", "scripts", "*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user