部署
This commit is contained in:
parent
292177e7ff
commit
17dc45fdfd
@ -48,7 +48,10 @@ ensure_base_image() {
|
|||||||
if docker image inspect "$BASE_IMAGE" >/dev/null 2>&1; then
|
if docker image inspect "$BASE_IMAGE" >/dev/null 2>&1; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
log "base image not cached, pulling $FALLBACK_BASE_IMAGE"
|
if docker pull "$BASE_IMAGE"; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
log "base image not available from primary registry, pulling $FALLBACK_BASE_IMAGE"
|
||||||
docker pull "$FALLBACK_BASE_IMAGE"
|
docker pull "$FALLBACK_BASE_IMAGE"
|
||||||
docker tag "$FALLBACK_BASE_IMAGE" "$BASE_IMAGE"
|
docker tag "$FALLBACK_BASE_IMAGE" "$BASE_IMAGE"
|
||||||
}
|
}
|
||||||
@ -139,6 +142,7 @@ build_service() {
|
|||||||
rollout "$svc" "$image"
|
rollout "$svc" "$image"
|
||||||
;;
|
;;
|
||||||
preload)
|
preload)
|
||||||
|
ensure_preload_pull_policy "$svc"
|
||||||
preload_image_to_nodes "$svc" "$image"
|
preload_image_to_nodes "$svc" "$image"
|
||||||
rollout "$svc" "$image"
|
rollout "$svc" "$image"
|
||||||
;;
|
;;
|
||||||
@ -182,6 +186,18 @@ preload_image_to_nodes() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_preload_pull_policy() {
|
||||||
|
local svc="$1"
|
||||||
|
local policy
|
||||||
|
policy="$(kubectl --kubeconfig "$KUBECONFIG" -n "$NAMESPACE" get "deployment/$svc" \
|
||||||
|
-o "jsonpath={.spec.template.spec.containers[?(@.name=='$svc')].imagePullPolicy}")"
|
||||||
|
# Preload mode imports images into node containerd; Always-pull pods would bypass that cache and fail.
|
||||||
|
if [[ "$policy" == "Always" ]]; then
|
||||||
|
echo "deployment/$svc uses imagePullPolicy=Always; preload mode requires IfNotPresent or unset" >&2
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
preload_image_to_node() {
|
preload_image_to_node() {
|
||||||
local svc="$1"
|
local svc="$1"
|
||||||
local image="$2"
|
local image="$2"
|
||||||
@ -275,17 +291,19 @@ main() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ "${1:-}" == "status" || "$MODE" == "status" ]]; then
|
||||||
|
need_cmd kubectl
|
||||||
|
[[ -f "$KUBECONFIG" ]] || { echo "missing kubeconfig: $KUBECONFIG" >&2; exit 2; }
|
||||||
|
status
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
need_cmd java
|
need_cmd java
|
||||||
need_cmd mvn
|
need_cmd mvn
|
||||||
need_cmd docker
|
need_cmd docker
|
||||||
need_cmd kubectl
|
need_cmd kubectl
|
||||||
[[ -f "$KUBECONFIG" ]] || { echo "missing kubeconfig: $KUBECONFIG" >&2; exit 2; }
|
[[ -f "$KUBECONFIG" ]] || { echo "missing kubeconfig: $KUBECONFIG" >&2; exit 2; }
|
||||||
|
|
||||||
if [[ "${1:-}" == "status" || "$MODE" == "status" ]]; then
|
|
||||||
status
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
update_source_from_git
|
update_source_from_git
|
||||||
|
|
||||||
local services=("$@")
|
local services=("$@")
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
DEPLOY_HOST="${DEPLOY_HOST:-43.160.245.220}"
|
DEPLOY_HOST="${DEPLOY_HOST:-43.160.219.15}"
|
||||||
DEPLOY_USER="${DEPLOY_USER:-ubuntu}"
|
DEPLOY_USER="${DEPLOY_USER:-ubuntu}"
|
||||||
SSH_KEY="${SSH_KEY:-$HOME/.ssh/aslan-deploy-sg-ed25519}"
|
SSH_KEY="${SSH_KEY:-$HOME/.ssh/aslan-deploy-sg-ed25519}"
|
||||||
REMOTE_BASE="${REMOTE_BASE:-/opt/aslan-deploy}"
|
REMOTE_BASE="${REMOTE_BASE:-/opt/aslan-deploy}"
|
||||||
@ -23,12 +23,12 @@ Examples:
|
|||||||
.deploy/aslan-deploy/sync-and-deploy.sh --mode preload other external console
|
.deploy/aslan-deploy/sync-and-deploy.sh --mode preload other external console
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
DEPLOY_HOST default 43.160.245.220
|
DEPLOY_HOST default 43.160.219.15
|
||||||
DEPLOY_USER default ubuntu
|
DEPLOY_USER default ubuntu
|
||||||
SSH_KEY default ~/.ssh/aslan-deploy-sg-ed25519
|
SSH_KEY default ~/.ssh/aslan-deploy-sg-ed25519
|
||||||
|
|
||||||
Git source on deploy host:
|
Git source on deploy host:
|
||||||
ssh -i ~/.ssh/aslan-deploy-sg-ed25519 ubuntu@43.160.245.220 \
|
ssh -i ~/.ssh/aslan-deploy-sg-ed25519 ubuntu@43.160.219.15 \
|
||||||
'USE_GIT_SOURCE=1 GIT_REF=atyou_prod /opt/aslan-deploy/deploy-likei-services.sh --mode preload other'
|
'USE_GIT_SOURCE=1 GIT_REF=atyou_prod /opt/aslan-deploy/deploy-likei-services.sh --mode preload other'
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@ -72,5 +72,9 @@ for cache_group in $M2_CACHE_GROUPS; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
printf -v remote_script_q '%q' "$REMOTE_BASE/deploy-likei-services.sh"
|
printf -v remote_script_q '%q' "$REMOTE_BASE/deploy-likei-services.sh"
|
||||||
|
remote_cmd="$remote_script_q"
|
||||||
|
if [[ "$#" -gt 0 ]]; then
|
||||||
printf -v remote_args_q ' %q' "$@"
|
printf -v remote_args_q ' %q' "$@"
|
||||||
"${ssh_base[@]}" "chmod +x $remote_script_q && $remote_script_q $remote_args_q"
|
remote_cmd+="$remote_args_q"
|
||||||
|
fi
|
||||||
|
"${ssh_base[@]}" "chmod +x $remote_script_q && $remote_cmd"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user