The relay image is ghcr.io/block/buzz:main with autoUpdate and BUZZ_AUTO_MIGRATE=true. On 2026-11-02 an auto-update pulled a newer build whose migrations include 0078_artifact_sync_indexes.sql. That migration refuses to create its four indexes inline once the target table is populated -- it raises "prebuild <index> concurrently" and points at docs/artifact-sync-deployment.md. channel_members is populated on a live relay, so migration 78 aborts, the relay exits 1 and has been crash-looping ever since. The schema sits at 0077, so every earlier migration (including 0077_artifact_sync_timestamps) is applied; rolling the image back is not an option because sqlx rejects a schema that is ahead of the binary's known migrations. Fix the gate instead of the image: a one-shot compose service, relay-index-prebuild, runs on the postgres image after postgres reports healthy and builds the four indexes CONCURRENTLY. Each index is checked first -- missing, valid, or invalid (present but not indisvalid/indisready/indislive); an invalid leftover is dropped concurrently before the rebuild, and an already-valid index is left alone, so re-runs are cheap and safe. The relay now waits on relay-index-prebuild completing successfully, next to its existing postgres/redis/minio/minio-init conditions. Authored by hermenix.
238 lines
8.9 KiB
Nix
238 lines
8.9 KiB
Nix
{ config, skygUtils, ... }:
|
|
let
|
|
nfsVolume = skygUtils.container-services.nfsVols.tnas1;
|
|
app = config.skyg.internalNetworkingMap.apps.buzz;
|
|
buzz = {
|
|
domain = app.effectiveDns;
|
|
publicDomain = builtins.elemAt app.aliases 0;
|
|
port = 3000;
|
|
pairPort = 5000;
|
|
ip = app.ip;
|
|
bucket = "buzz-media";
|
|
images = {
|
|
relay = "ghcr.io/block/buzz:main";
|
|
caddy = "caddy:2-alpine";
|
|
posgres = "postgres:17-alpine";
|
|
redis = "redis:7-alpine";
|
|
minio = "chainguard/minio:latest-dev@sha256:8d5a0265f0e18fb3b29f95598147f1cc2a86b782181668bad176b0e90cce9569";
|
|
mc = "chainguard/minio-client:latest-dev@sha256:a552f9a01603b3db647712ae056e8bb4c04800365707f5bd4abffa05c9e4198e";
|
|
};
|
|
};
|
|
in
|
|
{
|
|
skyg.nixos.common.container-services.buzz = {
|
|
enable = true;
|
|
autoUpdate.enable = true;
|
|
timeoutStartSec = 600;
|
|
networks = {
|
|
internal = { driver = "bridge"; };
|
|
lan = config.skyg.nixos.common.containers.networks.ipvlanLab.compose;
|
|
};
|
|
volumes = {
|
|
buzz-postgres = nfsVolume "/mnt/SmallG/buzz/postgres";
|
|
buzz-redis = nfsVolume "/mnt/SmallG/buzz/redis";
|
|
s3 = nfsVolume "/mnt/SmallG/buzz/s3";
|
|
buzz-git = nfsVolume "/mnt/SmallG/buzz/git";
|
|
};
|
|
services = {
|
|
relay = {
|
|
image = buzz.images.relay;
|
|
extraConfig.depends_on = {
|
|
postgres.condition = "service_healthy";
|
|
redis.condition = "service_healthy";
|
|
minio.condition = "service_healthy";
|
|
minio-init.condition = "service_completed_successfully";
|
|
relay-index-prebuild.condition = "service_completed_successfully";
|
|
};
|
|
networks = [ "internal" ];
|
|
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
|
environment = {
|
|
BUZZ_BIND_ADDR = "0.0.0.0:${toString buzz.port}";
|
|
BUZZ_HEALTH_PORT = "8080";
|
|
BUZZ_METRICS_PORT = "9102";
|
|
RELAY_URL = "wss://${buzz.publicDomain}";
|
|
BUZZ_MEDIA_BASE_URL = "https://${buzz.publicDomain}/media";
|
|
BUZZ_MEDIA_SERVER_DOMAIN = buzz.publicDomain;
|
|
BUZZ_CORS_ORIGINS = "https://${buzz.publicDomain}";
|
|
BUZZ_PAIRING_RELAY_URL = "wss://${buzz.publicDomain}/pair";
|
|
BUZZ_S3_ENDPOINT = "http://minio:9000";
|
|
BUZZ_S3_REGION = "us-east-1";
|
|
BUZZ_S3_ADDRESSING_STYLE = "path";
|
|
BUZZ_S3_BUCKET = buzz.bucket;
|
|
BUZZ_GIT_REPO_PATH = "/data/git";
|
|
BUZZ_AUTO_MIGRATE = "true";
|
|
BUZZ_GIT_CONFORMANCE_PROBE = "true";
|
|
RUST_LOG = "buzz_relay=info,buzz_db=info,buzz_auth=info,buzz_pubsub=info,tower_http=info";
|
|
};
|
|
volumes = [ "buzz-git:/data/git" ];
|
|
healthcheck = {
|
|
test = [ "CMD-SHELL" "bash -ec 'exec 3<>/dev/tcp/127.0.0.1/8080; printf \"GET /_readiness HTTP/1.1\\r\\nHost: 127.0.0.1\\r\\nConnection: close\\r\\n\\r\\n\" >&3; grep -q \"200 OK\" <&3'" ];
|
|
interval = "10s";
|
|
timeout = "3s";
|
|
retries = 12;
|
|
start_period = "30s";
|
|
};
|
|
};
|
|
pair = {
|
|
image = buzz.images.relay;
|
|
networks = [ "internal" ];
|
|
environment.BUZZ_PAIR_RELAY_BIND_ADDR = "0.0.0.0:${toString buzz.pairPort}";
|
|
extraConfig.entrypoint = [ "/usr/local/bin/buzz-pair-relay" ];
|
|
};
|
|
caddy = {
|
|
image = buzz.images.caddy;
|
|
extraConfig.depends_on = {
|
|
relay.condition = "service_healthy";
|
|
pair.condition = "service_started";
|
|
};
|
|
networks = {
|
|
internal = { };
|
|
lan = { ipv4_address = buzz.ip; };
|
|
};
|
|
files."/etc/caddy/Caddyfile" = ''
|
|
${buzz.publicDomain} {
|
|
tls /etc/caddy/tls/fullchain.pem /etc/caddy/tls/key.pem
|
|
encode zstd gzip
|
|
# Only /pair goes to the pairing service
|
|
handle /pair {
|
|
reverse_proxy pair:${toString buzz.pairPort}
|
|
}
|
|
handle {
|
|
reverse_proxy relay:${toString buzz.port}
|
|
}
|
|
}
|
|
http://${buzz.domain} {
|
|
redir https://${buzz.publicDomain}{uri} permanent
|
|
}
|
|
:${toString buzz.port} {
|
|
reverse_proxy relay:${toString buzz.port}
|
|
}
|
|
:8080 {
|
|
reverse_proxy relay:8080
|
|
}
|
|
:9102 {
|
|
reverse_proxy relay:9102
|
|
}
|
|
'';
|
|
volumes = [
|
|
"/var/lib/acme/${buzz.publicDomain}/fullchain.pem:/etc/caddy/tls/fullchain.pem:ro"
|
|
"/var/lib/acme/${buzz.publicDomain}/key.pem:/etc/caddy/tls/key.pem:ro"
|
|
];
|
|
};
|
|
postgres = {
|
|
image = buzz.images.posgres;
|
|
networks = [ "internal" ];
|
|
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
|
environment = {
|
|
POSTGRES_DB = "buzz";
|
|
POSTGRES_USER = "buzz";
|
|
PGDATA = "/var/lib/postgresql/data/pgdata";
|
|
};
|
|
volumes = [ "buzz-postgres:/var/lib/postgresql/data" ];
|
|
healthcheck = {
|
|
test = [ "CMD-SHELL" "pg_isready -U buzz -d buzz" ];
|
|
interval = "5s";
|
|
timeout = "5s";
|
|
retries = 12;
|
|
start_period = "10s";
|
|
};
|
|
};
|
|
redis = {
|
|
image = buzz.images.redis;
|
|
networks = [ "internal" ];
|
|
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
|
volumes = [ "buzz-redis:/data" ];
|
|
files."/usr/local/bin/redis-entrypoint.sh" = ''
|
|
#!/bin/sh
|
|
set -eu
|
|
exec redis-server --appendonly yes --requirepass "$REDIS_PASSWORD"
|
|
'';
|
|
command = [ "sh" "/usr/local/bin/redis-entrypoint.sh" ];
|
|
healthcheck = {
|
|
test = [ "CMD-SHELL" ''redis-cli -a "$''${REDIS_PASSWORD}" ping | grep -q PONG'' ];
|
|
interval = "5s";
|
|
timeout = "3s";
|
|
retries = 12;
|
|
start_period = "5s";
|
|
};
|
|
};
|
|
minio = {
|
|
image = buzz.images.minio;
|
|
networks = [ "internal" ];
|
|
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
|
volumes = [ "s3:/data" ];
|
|
command = [ "server" "/data" "--console-address" ":9001" ];
|
|
healthcheck = {
|
|
test = [ "CMD-SHELL" "wget -q -O /dev/null http://127.0.0.1:9000/minio/health/live" ];
|
|
interval = "5s";
|
|
timeout = "5s";
|
|
retries = 12;
|
|
start_period = "10s";
|
|
};
|
|
};
|
|
minio-init = {
|
|
image = buzz.images.mc;
|
|
networks = [ "internal" ];
|
|
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
|
environment.BUZZ_S3_BUCKET = buzz.bucket;
|
|
files."/usr/local/bin/minio-init.sh" = ''
|
|
#!/bin/sh
|
|
set -eu
|
|
echo "setting alias"
|
|
mc alias set local http://minio:9000 "$BUZZ_S3_ACCESS_KEY" "$BUZZ_S3_SECRET_KEY"
|
|
echo "creating bucket"
|
|
mc mb -p local/$BUZZ_S3_BUCKET
|
|
echo "setting bucket permissions"
|
|
mc anonymous set none local/$BUZZ_S3_BUCKET
|
|
'';
|
|
extraConfig = {
|
|
entrypoint = [ "/bin/sh" "/usr/local/bin/minio-init.sh" ];
|
|
depends_on.minio.condition = "service_healthy";
|
|
};
|
|
restart = "no";
|
|
};
|
|
relay-index-prebuild = {
|
|
image = buzz.images.posgres;
|
|
networks = [ "internal" ];
|
|
environmentFiles = [ config.age.secrets.buzz-env.path ];
|
|
environment = {
|
|
POSTGRES_DB = "buzz";
|
|
POSTGRES_USER = "buzz";
|
|
};
|
|
files."/usr/local/bin/prebuild-indexes.sh" = ''
|
|
#!/bin/sh
|
|
set -eu
|
|
export PGPASSWORD="$POSTGRES_PASSWORD"
|
|
|
|
run_psql() {
|
|
psql -v ON_ERROR_STOP=1 -h postgres -U "$POSTGRES_USER" -d "$POSTGRES_DB" "$@"
|
|
}
|
|
|
|
ensure_index() {
|
|
name="$1"
|
|
sql="$2"
|
|
state=$(run_psql -tAc "SELECT coalesce((SELECT CASE WHEN i.indisvalid AND i.indisready AND i.indislive THEN 'valid' ELSE 'invalid' END FROM pg_index i WHERE i.indexrelid = to_regclass('public.$name')), 'missing')")
|
|
if [ "$state" = valid ]; then
|
|
return 0
|
|
fi
|
|
if [ "$state" = invalid ]; then
|
|
run_psql -c "DROP INDEX CONCURRENTLY IF EXISTS public.$name"
|
|
fi
|
|
run_psql -c "$sql"
|
|
}
|
|
|
|
ensure_index artifact_heads_modified "CREATE INDEX CONCURRENTLY artifact_heads_modified ON public.artifact_heads (community_id, modified_at, artifact_id);"
|
|
ensure_index artifact_heads_channel "CREATE INDEX CONCURRENTLY artifact_heads_channel ON public.artifact_heads (community_id, channel_id, artifact_id);"
|
|
ensure_index channel_members_sync "CREATE INDEX CONCURRENTLY channel_members_sync ON public.channel_members (community_id, pubkey, sync_modified_at, channel_id);"
|
|
ensure_index artifact_revisions_moves "CREATE INDEX CONCURRENTLY artifact_revisions_moves ON public.artifact_revisions (community_id, modified_at, event_id) WHERE source_channel_id IS NOT NULL;"
|
|
'';
|
|
extraConfig = {
|
|
entrypoint = [ "/bin/sh" "/usr/local/bin/prebuild-indexes.sh" ];
|
|
depends_on.postgres.condition = "service_healthy";
|
|
};
|
|
restart = "no";
|
|
};
|
|
};
|
|
};
|
|
}
|