fix: 统一前端Harbor镜像发布与拉取部署
This commit is contained in:
+43
-10
@@ -17,6 +17,11 @@ case "$command" in
|
||||
inspect)
|
||||
format=''
|
||||
if [[ "$1" == --format ]]; then format=$2; shift 2; fi
|
||||
if [[ "$format" == *RepoDigests* ]]; then
|
||||
[[ "$1" == harbor.fuhua91.com/game/sw2:new ]] || exit 1
|
||||
if [[ "$TEST_MODE" != digest-missing ]]; then printf 'harbor.fuhua91.com/game/sw2@sha256:%064d\n' 1; fi
|
||||
exit 0
|
||||
fi
|
||||
[[ -d "$TEST_STATE/$1" ]] || exit 1
|
||||
case "$format" in
|
||||
*com.sw2.application*) cat "$TEST_STATE/$1/app" ;;
|
||||
@@ -24,6 +29,8 @@ case "$command" in
|
||||
*State.Running*) cat "$TEST_STATE/$1/running" ;;
|
||||
esac ;;
|
||||
network|build) exit 0 ;;
|
||||
push) [[ "$TEST_MODE" != push-fail ]] ;;
|
||||
pull) [[ "$TEST_MODE" != pull-fail ]] ;;
|
||||
run)
|
||||
name=''; version='new'
|
||||
while (($#)); do
|
||||
@@ -60,14 +67,17 @@ chmod +x "$TEST_ROOT/bin/"*
|
||||
export PATH="$TEST_ROOT/bin:$PATH"
|
||||
export SW_HEALTH_ATTEMPTS=1
|
||||
|
||||
for scenario in success preflight-fail final-fail build-only unmanaged; do
|
||||
for scenario in success preflight-fail final-fail build-only pull-only pull-preflight push-fail pull-fail digest-missing unmanaged; do
|
||||
export TEST_STATE="$TEST_ROOT/$scenario"
|
||||
export TEST_MODE="$scenario"
|
||||
export SW_DEPLOY_BASE="$TEST_STATE/base"
|
||||
mkdir -p "$SW_DEPLOY_BASE/frontend-releases/new/dist" "$TEST_STATE/sw2-frontend" "$TEST_STATE/sw2-backend"
|
||||
cp "$SCRIPT" "$SW_DEPLOY_BASE/frontend-releases/new/deploy.sh"
|
||||
printf '<html>test</html>' > "$SW_DEPLOY_BASE/frontend-releases/new/dist/index.html"
|
||||
printf 'new\n' > "$SW_DEPLOY_BASE/frontend-releases/new/dist/version.txt"
|
||||
mkdir -p "$SW_DEPLOY_BASE" "$TEST_STATE/sw2-frontend" "$TEST_STATE/sw2-backend"
|
||||
if [[ "$scenario" != pull-only && "$scenario" != pull-preflight ]]; then
|
||||
mkdir -p "$SW_DEPLOY_BASE/frontend-releases/new/dist"
|
||||
cp "$SCRIPT" "$SW_DEPLOY_BASE/frontend-releases/new/deploy.sh"
|
||||
printf '<html>test</html>' > "$SW_DEPLOY_BASE/frontend-releases/new/dist/index.html"
|
||||
printf 'new\n' > "$SW_DEPLOY_BASE/frontend-releases/new/dist/version.txt"
|
||||
fi
|
||||
printf 'old\n' > "$SW_DEPLOY_BASE/current-frontend-release"
|
||||
printf 'sw2' > "$TEST_STATE/sw2-frontend/app"
|
||||
printf 'old' > "$TEST_STATE/sw2-frontend/version"
|
||||
@@ -75,14 +85,21 @@ for scenario in success preflight-fail final-fail build-only unmanaged; do
|
||||
printf 'old-container' > "$TEST_STATE/sw2-frontend/id"
|
||||
printf 'backend-unchanged' > "$TEST_STATE/sw2-backend/id"
|
||||
if [[ "$scenario" == unmanaged ]]; then printf 'other' > "$TEST_STATE/sw2-frontend/app"; fi
|
||||
mode=''; [[ "$scenario" != build-only ]] || mode='--build-only'
|
||||
result=0
|
||||
bash "$SW_DEPLOY_BASE/frontend-releases/new/deploy.sh" new "$mode" > "$TEST_STATE/output" 2>&1 || result=$?
|
||||
modes=()
|
||||
case "$scenario" in
|
||||
success)
|
||||
build-only) modes=(--build-only) ;;
|
||||
pull-only) modes=(--pull-only) ;;
|
||||
pull-preflight) modes=(--pull-only --build-only) ;;
|
||||
esac
|
||||
result=0
|
||||
entry="$SW_DEPLOY_BASE/frontend-releases/new/deploy.sh"
|
||||
if [[ "$scenario" == pull-only || "$scenario" == pull-preflight ]]; then entry="$SCRIPT"; fi
|
||||
bash "$entry" new "${modes[@]}" > "$TEST_STATE/output" 2>&1 || result=$?
|
||||
case "$scenario" in
|
||||
success|pull-only)
|
||||
[[ "$result" == 0 && "$(cat "$TEST_STATE/sw2-frontend/id")" == new-container && "$(cat "$TEST_STATE/sw2-frontend-previous/id")" == old-container ]]
|
||||
[[ "$(cat "$SW_DEPLOY_BASE/current-frontend-release")" == new ]] ;;
|
||||
build-only)
|
||||
build-only|pull-preflight)
|
||||
[[ "$result" == 0 && "$(cat "$TEST_STATE/sw2-frontend/id")" == old-container ]]
|
||||
[[ "$(cat "$SW_DEPLOY_BASE/current-frontend-release")" == old ]] ;;
|
||||
*)
|
||||
@@ -91,6 +108,22 @@ for scenario in success preflight-fail final-fail build-only unmanaged; do
|
||||
esac
|
||||
[[ "$(cat "$TEST_STATE/sw2-backend/id")" == backend-unchanged ]]
|
||||
! grep -E '(stop|start|rename|rm|run).*sw2-backend' "$TEST_STATE/calls"
|
||||
! grep -F 'sw2/frontend:' "$TEST_STATE/calls"
|
||||
if [[ "$scenario" == success || "$scenario" == build-only ]]; then
|
||||
grep -q '^push harbor.fuhua91.com/game/sw2:new$' "$TEST_STATE/calls"
|
||||
grep -q '^pull harbor.fuhua91.com/game/sw2:new$' "$TEST_STATE/calls"
|
||||
fi
|
||||
if [[ "$scenario" == pull-only || "$scenario" == pull-preflight ]]; then
|
||||
! grep -E '^(build|push) ' "$TEST_STATE/calls"
|
||||
grep -q '^pull harbor.fuhua91.com/game/sw2:new$' "$TEST_STATE/calls"
|
||||
fi
|
||||
if [[ "$scenario" == success || "$scenario" == pull-only ]]; then
|
||||
grep -q 'harbor.fuhua91.com/game/sw2@sha256:' "$TEST_STATE/calls"
|
||||
grep -q '^harbor.fuhua91.com/game/sw2@sha256:' "$SW_DEPLOY_BASE/frontend-images/new.ref"
|
||||
fi
|
||||
if [[ "$scenario" == push-fail || "$scenario" == pull-fail || "$scenario" == digest-missing ]]; then
|
||||
! grep -E '^(stop|rename) ' "$TEST_STATE/calls"
|
||||
fi
|
||||
[[ "$(find "$TEST_STATE" -maxdepth 1 -name 'sw2-frontend-candidate-*' | wc -l)" == 0 ]]
|
||||
done
|
||||
echo 'all deployment scenarios passed'
|
||||
|
||||
Reference in New Issue
Block a user