diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index 2725a5a..2a10702 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -7,7 +7,7 @@ // Change these to configure the services. // Image tag (application version) to use. - // Note: "latest" is not reccomended in production, as you can't be sure what version + // Note: "latest" is not recommended in production, as you can't be sure what version // you're actually running, and must manually re-pull to get an updated copy. image_tag:: "latest", @@ -33,8 +33,11 @@ // On OSX you need to change this to /private/var/lib/wubloader segments_path:: "/var/lib/wubloader/", - // Local path to save database to. Full path must already exist. Cannot contain ':'. - database_path:: "/var/lib/wubloader_postgres/", + // Local path to save database to. Full path must already exist. Cannot + // contain ':'. If this directory is non-empty, the database will start with + // the database in this directory and not run the setup scripts to create a + // new database. + database_path:: "/private/var/lib/wubloader_postgres/", // The host's port to expose each service on. // Only nginx (and postgres if that is being deployed) needs to be externally accessible - the other non-database ports are routed through nginx. @@ -53,21 +56,27 @@ // You can exec into the container and telnet to this port to get a python shell. backdoor_port:: 1234, - // Other nodes to backfill from. You should not include the local node. + // Other nodes to always backfill from. You should not include the local node. peers:: [ - "http://wubloader.codegunner.com/" ], // Connection args for the database. // If database is defined in this config, host and port should be postgres:5432. db_args:: { - user: "postgres", - password: "postgres", + user: "vst", + password: "dbfh2019", // don't use default in production host: "postgres", port: 5432, dbname: "wubloader", }, + // Other database arguments + db_super_user:: "postgres", // only accessible from localhost + db_super_password:: "postgres", + db_replication_user:: "replicate", // if empty, don't allow replication + db_replication_password:: "standby", // don't use default in production + db_standby:: false, // set to true to have this database replicate another server + // Path to a JSON file containing google credentials as keys // 'client_id', 'client_secret' and 'refresh_token'. google_creds:: "./google_creds.json", @@ -137,7 +146,7 @@ "--qualities", std.join(",", $.qualities), "--static-nodes", std.join(",", $.peers), "--backdoor-port", std.toString($.backdoor_port), - "--node-database", $.db_connect, + "--node-database", $.db_connect, ], // Mount the segments directory at /mnt volumes: ["%s:/mnt" % $.segments_path], @@ -231,14 +240,22 @@ }, [if $.enabled.postgres then "postgres"]: { - image: "postgres:latest", + image: "quay.io/ekimekim/wubloader-postgres:%s" % $.image_tag, restart: "on-failure", [if "postgres" in $.ports then "ports"]: ["%s:5432" % $.ports.postgres], environment: { - POSTGRES_USER: $.db_args.user, - POSTGRES_PASSWORD: $.db_args.password, + POSTGRES_USER: $.db_super_user, + POSTGRES_PASSWORD: $.db_super_password, POSTGRES_DB: $.db_args.dbname, + PGDATA: "/mnt", + WUBLOADER_USER: $.db_args.user, + WUBLOADER_PASSWORD: $.db_args.password, + REPLICATION_USER: $.db_replication_user, + REPLICATION_PASSWORD: $.db_replication_password, + MASTER_NODE: $.db_args.host, }, + volumes: ["%s:/mnt" % $.database_path], + [if $.db_standby then "command"]: ["/standby_setup.sh"], }, }, diff --git a/postgres/setup.sh b/postgres/setup.sh index d267955..4c0553f 100644 --- a/postgres/setup.sh +++ b/postgres/setup.sh @@ -3,17 +3,26 @@ set -e sed -i "/host all all all/d" "$PGDATA/pg_hba.conf" -echo "host replication $REPLICATION_USER all md5" >> "$PGDATA/pg_hba.conf" echo "host all $WUBLOADER_USER all md5" >> "$PGDATA/pg_hba.conf" +echo "Creating $WUBLOADER_USER" psql -v ON_ERROR_STOP=1 -U postgres <<-EOSQL CREATE USER $WUBLOADER_USER LOGIN PASSWORD '$WUBLOADER_PASSWORD'; + +EOSQL + + +if [ -n "$REPLICATION_USER" ]; then + echo "Creating $REPLICATION_USER" + echo "host replication $REPLICATION_USER all md5" >> "$PGDATA/pg_hba.conf" + psql -v ON_ERROR_STOP=1 -U postgres <<-EOSQL + CREATE USER $REPLICATION_USER LOGIN REPLICATION PASSWORD '$REPLICATION_PASSWORD'; EOSQL -cat >> ${PGDATA}/postgresql.conf <> ${PGDATA}/postgresql.conf <