Compare commits

...
6 Commits
Author SHA1 Message Date
lijing 6f2edb171c refactor: API base 路径 /bschclass 改为 /userclass
deploy-bschclass-front / build-and-deploy (push) Failing after 24s
build / build (push) Failing after 5s
2026-09-04 15:22:57 +08:00
lijing 9e0c12ad42 merge projman injected files 2026-09-04 15:20:26 +08:00
lijing 487239724d init: 用户班级前端代码(源 BSchClassManageFront) 2026-09-04 15:20:04 +08:00
admin 0073213216 ci: init build workflow [skip ci] 2026-09-04 10:07:42 +08:00
admin c189c5ed1d init: readme guide [skip ci] 2026-09-04 10:07:12 +08:00
admin f77e5c7714 Initial commit 2026-09-04 10:07:12 +08:00
4 changed files with 144 additions and 3 deletions
+88
View File
@@ -0,0 +1,88 @@
name: build
# 前端应用 CI:构建 → 打包 zip → 推 Nexus raw → 通知 projman 建档
# 触发:push 到 main / 手动 Run workflow
# 链路:clone 源码 -> node 容器 npm ci + npm run build -> 打包 dist 为 zip -> 推 Nexus raw -> 通知 projman 建档
# 依赖仓库 Secrets:DEPLOY_TOKEN(webhook 鉴权)、NEXUS_USER / NEXUS_PASSWORD(上传 zip 到 Nexus raw)
# 注意:CI 构建后自动建档(status=pending),前端发布仍由用户在「前端发布」Tab 点部署触发
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
container:
image: docker:24
options: --network infra-infra-net
steps:
- name: 安装 git / curl / zip(alpine)
run: apk add --no-cache git curl zip
# 内网 Gitea 无法访问 GitHub 拉 actions/checkout,手动 clone 本仓库
- name: 拉取源码(内网无 GitHub,手动 clone 本仓库)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git clone --depth 1 --branch main "http://x-access-token:${GITHUB_TOKEN}@gitea.yunhaixingtong.com/${{ github.repository }}.git" /tmp/src
cp -a /tmp/src/. .
rm -rf /tmp/src
# 取提交备注首行,脱去换行/双引号/反斜杠(避免破坏 webhook JSON),截断到 200 字符
COMMIT_MSG=$(git log -1 --pretty=%s | tr '\n' ' ' | sed 's/["\\]/ /g' | cut -c1-200)
echo "COMMIT_MSG=${COMMIT_MSG}" >> "$GITHUB_ENV"
# 前端构建:起独立 node 容器(通过 docker.sock 调宿主 dockerd)
# node:20 镜像预装 npm,npm ci 按 lockfile 安装依赖
- name: 构建前端(node 容器)
run: |
set -e
docker rm -f frontbuild 2>/dev/null || true
docker run -d --name frontbuild -w /build node:20 sleep 3600
docker cp "${PWD}/." frontbuild:/build/
docker exec frontbuild sh -c '
set -e
cd /build
if [ -f .npmrc ]; then sed -i "/SASS_BINARY_PATH/d" .npmrc; fi
npm ci
npm run build
'
echo "=== dist 产物 ==="
docker exec frontbuild sh -c 'ls -la /build/dist/ | head -20'
# 从容器 cp dist 到宿主工作目录
docker cp frontbuild:/build/dist ./dist
docker rm -f frontbuild
echo "BUILD CHECK OK"
# 打包 dist → zip(进入 dist 目录打包,zip 根目录直接是 html/css/js 文件)
- name: 打包产物
run: |
TAG=$(echo "$GITHUB_SHA" | cut -c1-8)
ZIP_FILE="userclass-front-${TAG}.zip"
cd dist && zip -r "../${ZIP_FILE}" . && cd ..
echo "ZIP_FILE=${ZIP_FILE}" >> "$GITHUB_ENV"
echo "TAG=${TAG}" >> "$GITHUB_ENV"
ls -la "${ZIP_FILE}"
# 上传到 Nexus raw 仓库
- name: 上传产物到 Nexus
env:
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
run: |
NEXUS_URL="http://nexus.yunhaixingtong.com:8081/repository/front-hosted/${ZIP_FILE}"
curl -sS -X PUT \
-u "${NEXUS_USER}:${NEXUS_PASSWORD}" \
--upload-file "${ZIP_FILE}" \
"${NEXUS_URL}"
echo "NEXUS_URL=${NEXUS_URL}" >> "$GITHUB_ENV"
echo "uploaded to ${NEXUS_URL}"
# 通知 projman:webhook 收到后建档(type=front, status=pending),部署由用户在「前端发布」Tab 手动触发
- name: 通知 projman 建档
run: |
curl -sS -X POST "http://192.168.10.160:8090/projman/api/deploy/webhook" \
-H "Content-Type: application/json" \
-H "X-Deploy-Token: ${{ secrets.DEPLOY_TOKEN }}" \
-d "{\"app\":\"userclass\",\"front\":\"front\",\"tag\":\"${TAG}\",\"sha\":\"${GITHUB_SHA}\",\"message\":\"${COMMIT_MSG}\",\"nexusUrl\":\"${NEXUS_URL}\"}"
+53
View File
@@ -0,0 +1,53 @@
# UserclassFront
> 本仓库由 projman 自动创建并注入 CI(`.gitea/workflows/build.yml`)与 Dockerfile(`docker/Dockerfile`)。
> 推送代码到 main 分支即自动构建镜像并推送到 Nexus,projman 收到通知后建档待部署,由运维在 projman「后端发布」手动点部署。
## 首次推送本地代码到本仓库
> 目标:把本地已有代码推上去,同时**保留** projman 注入的文件(`build.yml`、`Dockerfile`)。
```bash
# 1. 进入本地代码目录
cd /your/local/code/dir
# 2. 初始化 git(目录已有 .git 也安全,git init 幂等无副作用)
git init
git branch -M main
# 3. 先把本地代码提交成一个 commit(关键!不提交直接 merge 会丢失本地代码)
git add -A
git commit -m "init local code"
# 4. 关联远程仓库(幂等:已存在 origin 则改地址,不报错)
git remote add origin http://gitea.yunhaixingtong.com/userclass/UserclassFront.git 2>/dev/null \
|| git remote set-url origin http://gitea.yunhaixingtong.com/userclass/UserclassFront.git
# 5. 拉取远程信息(只下载,不合并)
git fetch origin
# 6. 合并远程 main(关键步骤)
# 本地与远程是两条独立历史,需允许合并不相关历史。
# 此步会把 projman 注入的 build.yml 与 Dockerfile 合并进你的本地工作区。
git merge origin/main --allow-unrelated-histories -m "merge projman injected files"
# 7. 查看状态(确认 .gitea/workflows/build.yml、docker/Dockerfile 已在本地)
git status
# 8. 提交并推送
git add -A
git commit -m "sync local code" 2>/dev/null || true
git push origin main
```
## 推送后验证
push 触发 CI 构建,前往 Gitea 仓库 → **Actions** 查看日志;构建成功后镜像推送到 Nexus,projman 建档待部署,在 projman 应用详情「后端发布」手动点部署。
## 禁止写法(会导致注入文件被删)
`git reset origin/main` + `git add -A` 会把远程已注入、但你本地没有的文件(`build.yml`、`Dockerfile`)当作"删除"提交并推送,导致这些文件被删、CI 失败。务必用 `git merge` 而非 `git reset`,且 merge 前先提交本地代码。
## 关于 Dockerfile
projman 注入的 Dockerfile 仅在仓库不存在时写入;你自备的 Dockerfile 优先,不会被覆盖。
+1 -1
View File
@@ -85,7 +85,7 @@ function apiAxios(method, url, params, success, failure) {
.then(function (res) {
let response = res.data;
if (response.code == 302) {
window.location.href = response.urlToRedirectTo;
// window.location.href = response.urlToRedirectTo;
return;
} else if (response.code == 0) {
if (success) {
+2 -2
View File
@@ -1,8 +1,8 @@
let conf = {
baseHost: "http://base.yunhaixingtong.com",
ssoHost: "http://sso.yunhaixingtong.com",
serviceUrl: "http://base.yunhaixingtong.com/bschclass",
fileHost: "http://base.yunhaixingtong.com/bschclass",
serviceUrl: "http://base.yunhaixingtong.com/userclass",
fileHost: "http://base.yunhaixingtong.com/userclass",
isLayoutOld: false
// serviceUrl: "http://basedebug.bestsch.com/BschHome/",
};