Compare commits
2 commits
61f47320a7
...
206e450c99
Author | SHA1 | Date | |
---|---|---|---|
Patrik Lundin | 206e450c99 | ||
Patrik Lundin | 3cc1b602fd |
|
@ -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
|
|
@ -6,31 +6,71 @@ class cdn::db(
|
||||||
|
|
||||||
$db_secrets = lookup({ 'name' => 'cdn::db-secrets', 'default_value' => undef })
|
$db_secrets = lookup({ 'name' => 'cdn::db-secrets', 'default_value' => undef })
|
||||||
|
|
||||||
file { '/opt/sunet-cdn':
|
if $db_secrets {
|
||||||
ensure => directory,
|
file { '/opt/sunet-cdn':
|
||||||
owner => 'root',
|
ensure => directory,
|
||||||
group => 'root',
|
owner => 'root',
|
||||||
mode => '0755',
|
group => 'root',
|
||||||
}
|
mode => '0755',
|
||||||
|
}
|
||||||
|
|
||||||
file { '/opt/sunet-cdn/compose':
|
file { '/opt/sunet-cdn/compose':
|
||||||
ensure => directory,
|
ensure => directory,
|
||||||
owner => 'root',
|
owner => 'root',
|
||||||
group => 'root',
|
group => 'root',
|
||||||
mode => '0750',
|
mode => '0750',
|
||||||
}
|
}
|
||||||
|
|
||||||
sunet::nftables::docker_expose { 'expose postgres-db' :
|
file { '/opt/sunet-cdn/db':
|
||||||
allow_clients => '127.0.0.1',
|
ensure => directory,
|
||||||
port => 5432,
|
owner => 'root',
|
||||||
iif => $facts['networking']['primary'],
|
group => 'root',
|
||||||
}
|
mode => '0750',
|
||||||
|
}
|
||||||
|
|
||||||
sunet::docker_compose { 'sunet-cdn-db':
|
# User/group 999 matches postgres user in container
|
||||||
content => template('cdn/db/docker-compose.yml.erb'),
|
file { '/opt/sunet-cdn/db/conf':
|
||||||
service_name => 'cdn-db',
|
ensure => directory,
|
||||||
compose_dir => '/opt/sunet-cdn/compose',
|
owner => '999',
|
||||||
compose_filename => 'docker-compose.yml',
|
group => '999',
|
||||||
description => 'SUNET CDN DB',
|
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',
|
||||||
|
port => 5432,
|
||||||
|
iif => $facts['networking']['primary'],
|
||||||
|
}
|
||||||
|
|
||||||
|
sunet::docker_compose { 'sunet-cdn-db':
|
||||||
|
content => template('cdn/db/docker-compose.yml.erb'),
|
||||||
|
service_name => 'cdn-db',
|
||||||
|
compose_dir => '/opt/sunet-cdn/compose',
|
||||||
|
compose_filename => 'docker-compose.yml',
|
||||||
|
description => 'SUNET CDN DB',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
# File sourced by init-cdn-db.sh
|
||||||
|
cdn_password="<%= @db_secrets['cdn_password'] %>"
|
|
@ -1,3 +1,4 @@
|
||||||
---
|
---
|
||||||
cdn::db-secrets:
|
cdn::db-secrets:
|
||||||
postgres_password: ENC[PKCS7,MIIDCAYJKoZIhvcNAQcDoIIC+TCCAvUCAQAxggKQMIICjAIBADB0MFwxCzAJBgNVBAYTAlNFMQ4wDAYDVQQKDAVTVU5FVDEOMAwGA1UECwwFRVlBTUwxLTArBgNVBAMMJGludGVybmFsLXN0bzMtdGVzdC1kYi0xLmNkbi5zdW5ldC5zZQIUbbUXduFvDLw3OUVWiGrIvFBkkJMwDQYJKoZIhvcNAQEBBQAEggIAGKLk12OT5zsVKd04qsLkFtawdauLYUERXUC3d9FtZNVpwCFDNMnSsruUfasOvyvdaRbm8AUk/nAGuBNjD9HJj8J45KfQUEAPstnZPHndkF51LwU1twFrZvcSnvFANvxh61MzccMz6NVQL5CXsw4IWMDNhUbkhO5cRfxc0SOVugeTZ74BWwpEww9uKVPtfPRKCgJayBq1o/fyQblGsjJbmu/dRCm32gcdZu1lqfDU0DLsnjk14GJpqpP5h6sEfSrdXyFcWzFzdjtLZLL6TfUWYNYX6CnjjRMv1zZ73877DPXt+vvi0Nvqld5CDTXM9ggDWwZKvluVGn7sTyZdwtWLvs1qK4nui7NLfENtBrUi/GOWsxoFa9tmfeeX/cticzzQcUdDNkfaDgmBa/C7lyjlkwyDGvhYdBHycSEJJ8r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