From 4bd5c687bcb15608738ce2441b27c3045e924e3c Mon Sep 17 00:00:00 2001 From: SpecialX <47072643+wangxiner55@users.noreply.github.com> Date: Thu, 18 Dec 2025 17:16:39 +0800 Subject: [PATCH] feat: setup standalone build and docker deployment --- .gitea/workflows/ci.yml | 18 ++++++++++++++++++ Dockerfile | 22 ++++++++++++++++++++++ next.config.ts | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 19cd416..9841f71 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -40,3 +40,21 @@ jobs: next.config.* tsconfig.json .npmrc + public + Dockerfile + + deploy: + needs: build-and-test + runs-on: CDCD + steps: + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: next-build + + - name: Deploy to Docker + run: | + docker build -t nextjs-app . + docker stop nextjs-app || true + docker rm nextjs-app || true + docker run -d -p 3492:3000 --restart unless-stopped --name nextjs-app nextjs-app diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..842b8c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:22-alpine AS runner +WORKDIR /app + +ENV NODE_ENV production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +# Copy standalone output +# We assume the context contains the .next folder and public folder from the artifacts +COPY --chown=nextjs:nodejs .next/standalone ./ +COPY --chown=nextjs:nodejs .next/static ./.next/static +COPY --chown=nextjs:nodejs public ./public + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" + +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index e9ffa30..68a6c64 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", }; export default nextConfig;