ci(deploy): enable containerized production release
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Post-receive hook: push 后自动构建 Docker 镜像并重启容器
|
||||
|
||||
# pnpm / node 环境仍保留,便于服务器缺少 Docker 时做人工排查。
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||
|
||||
REPO_TOPLEVEL=""
|
||||
LOG_FILE=""
|
||||
CURRENT_BRANCH=""
|
||||
@@ -133,42 +128,8 @@ run_container_build() {
|
||||
return $COMPOSE_EXIT
|
||||
}
|
||||
|
||||
find_port_pids() {
|
||||
if ! command -v ss >/dev/null 2>&1; then
|
||||
echo "=== ss command not found; cannot inspect legacy port $START_PORT ===" >> "$LOG_FILE"
|
||||
return 0
|
||||
fi
|
||||
|
||||
ss -tulnp 2>/dev/null \
|
||||
| awk -v port=":$START_PORT" '$5 ~ port "$" { print }' \
|
||||
| sed -n 's/.*pid=\([0-9][0-9]*\).*/\1/p' \
|
||||
| sort -u
|
||||
}
|
||||
|
||||
container_exists() {
|
||||
docker ps -a --format '{{.Names}}' 2>/dev/null | grep -Fx "$CONTAINER_NAME" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
stop_legacy_next_if_needed() {
|
||||
if container_exists; then
|
||||
echo "=== existing container found; skip legacy port cleanup ===" >> "$LOG_FILE"
|
||||
return 0
|
||||
fi
|
||||
|
||||
PIDS="$(find_port_pids)"
|
||||
if [ -z "$PIDS" ]; then
|
||||
echo "=== no legacy process found on port $START_PORT ===" >> "$LOG_FILE"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "=== first container deploy: kill legacy PIDS on port $START_PORT: $PIDS ===" >> "$LOG_FILE"
|
||||
kill -9 $PIDS 2>/dev/null || true
|
||||
sleep 3
|
||||
}
|
||||
|
||||
launch_container() {
|
||||
echo "=== docker compose up START @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
||||
stop_legacy_next_if_needed
|
||||
docker_compose up -d --remove-orphans web >> "$LOG_FILE" 2>&1
|
||||
COMPOSE_EXIT=$?
|
||||
echo "=== docker compose up EXIT_CODE=$COMPOSE_EXIT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
||||
|
||||
Reference in New Issue
Block a user