Skip to content

Commit 6041d20

Browse files
authored
refactor: ♻️ migrate project structure to monorepo with turborepo- Move Next.js app to apps/DocFlow- Setup workspace root with pnpm-workspace.yaml- Configure turborepo for build orchestration- Update paths and environment variables (#287)
1 parent 53deb8e commit 6041d20

File tree

605 files changed

+1213
-970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

605 files changed

+1213
-970
lines changed

.github/ISSUE_TEMPLATE/TASK.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
name: 📋 需求任务
33
about: 用于发布新的开发需求任务
4-
title: '[需求] 需求标题'
5-
labels: '待认领'
6-
assignees: ''
4+
title: "[需求] 需求标题"
5+
labels: "待认领"
6+
assignees: ""
77
---
88

99
## 需求描述

.github/workflows/build.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4.2.0
15+
16+
- name: Extract version
17+
id: version
18+
run: |
19+
VERSION="$(echo ${{ github.sha }} | cut -c1-7)"
20+
echo "version=$VERSION" >> $GITHUB_OUTPUT
21+
echo "📦 Version: $VERSION"
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to Docker Hub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKER_USERNAME }}
30+
password: ${{ secrets.DOCKER_PASSWORD }}
31+
32+
- name: Build and push Docker image
33+
uses: docker/build-push-action@v5
34+
with:
35+
context: .
36+
push: true
37+
tags: |
38+
${{ secrets.DOCKER_USERNAME }}/docflow:latest
39+
${{ secrets.DOCKER_USERNAME }}/docflow:${{ steps.version.outputs.version }}
40+
build-args: |
41+
VERSION=${{ steps.version.outputs.version }}
42+
GIT_COMMIT=${{ github.sha }}
43+
cache-from: type=gha
44+
cache-to: type=gha,mode=max
45+
platforms: linux/amd64
46+
47+
- name: Build summary
48+
run: |
49+
echo "## 🐳 Docker Build Summary" >> $GITHUB_STEP_SUMMARY
50+
echo "" >> $GITHUB_STEP_SUMMARY
51+
echo "- 📦 Version: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
52+
echo "- 🐳 Image: [Docker Hub](https://hub.docker.com/r/${{ secrets.DOCKER_USERNAME }}/docflow)" >> $GITHUB_STEP_SUMMARY
53+
echo "- 🏷️ Tags: \`latest\`, \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
54+
echo "- ⏰ Time: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
55+
echo "" >> $GITHUB_STEP_SUMMARY
56+
echo "> 💡 **Tip:** To deploy this version, create a \`release/*\` branch" >> $GITHUB_STEP_SUMMARY

.github/workflows/deploy.yml

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,32 @@
1-
name: Deploy to Server via Docker Hub
1+
name: Deploy to Server
22

33
on:
44
push:
55
branches:
6-
- main
6+
- 'release/**'
77

88
jobs:
9-
build-and-push:
9+
deploy:
1010
runs-on: ubuntu-latest
11-
outputs:
12-
version: ${{ steps.version.outputs.version }}
1311

1412
steps:
1513
- name: Checkout code
1614
uses: actions/checkout@v4.2.0
1715

18-
- name: Extract version
16+
- name: Get latest image version
1917
id: version
2018
run: |
21-
VERSION="$(echo ${{ github.sha }} | cut -c1-7)"
19+
# 获取最新的短 commit SHA
20+
VERSION="$(git rev-parse --short=7 HEAD)"
2221
echo "version=$VERSION" >> $GITHUB_OUTPUT
23-
echo "📦 Version: $VERSION"
24-
25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v3
27-
28-
- name: Log in to Docker Hub
29-
uses: docker/login-action@v3
30-
with:
31-
username: ${{ secrets.DOCKER_USERNAME }}
32-
password: ${{ secrets.DOCKER_PASSWORD }}
33-
34-
- name: Build and push Docker image
35-
uses: docker/build-push-action@v5
36-
with:
37-
context: .
38-
push: true
39-
tags: |
40-
${{ secrets.DOCKER_USERNAME }}/docflow:latest
41-
${{ secrets.DOCKER_USERNAME }}/docflow:${{ steps.version.outputs.version }}
42-
cache-from: type=gha
43-
cache-to: type=gha,mode=max
44-
platforms: linux/amd64
22+
echo "📦 Deploying Version: $VERSION"
4523
46-
deploy:
47-
needs: build-and-push
48-
runs-on: ubuntu-latest
49-
50-
steps:
5124
- name: Deploy to server via SSH
5225
uses: appleboy/ssh-action@v1.2.1
5326
env:
5427
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
5528
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
56-
VERSION: ${{ needs.build-and-push.outputs.version }}
29+
VERSION: ${{ steps.version.outputs.version }}
5730
with:
5831
host: ${{ secrets.SERVER_HOST }}
5932
username: ${{ secrets.SERVER_USERNAME }}
@@ -181,6 +154,7 @@ jobs:
181154
run: |
182155
echo "## 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
183156
echo "" >> $GITHUB_STEP_SUMMARY
184-
echo "- 📦 Version: \`${{ needs.build-and-push.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
157+
echo "- 📦 Version: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
185158
echo "- 🐳 Image: [Docker Hub](https://hub.docker.com/r/${{ secrets.DOCKER_USERNAME }}/docflow)" >> $GITHUB_STEP_SUMMARY
159+
echo "- 🌿 Branch: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
186160
echo "- ⏰ Time: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

3+
# Environment variables
34
.env
5+
.env*.local
46

5-
# dependencies
6-
/node_modules
7-
/.pnp
7+
# Dependencies
8+
node_modules/
9+
.pnp
810
.pnp.js
911

10-
# testing
11-
/coverage
12+
# Monorepo & Build tools
13+
.turbo/
14+
*.tsbuildinfo
1215

13-
# next.js
14-
/.next/
15-
/out/
16+
# Build outputs
17+
dist/
18+
build/
19+
out/
20+
.next/
1621

17-
# production
18-
/build
22+
# Testing
23+
coverage/
1924

20-
# misc
21-
.DS_Store
22-
*.pem
25+
# Next.js
26+
next-env.d.ts
27+
28+
# Vercel
29+
.vercel
2330

24-
# debug
31+
# Debug logs
2532
npm-debug.log*
2633
yarn-debug.log*
2734
yarn-error.log*
35+
pnpm-debug.log*
2836

29-
# local env files
30-
.env*.local
31-
32-
# vercel
33-
.vercel
37+
# OS files
38+
.DS_Store
39+
*.pem
3440

35-
# typescript
36-
*.tsbuildinfo
37-
next-env.d.ts
41+
# IDE
42+
.vscode/settings.json
43+
.idea/
3844

45+
# Misc
3946
.hintrc

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -e
55

66
echo "🔍 Running lint check..."
7-
pnpm lint:ci
7+
pnpm lint
88

99
echo "🎨 Running format check..."
1010
pnpm format:ci

.npmrc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
public-hoist-pattern[]=*import-in-the-middle*
2-
public-hoist-pattern[]=*require-in-the-middle*
1+
# Monorepo settings
2+
auto-install-peers=true
3+
strict-peer-dependencies=false
4+
shamefully-hoist=false
35

4-
node-linker=hoisted
5-
shamefully-hoist=true
6+
# Performance
7+
prefer-frozen-lockfile=true
8+
engine-strict=true
9+
10+
# Resolution
11+
resolution-mode=highest

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
dist/
22
node_modules/
3-
pnpm-lock.yaml
3+
pnpm-lock.yaml
4+
.next/
5+
.turbo/
6+
coverage/

Dockerfile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ RUN npm config set registry https://registry.npmmirror.com && \
99
WORKDIR /app
1010

1111
FROM base AS deps
12-
COPY package.json pnpm-lock.yaml ./
12+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
13+
COPY apps/DocFlow/package.json ./apps/DocFlow/package.json
1314
RUN pnpm install --frozen-lockfile --ignore-scripts
1415

1516
FROM base AS builder
@@ -20,18 +21,21 @@ ARG GIT_COMMIT=unknown
2021

2122
WORKDIR /app
2223
COPY --from=deps /app/node_modules ./node_modules
23-
COPY . .
24+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
25+
COPY apps/ ./apps/
26+
COPY packages/ ./packages/ 2>/dev/null || true
2427

2528
# 构建时环境变量
2629
ENV NEXT_TELEMETRY_DISABLED=1
2730
ENV NODE_OPTIONS="--max-old-space-size=4096"
2831

2932
RUN pnpm build && \
30-
rm -rf .next/cache
33+
rm -rf apps/DocFlow/.next/cache
3134

3235
FROM base AS prod-deps
3336
WORKDIR /app
34-
COPY package.json pnpm-lock.yaml ./
37+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
38+
COPY apps/DocFlow/package.json ./apps/DocFlow/package.json
3539
RUN pnpm install --frozen-lockfile --prod --ignore-scripts && \
3640
find node_modules -name "*.d.ts" -delete && \
3741
find node_modules -name "*.map" -delete && \
@@ -69,14 +73,17 @@ RUN apk add --no-cache libc6-compat && \
6973
adduser --system --uid 1001 nextjs
7074

7175
COPY --from=prod-deps --chown=nextjs:nodejs /app/node_modules ./node_modules
72-
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
73-
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
76+
COPY --from=builder --chown=nextjs:nodejs /app/apps/DocFlow/.next ./apps/DocFlow/.next
77+
COPY --from=builder --chown=nextjs:nodejs /app/apps/DocFlow/public ./apps/DocFlow/public
78+
COPY --from=builder --chown=nextjs:nodejs /app/apps/DocFlow/package.json ./apps/DocFlow/package.json
7479
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
80+
COPY --from=builder --chown=nextjs:nodejs /app/pnpm-workspace.yaml ./pnpm-workspace.yaml
7581

7682
USER nextjs
7783
EXPOSE 3000
7884

7985
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
8086
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
8187

82-
CMD ["node_modules/.bin/next", "start"]
88+
WORKDIR /app/apps/DocFlow
89+
CMD ["../../node_modules/.bin/next", "start"]

0 commit comments

Comments
 (0)