chore(devops): CD — every merge into dev deploys dev.meditron.tenvex.ru
CI / ruff · pytest (pull_request) Successful in 2m24s
CI / ruff · pytest (pull_request) Successful in 2m24s
Gitea Actions: lint + tests, then infra/deploy/deploy.sh over ssh as the dedicated ptsr-deploy user (secrets DEPLOY_SSH_KEY, DEPLOY_HOST), then an HTTPS smoke check. deploy.sh now ships a tar.gz via scp and retries every remote step (the host drops some ssh connections); the web build runs as the deploy user so the next release can clean up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+19
-6
@@ -1,24 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# Deploy origin/dev to the shared server (ssh alias `vobot`, dir /srv/ptsr). Run from a clean checkout:
|
||||
# Deploy a git ref to the shared server (dir /srv/ptsr). Used by hand and by CD (.gitea/workflows/deploy.yml).
|
||||
# infra/deploy/deploy.sh [git-ref] default: origin/dev
|
||||
# Env: DEPLOY_HOST (ssh host/alias, default `vobot`), DEPLOY_SSH_OPTS (extra ssh/scp options).
|
||||
# Keeps /srv/ptsr/.env (secrets live only on the server) and the Postgres volume.
|
||||
# The host drops some ssh connections (rate limiting) — every remote step is retried.
|
||||
set -euo pipefail
|
||||
REF=${1:-origin/dev}
|
||||
HOST=${DEPLOY_HOST:-vobot}
|
||||
OPTS=${DEPLOY_SSH_OPTS:-}
|
||||
DIR=/srv/ptsr
|
||||
git fetch -q origin || true
|
||||
git fetch -q origin 2>/dev/null || true
|
||||
SHA=$(git rev-parse --short "$REF")
|
||||
TGZ=$(mktemp --suffix=.tgz)
|
||||
trap 'rm -f "$TGZ"' EXIT
|
||||
git archive --format=tar.gz -o "$TGZ" "$REF"
|
||||
|
||||
retry() { local n=0; until "$@"; do n=$((n + 1)); [ $n -ge 5 ] && return 1; echo "retry $n: $1" >&2; sleep $((n * 10)); done; }
|
||||
|
||||
echo "deploy $REF ($SHA) -> $HOST:$DIR"
|
||||
git archive --format=tar "$REF" | ssh "$HOST" "rm -rf $DIR/app.new && mkdir -p $DIR/app.new && tar -x -C $DIR/app.new"
|
||||
ssh "$HOST" bash -s <<SH
|
||||
# shellcheck disable=SC2086
|
||||
retry scp -q $OPTS "$TGZ" "$HOST:$DIR/release.tgz"
|
||||
# shellcheck disable=SC2086
|
||||
retry ssh $OPTS "$HOST" "bash -s" <<SH
|
||||
set -euo pipefail
|
||||
cd $DIR
|
||||
rm -rf app.new && mkdir app.new && tar -xzf release.tgz -C app.new && rm -f release.tgz
|
||||
cp .env app.new/.env
|
||||
rm -rf app.old; [ -d app ] && mv app app.old; mv app.new app
|
||||
chmod 755 $DIR
|
||||
cd app
|
||||
echo "$SHA" > REVISION
|
||||
docker run --rm -v "\$PWD/web:/w" -w /w node:20-alpine sh -c "npm ci --no-audit --no-fund >/dev/null && npm run build >/dev/null"
|
||||
docker run --rm --user "\$(id -u):\$(id -g)" -e HOME=/tmp -e npm_config_cache=/tmp/.npm -v "\$PWD/web:/w" -w /w node:20-alpine sh -c "npm ci --no-audit --no-fund >/dev/null && npm run build >/dev/null"
|
||||
docker compose -p ptsr -f docker-compose.yml -f infra/deploy/docker-compose.server.yml up -d --build </dev/null
|
||||
for i in \$(seq 1 40); do curl -sf 127.0.0.1:8010/health >/dev/null && break; sleep 3; done
|
||||
curl -sf 127.0.0.1:8010/health && echo " api ok"
|
||||
curl -sf 127.0.0.1:8010/health >/dev/null && echo "api ok @ $SHA"
|
||||
SH
|
||||
|
||||
Reference in New Issue
Block a user