Skip to content

Commit 0d32146

Browse files
authored
chore: add deployment test (#874)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an npm build script to simplify project compilation. * **Chores** * Simplified CI dependency installation to use standard npm install. * Added a new deployment test job that runs multi-service integration checks, build, health checks, and graceful shutdown. * Introduced an environment-variable gate to allow opting into local filesystem behavior in production. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 6c29f08 commit 0d32146

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

.github/workflows/nodejs.yml

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
node-version: 22
2929

3030
- name: Install Dependencies
31-
run: npm i -g npminstall && npminstall
31+
run: npm i
3232

3333
- name: Lint
3434
run: npm run lint
@@ -38,6 +38,79 @@ jobs:
3838

3939
- name: Build
4040
run: npm run tsc && npm run tsc:prod
41+
42+
test-deployment:
43+
runs-on: ubuntu-latest
44+
45+
concurrency:
46+
group: test-deployment-${{ github.workflow }}-#${{ github.event.pull_request.number || github.head_ref || github.ref }}
47+
cancel-in-progress: true
48+
49+
services:
50+
mysql:
51+
image: mysql:5.7
52+
env:
53+
MYSQL_ALLOW_EMPTY_PASSWORD: true
54+
MYSQL_DATABASE: cnpmcore
55+
ports:
56+
- 3306:3306
57+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
58+
redis:
59+
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers#example-mapping-redis-ports
60+
image: redis
61+
ports:
62+
# Opens tcp port 6379 on the host and service container
63+
- 6379:6379
64+
65+
steps:
66+
- name: Checkout Git Source
67+
uses: actions/checkout@v5
68+
69+
- name: Use Node.js
70+
uses: actions/setup-node@v6
71+
with:
72+
node-version: 22
73+
74+
- name: Install Dependencies
75+
run: npm i
76+
77+
- name: Test Deployment
78+
run: |
79+
npm run build
80+
echo "Preparing database..."
81+
CNPMCORE_DATABASE_NAME=cnpmcore bash ./prepare-database-mysql.sh
82+
echo "Starting cnpmcore..."
83+
CNPMCORE_FORCE_LOCAL_FS=true npm run start:foreground &
84+
sleep 5
85+
echo "Checking cnpmcore is ready..."
86+
87+
set -Eeuo pipefail
88+
URL="http://127.0.0.1:7001"
89+
PATTERN="instance_start_time"
90+
TIMEOUT=60
91+
TMP="$(mktemp)"
92+
echo "🔎 Health check $URL, expect 200 & body contains: $PATTERN"
93+
deadline=$((SECONDS + TIMEOUT))
94+
last_status=""
95+
96+
while (( SECONDS < deadline )); do
97+
last_status="$(curl -sS -o "$TMP" -w '%{http_code}' "$URL" || true)"
98+
echo "last_status=$last_status"
99+
echo "body=$(cat $TMP)"
100+
if [[ "$last_status" == "200" ]] && grep -q "$PATTERN" "$TMP"; then
101+
echo "✅ OK"
102+
rm -f "$TMP"
103+
npx eggctl stop
104+
exit 0
105+
fi
106+
sleep 1
107+
done
108+
109+
echo "::error::❌ Health check failed: status=$last_status"
110+
echo "---- Response body (last try) ----"
111+
cat "$TMP" || true
112+
rm -f "$TMP"
113+
exit 1
41114
42115
test-postgresql-fs-nfs:
43116
strategy:
@@ -91,7 +164,7 @@ jobs:
91164
node-version: ${{ matrix.node-version }}
92165

93166
- name: Install Dependencies
94-
run: npm i -g npminstall && npminstall
167+
run: npm i
95168

96169
# https://github.com/elastic/elastic-github-actions/blob/master/elasticsearch/README.md
97170
- name: Configure sysctl limits
@@ -178,7 +251,7 @@ jobs:
178251
node-version: ${{ matrix.node-version }}
179252

180253
- name: Install Dependencies
181-
run: npm i -g npminstall && npminstall
254+
run: npm i
182255

183256
- name: Continuous Integration
184257
run: npm run ci

app/infra/NFSClientAdapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export class NFSClientAdapter implements NFSClient {
4343
if (this.config.nfs.client) {
4444
this._client = this.config.nfs.client;
4545
} else {
46-
if (this.config.env === 'prod') {
46+
// Please do not set the CNPMCORE_FORCE_LOCAL_FS environment variable unless you know what you are doing.
47+
if (this.config.env === 'prod' && process.env.CNPMCORE_FORCE_LOCAL_FS !== 'true') {
4748
throw new Error(
4849
"[NFSAdapter] Can't use local fs NFS on production env"
4950
);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"ci": "npm run cov",
5959
"ci:postgresql": "npm run cov:postgresql",
6060
"clean": "tsc -b --clean && rm -rf dist *.tsbuildinfo",
61+
"build": "npm run tsc",
6162
"tsc": "npm run clean && tsc -p ./tsconfig.json",
6263
"tsc:prod": "npm run clean && tsc -p ./tsconfig.prod.json",
6364
"prepublishOnly": "npm run tsc:prod",

0 commit comments

Comments
 (0)