deploy: SSH roll to linuxuser@elektrine.com with shared Docker network
Add scripts/deploy.sh to build/start Magpie and ensure it joins elektrine-magpie-shared (alias magpie) so Elektrine can reach magpie:8090. Forgejo Actions rsyncs and runs the script on every main push.
This commit is contained in:
parent
9cd56a7770
commit
aa43ce2562
3 changed files with 164 additions and 0 deletions
61
scripts/deploy.sh
Executable file
61
scripts/deploy.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
# Deploy Magpie on the same host as Elektrine and join the shared Docker network
|
||||
# so app/worker/caddy can reach http://magpie:8090.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
NETWORK_NAME="${MAGPIE_DOCKER_NETWORK:-elektrine-magpie-shared}"
|
||||
CONTAINER_NAME="${MAGPIE_CONTAINER_NAME:-magpie}"
|
||||
COMPOSE_FILES=(-f docker-compose.yml -f docker-compose.network.yml)
|
||||
|
||||
if docker info >/dev/null 2>&1; then
|
||||
DOCKER=(docker)
|
||||
elif sudo -n docker info >/dev/null 2>&1; then
|
||||
DOCKER=(sudo -n docker)
|
||||
else
|
||||
echo "No docker access (need docker group or passwordless sudo docker)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f .env.production ]]; then
|
||||
echo "Missing $ROOT_DIR/.env.production" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export MAGPIE_DOCKER_NETWORK="$NETWORK_NAME"
|
||||
|
||||
echo "Info: ensuring shared network $NETWORK_NAME" >&2
|
||||
"${DOCKER[@]}" network inspect "$NETWORK_NAME" >/dev/null 2>&1 \
|
||||
|| "${DOCKER[@]}" network create "$NETWORK_NAME" >/dev/null
|
||||
|
||||
echo "Info: building and starting Magpie" >&2
|
||||
"${DOCKER[@]}" compose "${COMPOSE_FILES[@]}" build
|
||||
"${DOCKER[@]}" compose "${COMPOSE_FILES[@]}" up -d --force-recreate --remove-orphans
|
||||
|
||||
# Compose should attach via docker-compose.network.yml; re-connect with alias if needed
|
||||
# (force-recreate can drop a manually-connected endpoint).
|
||||
attached="$("${DOCKER[@]}" inspect "$CONTAINER_NAME" --format \
|
||||
"{{if index .NetworkSettings.Networks \"$NETWORK_NAME\"}}yes{{end}}" 2>/dev/null || true)"
|
||||
if [[ "$attached" != "yes" ]]; then
|
||||
echo "Info: connecting $CONTAINER_NAME to $NETWORK_NAME as alias magpie" >&2
|
||||
"${DOCKER[@]}" network connect --alias magpie "$NETWORK_NAME" "$CONTAINER_NAME"
|
||||
else
|
||||
# Ensure the magpie DNS alias exists (network connect --alias is idempotent only if already set)
|
||||
echo "Info: $CONTAINER_NAME already on $NETWORK_NAME" >&2
|
||||
fi
|
||||
|
||||
echo "Info: Magpie status" >&2
|
||||
"${DOCKER[@]}" compose "${COMPOSE_FILES[@]}" ps
|
||||
"${DOCKER[@]}" inspect "$CONTAINER_NAME" --format \
|
||||
'networks={{range $k,$v := .NetworkSettings.Networks}}{{$k}}({{join $v.Aliases ","}}) {{end}}'
|
||||
|
||||
# Quick health: S3 endpoint listens on loopback
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
if curl -sf -o /dev/null --max-time 3 "http://127.0.0.1:8090/" || true; then
|
||||
echo "Info: Magpie is listening on 127.0.0.1:8090" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "DEPLOY_OK"
|
||||
Loading…
Add table
Add a link
Reference in a new issue