Compare commits
3 Commits
f71ece31f1
...
3b7a597d8f
Author | SHA1 | Date |
---|---|---|
Sam | 3b7a597d8f | |
Sam | 1e95ba6c36 | |
Sam | d29250a2a6 |
|
@ -4,22 +4,55 @@
|
||||||
backend = "docker";
|
backend = "docker";
|
||||||
projects = {
|
projects = {
|
||||||
"db".settings.services."db".service = {
|
"db".settings.services."db".service = {
|
||||||
image = "postgres:16";
|
|
||||||
restart = "unless-stopped";
|
restart = "unless-stopped";
|
||||||
|
build.context = "/nix/store";
|
||||||
|
build.dockerfile = builtins.baseNameOf "${pkgs.writeScript "pgDockerfile" ''
|
||||||
|
FROM postgres:16
|
||||||
|
# install packages
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
postgresql-16-postgis \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
''}";
|
||||||
environment = {
|
environment = {
|
||||||
POSTGRES_PASSWORD = "balls1234";
|
POSTGRES_PASSWORD = "balls1234";
|
||||||
POSTGRES_USER = "admin";
|
POSTGRES_USER = "admin";
|
||||||
POSTGRES_DATABASE = "test_db";
|
POSTGRES_DB = "admin_db";
|
||||||
|
PGDATA = "/var/lib/postgresql/data/pgdata";
|
||||||
};
|
};
|
||||||
ports = [ "5432:5432" ];
|
ports = [ "5432:5432" ];
|
||||||
volumes = [
|
volumes = [
|
||||||
"/mnt/postgres/data:/var/lib/postgres/data"
|
"/mnt/postgres:/var/lib/postgresql/data"
|
||||||
"${pkgs.writeScript "load_extensions" ''
|
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<EOF
|
# PG init script
|
||||||
create extension postgis;
|
"${pkgs.writeScript "init.sh" ''
|
||||||
select * FROM pg_extension;
|
#!/bin/bash
|
||||||
EOF
|
|
||||||
''}:/docker-entrypoint-initdb.d/"
|
# Create additional databases
|
||||||
|
psql -v --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
create database bitcoin;
|
||||||
|
create database osm;
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
# Create additional users
|
||||||
|
psql -v --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
create user gis;
|
||||||
|
create user satoshi;
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
# Setup bitcoin db
|
||||||
|
psql -v --username "$POSTGRES_USER" --dbname "bitcoin" <<-EOSQL
|
||||||
|
grant all privileges on database bitcoin to satoshi;
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
# Setup osm db
|
||||||
|
psql -v --username "$POSTGRES_USER" --dbname "osm" <<-EOSQL
|
||||||
|
grant all privileges on database osm to gis;
|
||||||
|
create extension if not exists postgis;
|
||||||
|
create extension if not exists hstore;
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
''}:/docker-entrypoint-initdb.d/init.sh"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue