fix: publish backend images through Harbor
This commit is contained in:
+25
-14
@@ -5,10 +5,12 @@ TAG="${1:?Usage: deploy.sh TAG [--build-only]}"
|
||||
MODE="${2:-}"
|
||||
[[ "$TAG" =~ ^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,100}$ ]] || { echo 'Invalid release tag' >&2; exit 1; }
|
||||
[[ -z "$MODE" || "$MODE" == '--build-only' ]] || { echo 'Unknown mode' >&2; exit 1; }
|
||||
BASE_DIR=/www/wwwroot/sw2.fuhua91.com
|
||||
BASE_DIR="${SW_DEPLOY_BASE:-/www/wwwroot/sw2.fuhua91.com}"
|
||||
RELEASE="$BASE_DIR/releases/$TAG"
|
||||
BACKEND_IMAGE="sw2/backend:$TAG"
|
||||
FRONTEND_IMAGE="harbor.fuhua91.com/game/sw2:$TAG"
|
||||
BACKEND_REPOSITORY=harbor.fuhua91.com/game/sw2-backend
|
||||
FRONTEND_REPOSITORY=harbor.fuhua91.com/game/sw2
|
||||
BACKEND_IMAGE="$BACKEND_REPOSITORY:$TAG"
|
||||
FRONTEND_IMAGE="$FRONTEND_REPOSITORY:$TAG"
|
||||
NETWORK=sw2-net
|
||||
NAMES=(sw2-backend sw2-frontend)
|
||||
|
||||
@@ -19,17 +21,26 @@ test -f "$RELEASE/frontend/Dockerfile"
|
||||
|
||||
docker build --build-arg "VERSION=$TAG" -t "$BACKEND_IMAGE" "$RELEASE/backend"
|
||||
docker build --build-arg "VERSION=$TAG" -t "$FRONTEND_IMAGE" "$RELEASE/frontend"
|
||||
registry_args=()
|
||||
if [[ -s "$BASE_DIR/harbor-docker/config.json" ]]; then registry_args=(--config "$BASE_DIR/harbor-docker"); fi
|
||||
docker "${registry_args[@]}" push "$FRONTEND_IMAGE"
|
||||
docker "${registry_args[@]}" pull "$FRONTEND_IMAGE"
|
||||
frontend_digests=$(docker inspect --format '{{range .RepoDigests}}{{println .}}{{end}}' "$FRONTEND_IMAGE")
|
||||
frontend_ref=''
|
||||
while IFS= read -r reference; do
|
||||
if [[ "$reference" == 'harbor.fuhua91.com/game/sw2@sha256:'* && "${reference##*@}" =~ ^sha256:[a-f0-9]{64}$ ]]; then frontend_ref="$reference"; break; fi
|
||||
done <<< "$frontend_digests"
|
||||
[[ -n "$frontend_ref" ]] || { echo 'Harbor frontend digest is missing' >&2; exit 1; }
|
||||
FRONTEND_IMAGE="$frontend_ref"
|
||||
if [[ -s "$BASE_DIR/harbor-docker/config.json" ]]; then export DOCKER_CONFIG="$BASE_DIR/harbor-docker"; fi
|
||||
publish_image() {
|
||||
local repository=$1
|
||||
local image="$repository:$TAG"
|
||||
local digests reference
|
||||
# Explicitly propagate failures inside command substitutions on Bash 4.2.
|
||||
docker push "$image" >&2 || return 1
|
||||
docker pull "$image" >&2 || return 1
|
||||
digests=$(docker inspect --format '{{range .RepoDigests}}{{println .}}{{end}}' "$image") || return 1
|
||||
while IFS= read -r reference; do
|
||||
if [[ "$reference" == "$repository@sha256:"* && "${reference##*@}" =~ ^sha256:[a-f0-9]{64}$ ]]; then
|
||||
printf '%s\n' "$reference"
|
||||
return 0
|
||||
fi
|
||||
done <<< "$digests"
|
||||
echo "Harbor image digest is missing: $image" >&2
|
||||
return 1
|
||||
}
|
||||
BACKEND_IMAGE=$(publish_image "$BACKEND_REPOSITORY")
|
||||
FRONTEND_IMAGE=$(publish_image "$FRONTEND_REPOSITORY")
|
||||
docker run --rm "$BACKEND_IMAGE" /app/kratos-admin -h >/dev/null
|
||||
docker run --rm --add-host sw2-backend:127.0.0.1 "$FRONTEND_IMAGE" nginx -t
|
||||
if [[ "$MODE" == '--build-only' ]]; then exit 0; fi
|
||||
|
||||
Reference in New Issue
Block a user