diff --git a/.gitignore b/.gitignore index 8a6a2a7f2..4bd7fe08c 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ __pycache__/ /archipelago .agents-run/ /.pnpm-store/ +deployments/archie/.build/ diff --git a/deployments/archie/compose.yml b/deployments/archie/compose.yml new file mode 100644 index 000000000..2be697b3e --- /dev/null +++ b/deployments/archie/compose.yml @@ -0,0 +1,37 @@ +name: archie + +services: + archie-db: + image: postgres:18-alpine + restart: unless-stopped + environment: + POSTGRES_DB: archie + POSTGRES_USER: archie_owner + POSTGRES_PASSWORD: ${ARCHIE_OWNER_PASSWORD:?} + ARCHIE_APP_PASSWORD: ${ARCHIE_APP_PASSWORD:?} + volumes: + - ./postgres:/var/lib/postgresql + - ./initdb:/docker-entrypoint-initdb.d:ro + networks: [internal] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U archie_owner -d archie"] + interval: 5s + timeout: 3s + retries: 20 + + archie: + image: gcr.io/distroless/static-debian12:nonroot + restart: unless-stopped + command: ["/archie/archie", "-config", "/archie/config.toml"] + volumes: + - ./bin/archie:/archie/archie:ro + - ./config.toml:/archie/config.toml:ro + ports: + - "${ARCHIE_BIND:?}:8080" + networks: [internal] + depends_on: + archie-db: + condition: service_healthy + +networks: + internal: {} diff --git a/deployments/archie/deploy.sh b/deployments/archie/deploy.sh new file mode 100755 index 000000000..86806b1a6 --- /dev/null +++ b/deployments/archie/deploy.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Deploys the single binary's stack to a host over ssh: deploy.sh root@nebula. +# The first run creates the secrets on the host; they never leave it. +set -euo pipefail + +target=${1:?usage: deploy.sh user@host [bind-address:port]} +bind=${2:-} +here=$(cd "$(dirname "$0")" && pwd) +repo=$(cd "$here/../.." && pwd) +dir=/root/archie + +version=$(git -C "$repo" describe --tags --always --dirty) +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C "$repo" -trimpath \ + -ldflags "-X github.com/samcharles93/archie-core/internal/buildinfo.Version=$version" \ + -o "$here/.build/archie" ./cmd/archie + +ssh "$target" "mkdir -p $dir/bin $dir/initdb" +scp -q "$here/compose.yml" "$target:$dir/compose.yml" +scp -q "$here/initdb/01-roles.sh" "$target:$dir/initdb/01-roles.sh" +scp -q "$here/.build/archie" "$target:$dir/bin/archie.new" + +ssh "$target" BIND="$bind" DIR="$dir" bash -s <<'REMOTE' +set -euo pipefail +cd "$DIR" +chmod 755 initdb/01-roles.sh +mv bin/archie.new bin/archie && chmod 755 bin/archie +if [ ! -f .env ]; then + [ -n "$BIND" ] || { echo "first deploy needs a bind address, e.g. 10.0.0.1:8099" >&2; exit 1; } + umask 077 + printf 'ARCHIE_OWNER_PASSWORD=%s\nARCHIE_APP_PASSWORD=%s\nARCHIE_BIND=%s\n' \ + "$(openssl rand -hex 24)" "$(openssl rand -hex 24)" "$BIND" > .env +fi +if [ ! -f config.toml ]; then + set -a; . ./.env; set +a + umask 077 + cat > config.toml <