8000 nix run .#start server 15 local dev full config by samrose · Pull Request #1130 · supabase/postgres · GitHub
[go: up one dir, main page]

Skip to content

nix run .#start server 15 local dev full config #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,61 @@
# Start a version of the server.
start-server =
let
configFile = ./nix/tests/postgresql.conf.in;
pgconfigFile = builtins.path {
name = "postgresql.conf";
path = ./ansible/files/postgresql_config/postgresql.conf.j2;
};
supautilsConfigFile = builtins.path {
name = "supautils.conf";
path = ./ansible/files/postgresql_config/supautils.conf.j2;
};
loggingConfigFile = builtins.path {
name = "logging.conf";
path = ./ansible/files/postgresql_config/postgresql-csvlog.conf;
};
readReplicaConfigFile = builtins.path {
name = "readreplica.conf";
path = ./ansible/files/postgresql_config/custom_read_replica.conf.j2;
};
pgHbaConfigFile = builtins.path {
name = "pg_hba.conf";
path = ./ansible/files/postgresql_config/pg_hba.conf.j2;
};
pgIdentConfigFile = builtins.path {
name = "pg_ident.conf";
path = ./ansible/files/postgresql_config/pg_ident.conf.j2;
};
getkeyScript = ./nix/tests/util/pgsodium_getkey.sh;
localeArchive = if pkgs.stdenv.isDarwin
then "${pkgs.darwin.locale}/share/locale"
else "${pkgs.glibcLocales}/lib/locale/locale-archive";
in
pkgs.runCommand "start-postgres-server" { } ''
mkdir -p $out/bin
mkdir -p $out/bin $out/etc/postgresql-custom $out/etc/postgresql
cp ${supautilsConfigFile} $out/etc/postgresql-custom/supautils.conf || { echo "Failed to copy supautils.conf"; exit 1; }
cp ${pgconfigFile} $out/etc/postgresql/postgresql.conf || { echo "Failed to copy postgresql.conf"; exit 1; }
cp ${loggingConfigFile} $out/etc/postgresql-custom/logging.conf || { echo "Failed to copy logging.conf"; exit 1; }
cp ${readReplicaConfigFile} $out/etc/postgresql-custom/read-replica.conf || { echo "Failed to copy read-replica.conf"; exit 1; }
cp ${pgHbaConfigFile} $out/etc/postgresql/pg_hba.conf || { echo "Failed to copy pg_hba.conf"; exit 1; }
cp ${pgIdentConfigFile} $out/etc/postgresql/pg_ident.conf || { echo "Failed to copy pg_ident.conf"; exit 1; }
echo "Copy operation completed"
chmod 644 $out/etc/postgresql-custom/supautils.conf
chmod 644 $out/etc/postgresql/postgresql.conf
chmod 644 $out/etc/postgresql-custom/logging.conf
chmod 644 $out/etc/postgresql/pg_hba.conf
substitute ${./nix/tools/run-server.sh.in} $out/bin/start-postgres-server \
--subst-var-by 'PGSQL_DEFAULT_PORT' '${pgsqlDefaultPort}' \
--subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
--subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
--subst-var-by 'PSQL_CONF_FILE' '${configFile}' \
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'

--subst-var-by 'PSQL_CONF_FILE' $out/etc/postgresql/postgresql.conf \
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}' \
--subst-var-by 'READREPL_CONF_FILE' "$out/etc/postgresql-custom/read-replica.conf" \
--subst-var-by 'LOGGING_CONF_FILE' "$out/etc/postgresql-custom/logging.conf" \
--subst-var-by 'SUPAUTILS_CONF_FILE' "$out/etc/postgresql-custom/supautils.conf" \
--subst-var-by 'PG_HBA' "$out/etc/postgresql/pg_hba.conf" \
--subst-var-by 'PG_IDENT' "$out/etc/postgresql/pg_ident.conf" \
--subst-var-by 'LOCALES' '${localeArchive}'

chmod +x $out/bin/start-postgres-server
'';

Expand Down
5 changes: 5 additions & 0 deletions logfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2024-08-15 19:02:30.233 UTC [168132] LOG: invalid value for parameter "lc_messages": "en_US.UTF-8"
2024-08-15 19:02:30.233 UTC [168132] LOG: invalid value for parameter "lc_monetary": "en_US.UTF-8"
2024-08-15 19:02:30.233 UTC [168132] LOG: invalid value for parameter "lc_numeric": "en_US.UTF-8"
2024-08-15 19:02:30.233 UTC [168132] LOG: invalid value for parameter "lc_time": "en_US.UTF-8"
2024-08-15 19:02:30.234 UTC [168132] FATAL: configuration file "/tmp/tmp.ARsCfJV3Wf/postgresql.conf" contains errors
31 changes: 23 additions & 8 deletions nix/tools/run-server.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,36 @@ PGSQL_SUPERUSER=@PGSQL_SUPERUSER@
PSQL_CONF_FILE=@PSQL_CONF_FILE@
PGSODIUM_GETKEY_SCRIPT=@PGSODIUM_GETKEY@
PORTNO="${2:-@PGSQL_DEFAULT_PORT@}"
PLJAVA_LIBJVM_LOCATION=@LIBJVM_LOCATION@
SUPAUTILS_CONFIG_FILE=@SUPAUTILS_CONF_FILE@
LOGGING_CONFIG_FILE=@LOGGING_CONF_FILE@
READREPL_CONFIG_FILE=@READREPL_CONF_FILE@
PG_HBA_FILE=@PG_HBA@
PG_IDENT_FILE=@PG_IDENT@
DATDIR=$(mktemp -d)
LOCALE_ARCHIVE=@LOCALES@
export LOCALE_ARCHIVE
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
mkdir -p "$DATDIR"

echo "NOTE: using port $PORTNO for server"
echo "NOTE: using temporary directory $DATDIR for data, which will not be removed"
echo "NOTE: you are free to re-use this data directory at will"
echo

initdb -U "$PGSQL_SUPERUSER" -D "$DATDIR" --locale=C
initdb -U "$PGSQL_SUPERUSER" -D "$DATDIR"

echo "NOTE: patching postgresql.conf files"
echo "pljava libjvm location: $PLJAVA_LIBJVM_LOCATION"
sed -e "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \
-e "s#@PLJAVA_LIBJVM_LOCATION@#$PLJAVA_LIBJVM_LOCATION#g" \
$PSQL_CONF_FILE > "$DATDIR/postgresql.conf"

exec postgres -p "$PORTNO" -D "$DATDIR" -k /tmp
sed -e "\$a\\
include = '$SUPAUTILS_CONFIG_FILE' \\
pgsodium.getkey_script = '$PGSODIUM_GETKEY_SCRIPT'" \
-e "s|data_directory = '/var/lib/postgresql/data'|data_directory = '$DATDIR'|" \
-e "s|hba_file = '/etc/postgresql/pg_hba.conf'|hba_file = '$PG_HBA_FILE'|" \
-e "s|ident_file = '/etc/postgresql/pg_ident.conf'|ident_file = '$PG_IDENT_FILE'|" \
-e "s|include = '/etc/postgresql/logging.conf'|#&|" \
-e "s|include = '/etc/postgresql-custom/read-replica.conf'|include = '$READREPL_CONFIG_FILE'|" \
"$PSQL_CONF_FILE" > "$DATDIR/postgresql.conf"
postgres -p "$PORTNO" -D "$DATDIR" -k /tmp
Loading
0