构建与镜像仓库
本章涵盖构建 Java 应用、创建 Docker 镜像以及搭建私有镜像仓库。
Maven 构建
构建所有模块
bash
export ATLAS_ROOT=/path/to/slaunchx-backend-platform
cd $ATLAS_ROOT
mvn package -DskipTests这将在每个模块的 target/ 目录中生成 JAR 文件。
构建单个模块
bash
# Build app-prometheus and its dependencies only
mvn package -DskipTests -am -pl slaunchx-app-prometheus-am 标志会自动构建所需的上游模块。
模块列表
| 模块 | 类型 | JAR 位置 |
|---|---|---|
| slaunchx-app-prometheus | 可运行 | slaunchx-app-prometheus/target/*.jar |
| slaunchx-support-email | 可运行 | slaunchx-support-email/target/*.jar |
| slaunchx-support-file | 可运行 | slaunchx-support-file/target/*.jar |
| slaunchx-support-schedule | 可运行 | slaunchx-support-schedule/target/*.jar |
| slaunchx-partner-slash | 可运行 | slaunchx-partner-slash/target/*.jar |
| slaunchx-partner-stripe | 可运行 | slaunchx-partner-stripe/target/*.jar |
| slaunchx-support-tron-wallet | 可运行 | slaunchx-support-tron-wallet/target/*.jar |
| slaunchx-support-solana-wallet | 可运行 | slaunchx-support-solana-wallet/target/*.jar |
其他模块(sdk-、common-)为库模块——它们生成 JAR 但不生成 Docker 镜像。
Docker 镜像构建
Dockerfile 位置
每个可运行模块的 Dockerfile 位于:
deploy/docker/Dockerfile.{module-short-name}示例:deploy/docker/Dockerfile.app-prometheus
构建镜像
bash
cd $ATLAS_ROOT
# Build app-prometheus image
docker build \
-f deploy/docker/Dockerfile.app-prometheus \
-t slaunchx/app-prometheus:dev-latest \
.使用构建脚本
仓库中包含一个辅助脚本,可以同时完成 Maven 构建和 Docker 镜像创建:
bash
# Build all modules (Maven + Docker)
ci/local/build.sh
# Build single module
ci/local/build.sh app-prometheus
# Maven only (skip Docker image)
ci/local/build.sh app-prometheus --maven-only私有 Docker 镜像仓库
部署到远程主机时,需要将镜像推送到私有仓库。
启动仓库
bash
docker run -d \
--name slaunchx-registry \
--network slaunchx-intra \
-p 127.0.0.1:5000:5000 \
-v /home/registry/data:/var/lib/registry \
-e REGISTRY_AUTH=htpasswd \
-e REGISTRY_AUTH_HTPASSWD_REALM="SlaunchX Registry" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v /home/registry/auth:/auth \
--restart unless-stopped \
registry:2创建仓库凭据
bash
mkdir -p /home/registry/auth
docker run --rm --entrypoint htpasswd \
httpd:2 -Bbn <username> <password> > /home/registry/auth/htpasswd推送镜像
bash
# Login
docker login localhost:5000
# Tag and push
docker tag slaunchx/app-prometheus:dev-latest \
localhost:5000/slaunchx/app-prometheus:dev-latest
docker push localhost:5000/slaunchx/app-prometheus:dev-latest镜像标签规范
| 标签 | 含义 |
|---|---|
dev-latest | dev 分支的最新构建 |
dev-{YYYYMMDD}-{HHMMSS} | 带时间戳的构建(例如 dev-20260314-091500) |
仓库清理
旧镜像会不断累积。定期运行垃圾回收:
bash
# Delete old tags (keep latest + 4 most recent per module)
# Then run GC
docker exec slaunchx-registry bin/registry garbage-collect \
/etc/docker/registry/config.yml --delete-untagged构建检查清单
- [ ] Maven 构建成功无错误
- [ ] 已为所有需要的模块创建 Docker 镜像
- [ ] 私有仓库运行中(如果部署到远程主机)
- [ ] 镜像已推送到仓库