Skip to content

构建与镜像仓库

本章涵盖构建 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-latestdev 分支的最新构建
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 镜像
  • [ ] 私有仓库运行中(如果部署到远程主机)
  • [ ] 镜像已推送到仓库

内部手册