diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eca4c6e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.next +node_modules +.git +.env.local +.env.production.local +*.md +.DS_Store +.idea +.vscode +*.log +coverage +.github +.gitea diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..42e754b --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cebea61 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/next.config.ts b/next.config.ts index e9ffa30..15aed63 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,12 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: 'standalone', + experimental: { + serverActions: { + bodySizeLimit: '2mb' + } + } }; export default nextConfig;