Add a script that initializes the database.

This commit is contained in:
Andrea Dell'Amico 2020-10-14 13:58:10 +02:00
parent 2dd5b2b124
commit 222677dfb0
5 changed files with 26 additions and 0 deletions

View File

@ -16,6 +16,8 @@ open_asfa_docker_service_client_name: 'asfa-client'
open_asfa_docker_server_image: 'lucabrl01/asfa-server'
open_asfa_docker_client_image: 'lucabrl01/asfa-client'
open_asfa_docker_network: 'open_asfa_net'
# IMPORTANT. Set it to True for the server that is going to host the DB
open_asfa_docker_db_node: False
open_asfa_behind_haproxy: True
open_asfa_haproxy_public_net: 'haproxy-public'
# DB

View File

@ -6,6 +6,8 @@ open_asfa_docker_service_client_name: 'asfa-client'
open_asfa_docker_server_image: 'lucabrl01/asfa-server'
open_asfa_docker_client_image: 'lucabrl01/asfa-client'
open_asfa_docker_network: 'open_asfa_net'
# IMPORTANT. Set it to True for the server that is going to host the DB
open_asfa_docker_db_node: False
open_asfa_behind_haproxy: True
open_asfa_haproxy_public_net: 'haproxy-public'
# DB

View File

@ -4,6 +4,15 @@
- name: Create the directory where the dockerfile and the configuration file will be copied into
file: dest={{ open_asfa_compose_dir }} state=directory
- name: Install the DB initialization script
template: src=pg-create-user-db.sh.j2 dest={{ open_asfa_compose_dir }}/pg-create-user-db.sh owner=root group=root mode='0440'
run_once: True
when: open_asfa_docker_db_node is defined and open_asfa_docker_db_node
tags: [ 'open_asfa', 'open_asfa_swarm', 'open_asfa_db' ]
- name: Manage the installation of the OpenASFA configuration of the swarm service
block:
- name: Install the docker compose file
template: src=open-asfa-docker-compose.yml.j2 dest={{ open_asfa_compose_dir }}/docker-open-asfa-stack.yml owner=root group=root mode='0400'

View File

@ -53,6 +53,7 @@ services:
- 5432:5432
volumes:
- {{ open_asfa_db_volume }}:/var/lib/postgresql/data/pg_data
- {{ open_asfa_compose_dir }}/pg-create-user-db.sh:/docker-entrypoint-initdb.d/pg-create-user-db.sh:ro
environment:
POSTGRES_PASSWORD: {{ open_asfa_db_pwd }}
POSTGRES_DB: postgres

View File

@ -0,0 +1,12 @@
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER {{ open_asfa_db_user }} password {{ open_asfa_db_pwd }};
CREATE DATABASE {{ open_asfa_db_name }}
OWNER {{ open_asfa_db_user }}
ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8'
TEMPLATE template0;
GRANT ALL PRIVILEGES ON DATABASE {{ open_asfa_db_name }} TO {{ open_asfa_db_user }};
EOSQL