Skip to content

Commit 16423fa

Browse files
committed
update deploy
1 parent 01c2a64 commit 16423fa

File tree

9 files changed

+125
-28
lines changed

9 files changed

+125
-28
lines changed

.github/workflows/build-and-push.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ on:
44
push:
55
branches:
66
- main
7+
# 只有当以下路径的文件发生变动时,才触发此工作流
8+
paths:
9+
- 'src/**'
10+
- 'public/**'
11+
- 'docker/**'
12+
- 'package.json'
13+
- 'pnpm-lock.yaml'
14+
- 'next.config.js'
15+
- 'redirects.js'
16+
- 'tailwind.config.mjs'
17+
- 'tsconfig.json'
18+
- 'components.json'
19+
- '.env.example'
20+
21+
# 以下路径的变动绝对不会触发构建
22+
paths-ignore:
23+
- 'README.md'
24+
- 'AGENTS.md'
25+
- '.vscode/**'
26+
- '.cursor/**'
27+
- '.gitignore'
28+
- '.prettier*'
29+
- 'eslint.config.mjs'
30+
- 'tests/**'
31+
- 'playwright.config.ts'
32+
- 'vitest.config.mts'
733
workflow_dispatch:
834

935
permissions:
@@ -122,7 +148,7 @@ jobs:
122148
REGISTRY=public.ecr.aws/umcai/xc2f/payload
123149
124150
# 2. 构建镜像
125-
docker build -f docker/Dockerfile.CI \
151+
docker build -f docker/Dockerfile.prod \
126152
-t $REGISTRY:latest \
127153
-t $REGISTRY:${SHORT_SHA} .
128154

.github/workflows/build-to-branch.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ on:
44
push:
55
branches:
66
- main
7+
# 只有当以下路径的文件发生变动时,才触发此工作流
8+
paths:
9+
- 'src/**'
10+
- 'public/**'
11+
- 'docker/**'
12+
- 'package.json'
13+
- 'pnpm-lock.yaml'
14+
- 'next.config.js'
15+
- 'redirects.js'
16+
- 'tailwind.config.mjs'
17+
- 'tsconfig.json'
18+
- 'components.json'
19+
- '.env.example'
20+
21+
# 以下路径的变动绝对不会触发构建
22+
paths-ignore:
23+
- 'README.md'
24+
- 'AGENTS.md'
25+
- '.vscode/**'
26+
- '.cursor/**'
27+
- '.gitignore'
28+
- '.prettier*'
29+
- 'eslint.config.mjs'
30+
- 'tests/**'
31+
- 'playwright.config.ts'
32+
- 'vitest.config.mts'
733
workflow_dispatch:
834

935
env:

docker-compose.prod.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
payload:
3+
restart: always
4+
image: public.ecr.aws/umcai/xc2f/payload:latest
5+
container_name: payload
6+
ports:
7+
- '3000:3000'
8+
depends_on:
9+
- postgres
10+
env_file:
11+
- .env
12+
13+
postgres:
14+
restart: always
15+
image: postgres:latest
16+
container_name: postgres
17+
command: postgres -c config_file=/var/lib/postgresql/postgresql.conf
18+
volumes:
19+
- pgdata:/var/lib/postgresql
20+
- ./postgres/postgresql.conf:/var/lib/postgresql/postgresql.conf:ro
21+
- ./postgres/pg_hba.conf:/var/lib/postgresql/pg_hba.conf:ro
22+
environment:
23+
- POSTGRES_USER=${DATABASE_USER}
24+
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
25+
- POSTGRES_DB=${DATABASE_NAME}
26+
27+
volumes:
28+
pgdata:
29+
external: true
30+
name: xc2f_pgdata

docker-compose.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
services:
22
payload:
3-
# image: node:24-alpine
43
build:
54
context: .
65
dockerfile: ./docker/Dockerfile
@@ -16,12 +15,8 @@ services:
1615
environment:
1716
- NPM_CONFIG_USERCONFIG=/home/node/.npmrc
1817
- PNPM_STORE_DIR=/home/node/.pnpm-store
19-
- APP_CMD=${APP_CMD}
2018
# - NODE_OPTIONS="--max-old-space-size=4096"
21-
# for dev
22-
# command: sh -c "pnpm ${APP_CMD}"
23-
# for product
24-
command: sh -c "pnpm build && pnpm start"
19+
command: sh -c "pnpm ${APP_CMD}"
2520
working_dir: /app
2621
depends_on:
2722
- postgres
@@ -37,14 +32,14 @@ services:
3732
- pgdata:/var/lib/postgresql
3833
- ./postgres/postgresql.conf:/var/lib/postgresql/postgresql.conf:ro
3934
- ./postgres/pg_hba.conf:/var/lib/postgresql/pg_hba.conf:ro
40-
# ports:
41-
# - '5432:5432'
4235
environment:
4336
- POSTGRES_USER=${DATABASE_USER}
4437
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
4538
- POSTGRES_DB=${DATABASE_NAME}
4639

4740
volumes:
4841
pgdata:
42+
external: true
43+
name: xc2f_pgdata
4944
node_modules:
5045
pnpm_store:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"test": "pnpm run test:int && pnpm run test:e2e",
2121
"test:e2e": "cross-env NODE_OPTIONS=\"--no-deprecation --no-experimental-strip-types\" pnpm exec playwright test --config=playwright.config.ts",
2222
"test:int": "cross-env NODE_OPTIONS=--no-deprecation vitest run --config ./vitest.config.mts",
23-
"deploy": "bash scripts/deploy.sh"
23+
"deploy": "bash scripts/deploy.sh",
24+
"deploy-to-dev": "bash scripts/deploy-to-dev.sh"
2425
},
2526
"dependencies": {
2627
"@aws-sdk/client-sesv2": "^3.962.0",

scripts/deploy-to-dev.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
5+
6+
cd "$PROJECT_DIR"
7+
8+
echo "👉 Pull main"
9+
git pull origin main
10+
11+
echo "👉 Fetch build"
12+
git fetch origin build
13+
14+
echo "👉 Clean build artifacts"
15+
rm -rf .next public
16+
17+
echo "👉 Restore build artifacts"
18+
git restore --source origin/build .next public
19+
20+
echo "👉 Start docker"
21+
docker-compose up -d

scripts/deploy.sh

100755100644
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@ PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
55

66
cd "$PROJECT_DIR"
77

8-
echo "👉 Stop docker"
9-
docker-compose down
8+
# 定义文件路径变量
9+
COMPOSE_FILE="docker/docker-compose.prod.yml"
1010

11-
# echo "👉 Stash docker-compose.yml"
12-
# git stash push -- docker-compose.yml || true
11+
echo "🚀 Starting deployment..."
1312

14-
echo "👉 Pull main"
15-
git pull origin main
13+
# 1. 拉取最新镜像
14+
echo "📥 Pulling latest images..."
15+
docker compose -f $COMPOSE_FILE pull
1616

17-
echo "👉 Fetch build"
18-
git fetch origin build
17+
# 2. 启动/更新容器
18+
echo "🆙 Starting containers..."
19+
docker compose -f $COMPOSE_FILE up -d
1920

20-
echo "👉 Clean build artifacts"
21-
rm -rf .next public
21+
# 3. 清理旧镜像
22+
echo "🧹 Cleaning up old images..."
23+
docker image prune -f
2224

23-
echo "👉 Restore build artifacts"
24-
git restore --source origin/build .next public
25-
26-
# echo "👉 Restore stash"
27-
# git stash pop || true
28-
29-
echo "👉 Start docker"
30-
docker-compose up -d
25+
echo "✅ Deployment completed successfully!"

src/payload.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { sendEmailTask } from './tasks/sendEmail'
2626
import { en } from '@payloadcms/translations/languages/en'
2727
import { zh } from '@payloadcms/translations/languages/zh'
2828

29+
import { migrations } from './migrations'
30+
2931
const filename = fileURLToPath(import.meta.url)
3032
const dirname = path.dirname(filename)
3133

@@ -81,6 +83,7 @@ export default buildConfig({
8183
connectionString: process.env.DATABASE_URL,
8284
},
8385
// push: true,
86+
// prodMigrations: migrations,
8487
}),
8588
collections: [Pages, Posts, Media, Categories, Notes, Feeds, Mails, Users],
8689
cors: [getServerSideURL()].filter(Boolean),

0 commit comments

Comments
 (0)