Build the frontend once per pipeline and reuse it in the dev backend image [CI]
This commit is contained in:
1 parent
3654d37da5
commit
d1ece67a6a
5 files changed
+82
-6
No files matched your search
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
# 同一条流水线里,前端只构建一次:web-build workflow 构建完把 dist 放到流水线的共享目录,开发镜像的 Backend 步骤直接拿来用。
|
||||
# 用法:
|
||||
# shared-web.sh publish 把 web/display/dist 和 web/admin/dist 放进共享目录(先写临时目录,最后用一次 rename 加上 ready 标记)
|
||||
# shared-web.sh fetch 等 ready 标记出现(最多 MOSHIRO_SHARED_WEB_WAIT 秒,默认 600),再复制回工作区;
|
||||
# 退出码 0 = 已复制,1 = 没等到或流水线已经失败(调用方自己构建兜底)
|
||||
# 共享目录和 ci/guard-step.py 用的是同一个:${MOSHIRO_CI_STATE}/${CI_REPO_ID}-${CI_PIPELINE_NUMBER}。
|
||||
set -euo pipefail
|
||||
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
state="${MOSHIRO_CI_STATE:-/home/justme/woodpecker/cache/pipeline-state}/${CI_REPO_ID:-0}-${CI_PIPELINE_NUMBER:-0}"
|
||||
shared="$state/web-dist"
|
||||
apps=(display admin)
|
||||
|
||||
case "${1:-}" in
|
||||
publish)
|
||||
mkdir -p "$state"
|
||||
tmp="$state/web-dist.tmp.$$"
|
||||
rm -rf "$tmp" "$shared"
|
||||
for app in "${apps[@]}"; do
|
||||
[[ -f "$root/web/$app/dist/index.html" ]] || { echo "web/$app/dist is missing" >&2; exit 1; }
|
||||
mkdir -p "$tmp/$app"
|
||||
cp -a "$root/web/$app/dist/." "$tmp/$app/"
|
||||
done
|
||||
mv "$tmp" "$shared"
|
||||
;;
|
||||
fetch)
|
||||
deadline=$((SECONDS + ${MOSHIRO_SHARED_WEB_WAIT:-600}))
|
||||
until [[ -f "$shared/display/index.html" && -f "$shared/admin/index.html" ]]; do
|
||||
if [[ -e "$state/failed" ]]; then echo "the pipeline already failed; no shared web build" >&2; exit 1; fi
|
||||
if ((SECONDS >= deadline)); then echo "the shared web build did not appear in time" >&2; exit 1; fi
|
||||
sleep 2
|
||||
done
|
||||
for app in "${apps[@]}"; do
|
||||
rm -rf "$root/web/$app/dist"
|
||||
mkdir -p "$root/web/$app/dist"
|
||||
cp -a "$shared/$app/." "$root/web/$app/dist/"
|
||||
done
|
||||
;;
|
||||
*)
|
||||
echo "usage: shared-web.sh publish|fetch" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
Reference in new issue
Block a user