Files
UserclassService/.gitea/workflows/ci.yml
T

85 lines
4.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: ci-bschclass-service
# 后端标准化 CI:maven 构建 jar -> docker build -> 推 Nexus docker-hosted
# 触发:push 到 master(本仓库默认分支)/ 手动 Run workflow
# ⚠️ 本 workflow 不再负责部署:镜像推完后由 projman 平台接管(DeployTab 选 tag 手动触发部署,
# 平台负责 compose 渲染 / 配置挂载 / 健康检查 / Caddy 路由)。
# 依赖仓库 Actions Secrets:NEXUS_USER / NEXUS_PASSWORD(ci-docker 账号,仅 docker-hosted 推送权)
# 中间件连接由 projman 平台按「infra 勾选」注入容器 env,无需 Secret
on:
push:
branches: [master]
workflow_dispatch:
inputs:
tag:
description: 'image tag (default = short sha)'
required: false
default: 'auto'
jobs:
build-and-push:
runs-on: ubuntu-latest
# docker:24 自带 docker CLI,复用宿主 docker daemon。
# 注意:act_runner 已把宿主 docker.sock 挂入每个 job 容器,
# 切勿在此再声明 volumes: docker.sock(会与默认挂载重复,报
# "Duplicate mount point" 导致容器创建失败、全部 step cancelled)。
container:
image: docker:24
steps:
# docker:24 基于 alpine,默认无 git;先装 git 再手动 clone 本仓库
- name: Install git (alpine)
run: apk add --no-cache git
# 内网 Gitea 无法访问 github.com 拉取 actions/checkout,改为直接 clone 本仓库(master 分支)
- name: Checkout (manual, internal Gitea)
run: |
git clone --depth 1 --branch master http://192.168.10.160:3000/${GITHUB_REPOSITORY}.git /tmp/src
cp -a /tmp/src/. .
rm -rf /tmp/src
- name: Compute image tag
id: meta
run: |
if [ "${{ inputs.tag }}" = "auto" ] || [ -z "${{ inputs.tag }}" ]; then
echo "tag=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT
else
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
fi
- name: Build jar with Maven
run: |
# job 容器通过 docker.sock 调的是【宿主 docker daemon】,
# 因此 docker run -v <path> 里的路径会被宿主按【宿主路径】解析;
# act 工作区是宿主上的 docker volume,容器内 $PWD 对宿主不可见,
# 直接 -v $PWD:/build 会绑成空目录导致找不到 pom.xml。
# 故改为:起 maven 容器 -> docker cp 源码入容器 -> exec 构建 -> cp 产物回工作区。
# mavenbuild 加入 infra-infra-net,用容器名 nexus 直连 Nexus(8081 maven-public)。
# settings.xml 新增 nexus-repo profile,把 pom 里的外部 HTTP 仓库重定向到
# http://nexus:8081/repository/maven-public/(infra-infra-net 内容器名直连,已验证可达),
# 避免容器内无法解析 nexus.yunhaixingtong.com(Caddy:80) 而拉不到 yh-platform 依赖。
docker rm -f mavenbuild 2>/dev/null || true
docker run -d --name mavenbuild \
--network infra-infra-net \
-v /opt/docker/ubs-m2:/root/.m2 \
-w /build maven:3.6.3-jdk-8 sleep 3600
docker cp "${PWD}/." mavenbuild:/build/
docker exec mavenbuild sh -c "printf '%s' '<settings><profiles><profile><id>nexus-repo</id><repositories><repository><id>nexus-internal</id><url>http://nexus:8081/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories></profile></profiles><activeProfiles><activeProfile>nexus-repo</activeProfile></activeProfiles></settings>' > /root/.m2/settings.xml"
# 仅清旧 yh-auth 缓存(避免本地安装优先于远端),其余 yh.platform 模块保留缓存
docker exec mavenbuild rm -rf /root/.m2/repository/com/yunhai/platform/yh-auth-spring-boot-starter
docker exec mavenbuild sh -c 'cd /build && mvn -U -B -DskipTests clean package'
mkdir -p "${PWD}/target"
docker cp mavenbuild:/build/target/BschClass-0.1.jar "${PWD}/target/BschClass-0.1.jar"
docker rm -f mavenbuild
- name: Login to Nexus docker registry
run: echo "${{ secrets.NEXUS_PASSWORD }}" | docker login nexus:8083 -u ${{ secrets.NEXUS_USER }} --password-stdin
- name: Build image
run: docker build -t nexus:8083/docker-hosted/bschclass-service:${{ steps.meta.outputs.tag }} -f docker/Dockerfile .
- name: Push image
run: docker push nexus:8083/docker-hosted/bschclass-service:${{ steps.meta.outputs.tag }}
- name: Report build
run: echo "pushed nexus:8083/docker-hosted/bschclass-service:${{ steps.meta.outputs.tag }} —— 部署请到 projman 平台 DeployTab 手动触发"