Compare commits

...

2 commits

Author SHA1 Message Date
Patrik Lundin 206e450c99
Add init script for setting up cdn database 2024-11-13 14:52:17 +01:00
Patrik Lundin 3cc1b602fd
Add cdn user password 2024-11-13 14:35:18 +01:00
5 changed files with 78 additions and 23 deletions

View file

@ -0,0 +1,10 @@
#!/bin/bash
set -e
. /conf/init-cdn-db.conf
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER cdn WITH PASSWORD \'"$cdn_password"\';
CREATE DATABASE cdn;
GRANT ALL PRIVILEGES ON DATABASE cdn TO cdn;
EOSQL

View file

@ -6,6 +6,7 @@ class cdn::db(
$db_secrets = lookup({ 'name' => 'cdn::db-secrets', 'default_value' => undef }) $db_secrets = lookup({ 'name' => 'cdn::db-secrets', 'default_value' => undef })
if $db_secrets {
file { '/opt/sunet-cdn': file { '/opt/sunet-cdn':
ensure => directory, ensure => directory,
owner => 'root', owner => 'root',
@ -20,7 +21,45 @@ class cdn::db(
mode => '0750', mode => '0750',
} }
sunet::nftables::docker_expose { 'expose postgres-db' : file { '/opt/sunet-cdn/db':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0750',
}
# User/group 999 matches postgres user in container
file { '/opt/sunet-cdn/db/conf':
ensure => directory,
owner => '999',
group => '999',
mode => '0750',
}
file { '/opt/sunet-cdn/db/docker-entrypoint-initdb.d':
ensure => directory,
owner => '999',
group => '999',
mode => '0750',
}
file { '/opt/sunet-cdn/db/conf/init-cdn-db.conf':
ensure => directory,
owner => '999',
group => '999',
mode => '0640',
content => template('cdn/db/init-cdn-db.conf.erb'),
}
file { '/opt/sunet-cdn/db/docker-entrypoint-initdb.d/init-cdn-db.sh':
ensure => directory,
owner => '999',
group => '999',
mode => '0750',
content => file('cdn/db/init-cdn-db.sh'),
}
sunet::nftables::docker_expose { 'postgres-db' :
allow_clients => '127.0.0.1', allow_clients => '127.0.0.1',
port => 5432, port => 5432,
iif => $facts['networking']['primary'], iif => $facts['networking']['primary'],
@ -33,4 +72,5 @@ class cdn::db(
compose_filename => 'docker-compose.yml', compose_filename => 'docker-compose.yml',
description => 'SUNET CDN DB', description => 'SUNET CDN DB',
} }
}
} }

View file

@ -5,5 +5,7 @@ services:
- POSTGRES_PASSWORD=<%= @db_secrets['postgres_password'] %> - POSTGRES_PASSWORD=<%= @db_secrets['postgres_password'] %>
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
- /opt/sunet-cdn/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.dh
- /opt/sunet-cdn/db/conf:/conf
volumes: volumes:
postgres_data: postgres_data:

View file

@ -0,0 +1,2 @@
# File sourced by init-cdn-db.sh
cdn_password="<%= @db_secrets['cdn_password'] %>"

View file

@ -1,3 +1,4 @@
--- ---
cdn::db-secrets: cdn::db-secrets:
postgres_password: ENC[PKCS7,MIIDCAYJKoZIhvcNAQcDoIIC+TCCAvUCAQAxggKQMIICjAIBADB0MFwxCzAJBgNVBAYTAlNFMQ4wDAYDVQQKDAVTVU5FVDEOMAwGA1UECwwFRVlBTUwxLTArBgNVBAMMJGludGVybmFsLXN0bzMtdGVzdC1kYi0xLmNkbi5zdW5ldC5zZQIUbbUXduFvDLw3OUVWiGrIvFBkkJMwDQYJKoZIhvcNAQEBBQAEggIAGKLk12OT5zsVKd04qsLkFtawdauLYUERXUC3d9FtZNVpwCFDNMnSsruUfasOvyvdaRbm8AUk/nAGuBNjD9HJj8J45KfQUEAPstnZPHndkF51LwU1twFrZvcSnvFANvxh61MzccMz6NVQL5CXsw4IWMDNhUbkhO5cRfxc0SOVugeTZ74BWwpEww9uKVPtfPRKCgJayBq1o/fyQblGsjJbmu/dRCm32gcdZu1lqfDU0DLsnjk14GJpqpP5h6sEfSrdXyFcWzFzdjtLZLL6TfUWYNYX6CnjjRMv1zZ73877DPXt+vvi0Nvqld5CDTXM9ggDWwZKvluVGn7sTyZdwtWLvs1qK4nui7NLfENtBrUi/GOWsxoFa9tmf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