Add Docker deployment and Gitea Actions CI/CD
Some checks failed
Deploy Documentation Site / build (push) Has been cancelled
Deploy Documentation Site / deploy (push) Has been cancelled

This commit is contained in:
hjdave
2026-04-04 16:17:02 +08:00
parent 38dc7203d1
commit d6db7a3eef
4 changed files with 164 additions and 1 deletions

13
.dockerignore Normal file
View File

@@ -0,0 +1,13 @@
.next
node_modules
.git
.env.local
.env.production.local
*.md
.DS_Store
.idea
.vscode
*.log
coverage
.github
.gitea

102
.gitea/workflows/deploy.yml Normal file
View File

@@ -0,0 +1,102 @@
name: Deploy Documentation Site
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
NODE_VERSION: '20.x'
REGISTRY: 'ghcr.io'
IMAGE_NAME: hjdave2/docs-site
jobs:
# 代码检查与测试
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Lint
run: npm run lint
if: always()
# 构建 Docker 镜像并部署
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd /var/www/docs-site
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker stop docs-site || true
docker rm docs-site || true
docker run -d --name docs-site \
-p 3000:3000 \
-e NODE_ENV=production \
-e HOST=0.0.0.0 \
-v /var/www/docs-site/.env:/app/.env \
--restart always \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker system prune -af --volumes

43
Dockerfile Normal file
View File

@@ -0,0 +1,43 @@
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package.json package-lock.json ./
RUN npm ci --ignore-scripts
# Copy source code
COPY . .
# Build the application
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy built application
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
CMD ["node", "server.js"]

View File

@@ -1,7 +1,12 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ output: 'standalone',
experimental: {
serverActions: {
bodySizeLimit: '2mb'
}
}
}; };
export default nextConfig; export default nextConfig;