fix: change from static execute to dynamic execute (#19)
Release package / release (push) Failing after 24m2s
Release package / release (push) Failing after 24m2s
Reviewed-on: #19
This commit was merged in pull request #19.
This commit is contained in:
@@ -4,7 +4,10 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- dev-*
|
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
|
|||||||
+34
-18
@@ -1,32 +1,48 @@
|
|||||||
# --- Giai đoạn 1: Build ---
|
# --- Giai đoạn 1: Dependencies ---
|
||||||
FROM node:25-alpine AS builder
|
FROM node:25-alpine AS deps
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# Cài đặt pnpm
|
# Cài đặt pnpm
|
||||||
RUN npm install -g pnpm
|
RUN npm install -g pnpm
|
||||||
|
|
||||||
WORKDIR /app
|
# Copy file định nghĩa package để tận dụng cache của Docker
|
||||||
|
|
||||||
# Copy file định nghĩa package
|
|
||||||
COPY package.json pnpm-lock.yaml ./
|
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)
|
# --- Giai đoạn 2: Builder ---
|
||||||
RUN pnpm install --prod --frozen-lockfile
|
FROM node:25-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
# Copy toàn bộ code
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
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
|
RUN pnpm run build
|
||||||
|
|
||||||
# --- Giai đoạn 2: Run (Sản phẩm cuối) ---
|
# --- Giai đoạn 3: Runner (Sản phẩm cuối) ---
|
||||||
FROM nginx:alpine
|
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)
|
ENV NODE_ENV production
|
||||||
RUN rm -rf /usr/share/nginx/html/*
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
# Copy folder out từ giai đoạn builder
|
# Tạo user để chạy app (bảo mật hơn chạy root)
|
||||||
COPY --from=builder /app/out /usr/share/nginx/html
|
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:
|
containers:
|
||||||
- name: frontend-container
|
- name: frontend-container
|
||||||
image: git.demonkernel.io.vn/foodsurf/frontend:latest
|
image: git.demonkernel.io.vn/foodsurf/frontend:latest
|
||||||
|
ports:
|
||||||
|
- containerPort: 3000
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: "50m"
|
cpu: "200m"
|
||||||
memory: "32Mi"
|
memory: "256Mi"
|
||||||
requests:
|
requests:
|
||||||
cpu: "10m"
|
cpu: "50m"
|
||||||
memory: "16Mi"
|
memory: "128Mi"
|
||||||
|
env:
|
||||||
|
- name: NODE_ENV
|
||||||
|
value: "production"
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
@@ -36,5 +41,5 @@ spec:
|
|||||||
ports:
|
ports:
|
||||||
- protocol: TCP
|
- protocol: TCP
|
||||||
port: 80
|
port: 80
|
||||||
targetPort: 80
|
targetPort: 3000
|
||||||
nodePort: 30080
|
nodePort: 30080
|
||||||
+1
-1
@@ -10,7 +10,7 @@ import type { NextConfig } from "next";
|
|||||||
* Docs: https://nextjs.org/docs/app/api-reference/next-config-js
|
* Docs: https://nextjs.org/docs/app/api-reference/next-config-js
|
||||||
*/
|
*/
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
output: "export",
|
output: 'standalone',
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
|
|||||||
+39
-6
@@ -1,4 +1,5 @@
|
|||||||
import { execSync } from "node:child_process";
|
import { execSync } from "node:child_process";
|
||||||
|
import fs from "node:fs";
|
||||||
|
|
||||||
const version = process.argv[2];
|
const version = process.argv[2];
|
||||||
if (!version) {
|
if (!version) {
|
||||||
@@ -6,14 +7,46 @@ if (!version) {
|
|||||||
process.exit(1);
|
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} .`, {
|
// Kiểm tra xem đã build chưa
|
||||||
stdio: "inherit",
|
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)
|
||||||
|
*/
|
||||||
|
|
||||||
|
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");
|
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",
|
".next/dev/types/**/*.ts",
|
||||||
"types/**/*.d.ts"
|
"types/**/*.d.ts"
|
||||||
],
|
],
|
||||||
"exclude": ["node_modules", "script", "*.ts"]
|
"exclude": ["node_modules", "scripts", "*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user