chore(deploy): staging stack for the single binary on nebula (#1998)
This commit is contained in:
4 files changed
+94
No files matched your search
@@ -50,3 +50,4 @@ __pycache__/
|
|||||||
/archipelago
|
/archipelago
|
||||||
.agents-run/
|
.agents-run/
|
||||||
/.pnpm-store/
|
/.pnpm-store/
|
||||||
|
deployments/archie/.build/
|
||||||
@@ -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: {}
|
||||||
Executable
+47
@@ -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 <<CONFIG
|
||||||
|
listen = "0.0.0.0:8080"
|
||||||
|
[database]
|
||||||
|
url = "postgres://archie_app:${ARCHIE_APP_PASSWORD}@archie-db:5432/archie?sslmode=disable"
|
||||||
|
owner_url = "postgres://archie_owner:${ARCHIE_OWNER_PASSWORD}@archie-db:5432/archie?sslmode=disable"
|
||||||
|
CONFIG
|
||||||
|
chown 65532:65532 config.toml
|
||||||
|
fi
|
||||||
|
docker compose up -d --remove-orphans
|
||||||
|
docker compose restart archie
|
||||||
|
REMOTE
|
||||||
|
echo "deployed $version to $target"
|
||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Runs once, on an empty data directory. The owner (POSTGRES_USER) runs
|
||||||
|
# migrations; archie_app is the runtime role and holds no DDL rights.
|
||||||
|
set -eu
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" \
|
||||||
|
-v app_password="$ARCHIE_APP_PASSWORD" <<'SQL'
|
||||||
|
CREATE ROLE archie_app LOGIN PASSWORD :'app_password';
|
||||||
|
GRANT CONNECT ON DATABASE archie TO archie_app;
|
||||||
|
SQL
|
||||||
Reference in new issue
Block a user