speccore 8.3.147 → 8.3.149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/commands/init.d.ts.map +1 -1
  2. package/dist/commands/init.js +9 -1
  3. package/dist/commands/init.js.map +1 -1
  4. package/dist/commands/update.d.ts.map +1 -1
  5. package/dist/commands/update.js +4 -1
  6. package/dist/commands/update.js.map +1 -1
  7. package/package.json +3 -2
  8. package/templates/api-design-example.md +338 -0
  9. package/templates/ci/github-actions.yml +44 -0
  10. package/templates/dashboard.html +425 -0
  11. package/templates/database-example.md +223 -0
  12. package/templates/deploy-docker/README.md +284 -0
  13. package/templates/deploy-docker/deploy-remote.sh +79 -0
  14. package/templates/deploy-docker/docker-compose.yml +113 -0
  15. package/templates/deploy-docker/frontend.Dockerfile +43 -0
  16. package/templates/deploy-docker/nginx.conf +30 -0
  17. package/templates/deploy-examples.yaml +436 -0
  18. package/templates/deploy-java/Dockerfile +50 -0
  19. package/templates/deploy-java/README.md +212 -0
  20. package/templates/deploy-java/deploy.sh +120 -0
  21. package/templates/deploy-java/spring-boot.service +35 -0
  22. package/templates/html/speccore-ask-explain.html +10 -0
  23. package/templates/html/speccore-ask-guide.html +10 -0
  24. package/templates/html/speccore-ask-match.html +10 -0
  25. package/templates/html/speccore-ask-pipeline.html +1 -0
  26. package/templates/html/speccore-ask-result.html +10 -0
  27. package/templates/html/speccore-demo.html +449 -0
  28. package/templates/html/speccore-dev.html +202 -0
  29. package/templates/html/speccore-help.html +1 -0
  30. package/templates/html/speccore-knowledge-graph.html +656 -0
  31. package/templates/html/speccore-retro-T-001.html +1 -0
  32. package/templates/html/speccore-setup-guide.html +289 -0
  33. package/templates/html/speccore-welcome.html +1 -0
  34. package/templates/security-example.md +226 -0
  35. package/templates/verify-spec-example.yaml +852 -0
@@ -0,0 +1,43 @@
1
+ # ═══════════════════════════════════════════════════════════
2
+ # 前端 Docker 构建示例(Nginx 多阶段构建)
3
+ # ═══════════════════════════════════════════════════════════
4
+ #
5
+ # 用法:
6
+ # 1. 将本文件复制到前端工程根目录
7
+ # 2. 如有自定义 nginx 配置,一并复制 nginx.conf 到同目录
8
+ # 3. 在 PROJECT.yaml 中配置 docker 类型部署
9
+ # 4. 执行: speccore deploy --env staging --platform admin-web
10
+ #
11
+ # 多阶段构建:Node 编译 → Nginx 托管静态资源
12
+ # ═══════════════════════════════════════════════════════════
13
+
14
+ # ── 阶段 1:构建 ──
15
+ FROM node:18-alpine AS builder
16
+ WORKDIR /app
17
+
18
+ # 先复制依赖文件(利用 Docker 缓存层)
19
+ COPY package*.json ./
20
+ RUN npm ci
21
+
22
+ # 复制源码并构建
23
+ COPY . .
24
+ ARG BUILD_ENV=staging
25
+ RUN npm run build:$BUILD_ENV
26
+
27
+ # ── 阶段 2:运行 ──
28
+ FROM nginx:alpine
29
+ WORKDIR /usr/share/nginx/html
30
+
31
+ # 复制构建产物
32
+ COPY --from=builder /app/dist .
33
+
34
+ # 复制自定义 nginx 配置(可选,没有则使用 Nginx 默认配置)
35
+ # COPY nginx.conf /etc/nginx/conf.d/default.conf
36
+
37
+ # 健康检查
38
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
39
+ CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1
40
+
41
+ EXPOSE 80
42
+
43
+ CMD ["nginx", "-g", "daemon off;"]
@@ -0,0 +1,30 @@
1
+ server {
2
+ listen 80;
3
+ server_name localhost;
4
+ root /usr/share/nginx/html;
5
+ index index.html;
6
+
7
+ # 前端路由支持(SPA 应用)
8
+ location / {
9
+ try_files $uri $uri/ /index.html;
10
+ }
11
+
12
+ # 静态资源缓存
13
+ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
14
+ expires 1y;
15
+ add_header Cache-Control "public, immutable";
16
+ }
17
+
18
+ # API 代理到后端(按需配置)
19
+ location /api/ {
20
+ proxy_pass http://backend:8080/api/;
21
+ proxy_set_header Host $host;
22
+ proxy_set_header X-Real-IP $remote_addr;
23
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
24
+ }
25
+
26
+ # 禁止访问隐藏文件
27
+ location ~ /\. {
28
+ deny all;
29
+ }
30
+ }
@@ -0,0 +1,436 @@
1
+ # ═══════════════════════════════════════════════════════════
2
+ # SpecCore 部署配置示例(v8.3.91+)
3
+ # ═══════════════════════════════════════════════════════════
4
+ #
5
+ # 使用方式:
6
+ # 1. 复制你需要的配置块到 PROJECT.yaml 的 platform.deploy 段
7
+ # 2. 或复制到 .speccore/environments/{env}.yaml 的 platform 段
8
+ #
9
+ # 部署命令:
10
+ # speccore deploy --env staging --platform <端名>
11
+ # speccore deploy --env staging --all
12
+ # speccore deploy --env production --platform h5 --dry-run # 预览模式
13
+ #
14
+ # ═══════════════════════════════════════════════════════════
15
+
16
+ # ─────────────────────────────────────────
17
+ # 1. SSH 部署(推荐:有独立服务器的场景)
18
+ # ─────────────────────────────────────────
19
+ #
20
+ # 适用场景:前端构建后上传到 Nginx/Apache 静态目录,或后端上传到服务器重启
21
+ #
22
+ # 认证方式:
23
+ # 方式 A — 密钥认证(推荐,更安全):
24
+ # 1) 本地生成密钥:ssh-keygen -t rsa -b 4096
25
+ # 2) 上传公钥到服务器:ssh-copy-id -i ~/.ssh/id_rsa.pub user@host
26
+ # 3) 配置 key 字段指向私钥路径
27
+ #
28
+ # 方式 B — 密码认证(v8.3.91+):
29
+ # 1) 安装 sshpass:
30
+ # macOS: brew install sshpass
31
+ # Ubuntu/Debian: apt-get install sshpass
32
+ # 2) 配置 password 字段
33
+ #
34
+ ssh_key_example:
35
+ type: ssh
36
+ build_cmd: npm run build:staging
37
+ output_dir: dist
38
+ host: deployer@192.168.1.100:22
39
+ key: ~/.ssh/id_rsa
40
+ remote_dir: /var/www/html/h5
41
+ script: sudo nginx -s reload
42
+ pre_deploy:
43
+ - echo "开始部署到 staging..."
44
+ post_deploy:
45
+ - echo "部署完成"
46
+
47
+ # SSH 密码认证示例
48
+ ssh_password_example:
49
+ type: ssh
50
+ build_cmd: npm run build:staging
51
+ output_dir: dist
52
+ host: deployer@192.168.1.100:22
53
+ password: your-password-here # SSH 密码(v8.3.91+,需安装 sshpass)
54
+ remote_dir: /var/www/html/h5
55
+ script: sudo nginx -s reload
56
+
57
+ # ─────────────────────────────────────────
58
+ # 2. SFTP 部署(无 SSH 权限,只有 SFTP)
59
+ # ─────────────────────────────────────────
60
+ #
61
+ # 适用场景:共享主机、虚拟主机,只有 SFTP 权限无 SSH 登录权限
62
+ #
63
+ sftp_example:
64
+ type: sftp
65
+ build_cmd: npm run build
66
+ output_dir: dist
67
+ host: deployer@192.168.1.100 # SFTP 地址(格式 user@host)
68
+ key: ~/.ssh/id_rsa # SSH 私钥路径
69
+ remote_dir: /var/www/html/h5 # 远程目录(SFTP 必须有写权限)
70
+
71
+ # ─────────────────────────────────────────
72
+ # 3. 静态资源部署(local / S3 / rsync)
73
+ # ─────────────────────────────────────────
74
+ #
75
+ # 适用场景:CDN、对象存储、共享文件系统、本地目录
76
+ #
77
+ # target 格式:
78
+ # - 本地路径:/var/www/html/h5
79
+ # - S3 桶:s3://my-bucket/h5/
80
+ # - rsync 远程:rsync://user@host:/var/www/html/h5
81
+ # - rsync 远程(简写):user@host:/var/www/html/h5
82
+ #
83
+ static_local_example:
84
+ type: static
85
+ build_cmd: npm run build
86
+ output_dir: dist
87
+ target: /var/www/html/h5 # 本地或挂载的共享目录
88
+
89
+ static_s3_example:
90
+ type: static
91
+ build_cmd: npm run build
92
+ output_dir: dist
93
+ target: s3://my-cdn-bucket/h5-staging/ # AWS S3(需安装 AWS CLI)
94
+
95
+ static_rsync_example:
96
+ type: static
97
+ build_cmd: npm run build
98
+ output_dir: dist
99
+ target: deployer@cdn-server:/var/www/html/h5 # rsync 远程同步
100
+
101
+ # ─────────────────────────────────────────
102
+ # 4. 自定义脚本部署(最灵活)
103
+ # ─────────────────────────────────────────
104
+ #
105
+ # 适用场景:Jenkins 触发、FTP 上传、复杂部署流程
106
+ #
107
+ # script 字段可以是:
108
+ # - 脚本文件路径(相对于 code_path):./scripts/deploy-staging.sh
109
+ # - 直接命令:curl -X POST http://jenkins/job/build/build
110
+ #
111
+ script_jenkins_example:
112
+ type: script
113
+ build_cmd: npm run build
114
+ script: ./scripts/trigger-jenkins.sh # 脚本文件(存在则执行 bash)
115
+ # 或直接写命令:
116
+ # script: "curl -X POST -u user:token http://jenkins.example.com/job/my-job/build"
117
+
118
+ script_ftp_example:
119
+ type: script
120
+ build_cmd: npm run build
121
+ output_dir: dist
122
+ script: ./scripts/deploy-ftp.sh # 脚本内容示例见下文
123
+
124
+ # ─────────────────────────────────────────
125
+ # 5. Docker 部署
126
+ # ─────────────────────────────────────────
127
+ #
128
+ # 适用场景:容器化部署,支持本地构建 + 镜像仓库推送 + 远程服务器部署
129
+ #
130
+ # 远程部署说明(v8.3.96+):
131
+ # - 配置 host 后,speccore 会自动 SSH 到远程服务器执行 docker pull && run
132
+ # - 远程部署必须配置 registry(否则远程服务器无法获取镜像)
133
+ # - 可通过 script 字段自定义远程命令(默认:stop → rm → pull → run)
134
+ # - 支持密钥认证(key)和密码认证(password + sshpass)
135
+ #
136
+ # 完整模板见 templates/deploy-docker/(含前端 Dockerfile、Nginx 配置、Compose 编排)
137
+
138
+ # 基础 Docker:仅本地构建并推送到仓库(适合 CI/CD 场景)
139
+ docker_push_only:
140
+ type: docker
141
+ dockerfile: ./Dockerfile
142
+ registry: registry.example.com
143
+ image: my-project/h5
144
+ tag: staging
145
+
146
+ # 前端 Docker + 远程部署(Nginx 托管)
147
+ docker_frontend_remote:
148
+ type: docker
149
+ build_cmd: npm run build:staging # 前置构建(可选)
150
+ dockerfile: ./Dockerfile # 多阶段构建:Node → Nginx
151
+ registry: registry.example.com
152
+ image: my-project/admin-web
153
+ tag: staging
154
+ host: deployer@staging-server.example.com # 远程服务器(v8.3.96+)
155
+ key: ~/.ssh/id_rsa
156
+ # script 自定义远程命令(可选,以下为默认值示例)
157
+ # script: "docker pull registry.example.com/my-project/admin-web:staging && docker stop admin-web 2>/dev/null; docker rm admin-web 2>/dev/null; docker run -d --name admin-web --restart always -p 80:80 registry.example.com/my-project/admin-web:staging"
158
+
159
+ # 后端 Java Docker + 远程部署
160
+ docker_backend_remote:
161
+ type: docker
162
+ dockerfile: ./Dockerfile # 多阶段构建:Maven → JRE
163
+ registry: registry.example.com
164
+ image: my-project/order-service
165
+ tag: staging
166
+ host: deployer@staging-server.example.com
167
+ key: ~/.ssh/id_rsa
168
+
169
+ # Docker Compose 统一部署(使用 script 类型调用 compose)
170
+ docker_compose_example:
171
+ type: script
172
+ script: ./scripts/deploy-compose.sh
173
+ # deploy-compose.sh 内容示例:
174
+ # cd /opt/deploy && docker-compose pull && docker-compose up -d
175
+
176
+ # ─────────────────────────────────────────
177
+ # 6. PM2 部署(Node.js 后端)
178
+ # ─────────────────────────────────────────
179
+ #
180
+ # 适用场景:Node.js 服务,本地或远程 PM2 进程管理
181
+ #
182
+ pm2_local_example:
183
+ type: pm2
184
+ build_cmd: npm run build
185
+ output_dir: .
186
+ pm2_config: ecosystem.config.js # PM2 配置文件(默认 ecosystem.config.js)
187
+
188
+ pm2_remote_example:
189
+ type: pm2
190
+ build_cmd: npm run build
191
+ pm2_config: ecosystem.config.js
192
+ host: deployer@192.168.1.100 # 远程服务器(可选,配置则 SSH 远程重启)
193
+ key: ~/.ssh/id_rsa
194
+ remote_dir: /opt/services/api
195
+
196
+ # ─────────────────────────────────────────
197
+ # 7. Kubernetes 部署
198
+ # ─────────────────────────────────────────
199
+ #
200
+ # 适用场景:K8s 集群
201
+ #
202
+ k8s_example:
203
+ type: k8s
204
+ target: staging # namespace(默认 default)
205
+ script: k8s/deployment.yaml # K8s manifest 文件路径(默认 k8s-deployment.yaml)
206
+
207
+ # ─────────────────────────────────────────
208
+ # 8. Helm 部署
209
+ # ─────────────────────────────────────────
210
+ #
211
+ # 适用场景:使用 Helm 管理 K8s 应用
212
+ #
213
+ helm_example:
214
+ type: helm
215
+ target: staging # namespace(默认环境名)
216
+ script: ./helm/h5 # Chart 路径(默认 ./helm/<端名>)
217
+ output_dir: values-staging.yaml # values 文件路径(默认 values-<env>.yaml)
218
+
219
+ # ─────────────────────────────────────────
220
+ # 9. Vercel 部署
221
+ # ─────────────────────────────────────────
222
+ #
223
+ # 适用场景:前端项目快速部署到 Vercel
224
+ #
225
+ vercel_example:
226
+ type: vercel
227
+ # 无需额外配置,执行 npx vercel --prod(production)或 npx vercel(preview)
228
+ # 需提前安装 Vercel CLI 并登录:npm i -g vercel && vercel login
229
+
230
+ # ─────────────────────────────────────────
231
+ # 10. Serverless 部署(函数计算)
232
+ # ─────────────────────────────────────────
233
+ #
234
+ # 适用场景:函数计算、无服务器架构
235
+ #
236
+ serverless_aliyun_example:
237
+ type: serverless
238
+ provider: aliyun-fc # 阿里云函数计算
239
+ target: my-func-name # 函数名(默认使用端名)
240
+
241
+ serverless_aws_example:
242
+ type: serverless
243
+ provider: aws-lambda # AWS Lambda
244
+ target: my-lambda-func
245
+
246
+ serverless_tencent_example:
247
+ type: serverless
248
+ provider: tencent-scf # 腾讯云云函数
249
+ target: my-scf-func
250
+
251
+ # ─────────────────────────────────────────
252
+ # 11. Java 后端部署(Spring Boot + systemd)
253
+ # ─────────────────────────────────────────
254
+ #
255
+ # 适用场景:Java 后端服务,通过 systemd 管理 jar 进程
256
+ #
257
+ # 服务器端准备(只需一次):
258
+ # 1) 将 templates/deploy-java/spring-boot.service 复制到服务器:
259
+ # /etc/systemd/system/order-service.service
260
+ # (文件名必须与 platform.name 一致)
261
+ # 2) 创建部署目录:mkdir -p /opt/services/order-service
262
+ # 3) 创建日志目录:mkdir -p /var/log/order-service
263
+ # 4) 重载 systemd:sudo systemctl daemon-reload
264
+ # 5) 启用开机自启:sudo systemctl enable order-service
265
+ #
266
+ # 数据库 / Redis 配置:
267
+ # 通过 Spring Boot profiles 切换,如 application-staging.yml
268
+ # 部署时激活 profile:script 中传入 --spring.profiles.active=staging
269
+ #
270
+ java_systemd_example:
271
+ type: ssh
272
+ build_cmd: mvn clean package -DskipTests -P staging
273
+ output_dir: target
274
+ host: deployer@staging-server.example.com:22
275
+ key: ~/.ssh/id_rsa
276
+ remote_dir: /opt/services/order-service
277
+ # 部署后执行:停止服务 → 替换 jar → 启动服务
278
+ script: sudo systemctl restart order-service
279
+ pre_deploy:
280
+ - echo "开始部署 Java 后端..."
281
+ post_deploy:
282
+ - echo "部署完成,检查状态..."
283
+ - ssh deployer@staging-server.example.com "sudo systemctl status order-service --no-pager"
284
+
285
+ # ─────────────────────────────────────────
286
+ # 12. Java 后端部署(Spring Boot + Docker)
287
+ # ─────────────────────────────────────────
288
+ #
289
+ # 适用场景:Java 服务容器化部署
290
+ #
291
+ # Dockerfile 示例见 templates/deploy-java/Dockerfile
292
+ #
293
+ java_docker_example:
294
+ type: docker
295
+ dockerfile: ./Dockerfile
296
+ registry: registry.example.com
297
+ image: my-project/order-service
298
+ tag: staging
299
+
300
+ # ═══════════════════════════════════════════════════════════
301
+ # 完整 PROJECT.yaml 示例(含部署配置)
302
+ # ═══════════════════════════════════════════════════════════
303
+
304
+ platforms:
305
+ - name: sr-web-operation
306
+ type: frontend
307
+ description: 运营管理前端
308
+ code_path: ./sr-web-operation
309
+ default_branch: main
310
+ requirement_unit: 运营管理
311
+ deploy:
312
+ staging:
313
+ type: ssh
314
+ build_cmd: npm run build:staging
315
+ output_dir: dist
316
+ host: deployer@staging-server.example.com
317
+ key: ~/.ssh/id_rsa
318
+ remote_dir: /var/www/html/sr-web-operation
319
+ script: sudo nginx -s reload
320
+ production:
321
+ type: ssh
322
+ build_cmd: npm run build:prod
323
+ output_dir: dist
324
+ host: deployer@prod-server.example.com
325
+ key: ~/.ssh/id_rsa_production
326
+ remote_dir: /var/www/html/sr-web-operation
327
+ script: sudo nginx -s reload
328
+
329
+ - name: api-service
330
+ type: backend
331
+ description: API 服务
332
+ code_path: ./api-service
333
+ default_branch: main
334
+ deploy:
335
+ staging:
336
+ type: pm2
337
+ build_cmd: npm run build
338
+ pm2_config: ecosystem.config.js
339
+ host: deployer@staging-server.example.com
340
+ key: ~/.ssh/id_rsa
341
+ remote_dir: /opt/services/api-service
342
+
343
+ # ═══════════════════════════════════════════════════════════
344
+ # 环境配置文件示例(.speccore/environments/staging.yaml)
345
+ # ═══════════════════════════════════════════════════════════
346
+ #
347
+ # 环境配置会与 PROJECT.yaml 的 deploy 段合并,优先级:环境配置 > PROJECT.yaml
348
+ #
349
+
350
+ branch: develop # pipeline 命令的目标分支
351
+ build_cmd: npm run build:staging # 覆盖 PROJECT.yaml 的构建命令
352
+
353
+ deploy:
354
+ type: ssh
355
+ host: deployer@staging-server.example.com:22
356
+ key: ~/.ssh/id_rsa
357
+ remote_dir: /var/www/html/sr-web-operation
358
+
359
+ # ═══════════════════════════════════════════════════════════
360
+ # 常用脚本示例
361
+ # ═══════════════════════════════════════════════════════════
362
+
363
+ # --- scripts/trigger-jenkins.sh ---
364
+ # #!/bin/bash
365
+ # curl -X POST \
366
+ # -u "$JENKINS_USER:$JENKINS_TOKEN" \
367
+ # "http://jenkins.example.com/job/my-project-$1/build"
368
+
369
+ # --- scripts/deploy-ftp.sh ---
370
+ # #!/bin/bash
371
+ # # 使用 lftp 进行 FTP 上传(支持密码)
372
+ # lftp -u "$FTP_USER,$FTP_PASS" "$FTP_HOST" <<EOF
373
+ # set ssl:verify-certificate no
374
+ # mirror -R dist /public_html/h5
375
+ # bye
376
+ # EOF
377
+
378
+ # --- scripts/deploy-password-ssh.sh ---
379
+ # #!/bin/bash
380
+ # # 使用 sshpass 进行密码认证的 SSH 部署(需安装 sshpass)
381
+ # # macOS: brew install sshpass
382
+ # # Ubuntu: apt-get install sshpass
383
+ # sshpass -p "$SSH_PASSWORD" scp -r dist/* "$SSH_USER@$SSH_HOST:$REMOTE_DIR/"
384
+ # sshpass -p "$SSH_PASSWORD" ssh "$SSH_USER@$SSH_HOST" "sudo nginx -s reload"
385
+
386
+ # --- scripts/deploy-java.sh(服务器端执行) ---
387
+ # #!/bin/bash
388
+ # # Java 后端部署脚本(放在服务器上,由 SSH 调用或手动执行)
389
+ # APP_NAME="${1:-order-service}"
390
+ # DEPLOY_DIR="/opt/services/$APP_NAME"
391
+ # BACKUP_DIR="/opt/services/$APP_NAME/backups"
392
+ # JAR_FILE="$DEPLOY_DIR/$APP_NAME.jar"
393
+ # NEW_JAR="$DEPLOY_DIR/$APP_NAME-new.jar"
394
+ #
395
+ # # 1. 备份旧版本
396
+ # mkdir -p "$BACKUP_DIR"
397
+ # if [ -f "$JAR_FILE" ]; then
398
+ # cp "$JAR_FILE" "$BACKUP_DIR/$APP_NAME-$(date +%Y%m%d-%H%M%S).jar"
399
+ # # 只保留最近 5 个备份
400
+ # ls -t "$BACKUP_DIR"/*.jar | tail -n +6 | xargs -r rm -f
401
+ # fi
402
+ #
403
+ # # 2. 替换 jar
404
+ # if [ -f "$NEW_JAR" ]; then
405
+ # mv "$NEW_JAR" "$JAR_FILE"
406
+ # else
407
+ # echo "错误:未找到新 jar 文件 $NEW_JAR"
408
+ # exit 1
409
+ # fi
410
+ #
411
+ # # 3. 重启服务
412
+ # sudo systemctl restart "$APP_NAME"
413
+ # sleep 2
414
+ # sudo systemctl status "$APP_NAME" --no-pager
415
+
416
+ # --- systemd service 文件示例(/etc/systemd/system/order-service.service) ---
417
+ # [Unit]
418
+ # Description=Order Service
419
+ # After=network.target
420
+ #
421
+ # [Service]
422
+ # Type=simple
423
+ # User=deployer
424
+ # Group=deployer
425
+ # WorkingDirectory=/opt/services/order-service
426
+ # Environment="SPRING_PROFILES_ACTIVE=staging"
427
+ # Environment="JAVA_OPTS=-Xms512m -Xmx1024m -Dfile.encoding=UTF-8"
428
+ # ExecStart=/usr/bin/java $JAVA_OPTS -jar order-service.jar
429
+ # ExecStop=/bin/kill -SIGTERM $MAINPID
430
+ # Restart=on-failure
431
+ # RestartSec=10
432
+ # StandardOutput=append:/var/log/order-service/app.log
433
+ # StandardError=append:/var/log/order-service/error.log
434
+ #
435
+ # [Install]
436
+ # WantedBy=multi-user.target
@@ -0,0 +1,50 @@
1
+ # ═══════════════════════════════════════════════════════════
2
+ # Spring Boot Docker 构建示例
3
+ # ═══════════════════════════════════════════════════════════
4
+ #
5
+ # 用法:
6
+ # 1. 将本文件复制到 Java 工程根目录(与 pom.xml 同级)
7
+ # 2. 在 PROJECT.yaml 中配置 docker 类型部署:
8
+ # deploy:
9
+ # staging:
10
+ # type: docker
11
+ # dockerfile: ./Dockerfile
12
+ # registry: registry.example.com
13
+ # image: my-project/order-service
14
+ # tag: staging
15
+ # 3. 执行: speccore deploy --env staging --platform order-service
16
+ #
17
+ # 多阶段构建:先编译,再复制 jar 到精简镜像
18
+ # ═══════════════════════════════════════════════════════════
19
+
20
+ # ── 阶段 1:构建 ──
21
+ FROM maven:3.9-eclipse-temurin-17-alpine AS builder
22
+ WORKDIR /build
23
+ COPY pom.xml .
24
+ COPY src ./src
25
+ RUN mvn clean package -DskipTests -P docker
26
+
27
+ # ── 阶段 2:运行 ──
28
+ FROM eclipse-temurin:17-jre-alpine
29
+ WORKDIR /app
30
+
31
+ # 创建非 root 用户(安全最佳实践)
32
+ RUN addgroup -S appgroup && adduser -S appuser -G appgroup
33
+
34
+ # 复制构建产物
35
+ COPY --from=builder /build/target/*.jar app.jar
36
+
37
+ # 环境变量(可在运行时通过 -e 覆盖)
38
+ ENV SPRING_PROFILES_ACTIVE=staging
39
+ ENV JAVA_OPTS="-Xms512m -Xmx1024m -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"
40
+
41
+ # 暴露端口(根据实际应用修改)
42
+ EXPOSE 8080
43
+
44
+ # 健康检查
45
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
46
+ CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
47
+
48
+ USER appuser
49
+
50
+ ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]