Update brouter deploy scp to single ssh
This commit is contained in:
parent
b763d9350c
commit
6bae26de6e
1 changed files with 46 additions and 38 deletions
84
.github/workflows/cd-brouter.yml
vendored
84
.github/workflows/cd-brouter.yml
vendored
|
|
@ -64,49 +64,57 @@ jobs:
|
||||||
echo "::add-mask::$GHCR_TOKEN"
|
echo "::add-mask::$GHCR_TOKEN"
|
||||||
echo "GHCR_TOKEN=$GHCR_TOKEN" >> $GITHUB_ENV
|
echo "GHCR_TOKEN=$GHCR_TOKEN" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Copy compose project to dedicated host
|
- name: Deploy to dedicated host (single SSH connection)
|
||||||
uses: appleboy/scp-action@v1
|
# Consolidated into one SSH session on purpose: UFW on the
|
||||||
with:
|
# dedicated host rate-limits port 2232 via `LIMIT` (~6 conns /
|
||||||
host: ${{ secrets.BROUTER_DEPLOY_HOST }}
|
# 30s). `appleboy/scp-action` burns that budget across
|
||||||
username: trails
|
# scp+mkdir+untar+cleanup conns and the final cleanup times
|
||||||
port: ${{ secrets.BROUTER_DEPLOY_SSH_PORT }}
|
# out. One SSH here sidesteps the limit entirely. The tarball
|
||||||
key: ${{ secrets.BROUTER_DEPLOY_SSH_KEY }}
|
# is piped in as a base64 env var so we don't fight over
|
||||||
source: "infrastructure/brouter-host/docker-compose.yml,infrastructure/brouter-host/Caddyfile,infrastructure/brouter-host/promtail-config.yml,infrastructure/brouter-host/download-segments.sh,infrastructure/brouter-host/.env"
|
# stdin (reserved for the heredoc script).
|
||||||
target: /home/trails/brouter
|
env:
|
||||||
strip_components: 2
|
SSH_KEY: ${{ secrets.BROUTER_DEPLOY_SSH_KEY }}
|
||||||
|
HOST: ${{ secrets.BROUTER_DEPLOY_HOST }}
|
||||||
|
PORT: ${{ secrets.BROUTER_DEPLOY_SSH_PORT }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
- name: Pull image and restart containers
|
# SSH key to a locked-down file (env-var keys break openssh)
|
||||||
uses: appleboy/ssh-action@v1
|
install -m 0600 /dev/null ~/id_deploy
|
||||||
with:
|
printf '%s\n' "$SSH_KEY" > ~/id_deploy
|
||||||
host: ${{ secrets.BROUTER_DEPLOY_HOST }}
|
|
||||||
username: trails
|
|
||||||
port: ${{ secrets.BROUTER_DEPLOY_SSH_PORT }}
|
|
||||||
key: ${{ secrets.BROUTER_DEPLOY_SSH_KEY }}
|
|
||||||
envs: GHCR_TOKEN
|
|
||||||
script: |
|
|
||||||
set -euo pipefail
|
|
||||||
cd /home/trails/brouter
|
|
||||||
|
|
||||||
chmod +x download-segments.sh
|
# Bundle the compose project
|
||||||
|
TARBALL_B64=$(tar -C infrastructure/brouter-host -czf - \
|
||||||
|
docker-compose.yml Caddyfile promtail-config.yml \
|
||||||
|
download-segments.sh .env \
|
||||||
|
| base64 -w0)
|
||||||
|
|
||||||
# Segment download is explicitly NOT run here — it's
|
# One SSH session: untar, (re)start containers, report status
|
||||||
# multi-hour and idempotent. Seeding the segments directory
|
ssh -i ~/id_deploy -p "$PORT" \
|
||||||
# is a one-shot operator task (see brouter-host/README.md).
|
-o StrictHostKeyChecking=accept-new \
|
||||||
# Run `~/brouter/download-segments.sh` by hand (or via cron)
|
-o UserKnownHostsFile=/tmp/known_hosts \
|
||||||
# to refresh.
|
-o ConnectTimeout=30 \
|
||||||
if [ ! -d segments ] || [ -z "$(ls -A segments 2>/dev/null)" ]; then
|
trails@"$HOST" \
|
||||||
echo "WARNING: segments/ is empty. BRouter will start but return 404 until segments are seeded."
|
"TARBALL_B64='$TARBALL_B64' GHCR_TOKEN='$GHCR_TOKEN' bash -s" <<'REMOTE'
|
||||||
mkdir -p segments
|
set -euo pipefail
|
||||||
fi
|
mkdir -p ~/brouter && cd ~/brouter
|
||||||
|
echo "$TARBALL_B64" | base64 -d | tar -xzf -
|
||||||
|
chmod +x download-segments.sh
|
||||||
|
|
||||||
# GHCR images (brouter) are private; log in so pull works.
|
# Segment seeding is a one-shot operator task (~10 GB, a few
|
||||||
# Credentials stay in ~/.docker/config.json; acceptable on a
|
# minutes). CD must not rerun it on every deploy.
|
||||||
# single-tenant trails user.
|
if [ ! -d segments ] || [ -z "$(ls -A segments 2>/dev/null)" ]; then
|
||||||
echo "$GHCR_TOKEN" | docker login ghcr.io -u stigi --password-stdin
|
echo "WARNING: segments/ is empty. BRouter will start but return 404 until segments are seeded."
|
||||||
|
mkdir -p segments
|
||||||
|
fi
|
||||||
|
|
||||||
docker compose pull
|
# GHCR brouter image is private; log in so pull works.
|
||||||
docker compose up -d --remove-orphans
|
echo "$GHCR_TOKEN" | docker login ghcr.io -u stigi --password-stdin
|
||||||
docker compose ps
|
|
||||||
|
docker compose pull
|
||||||
|
docker compose up -d --remove-orphans
|
||||||
|
docker compose ps
|
||||||
|
REMOTE
|
||||||
|
|
||||||
- name: Annotate deploy in flagship Grafana
|
- name: Annotate deploy in flagship Grafana
|
||||||
uses: appleboy/ssh-action@v1
|
uses: appleboy/ssh-action@v1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue