From 15bf14006551a3e9a20a79ffa028f1df459485e3 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 26 Dec 2023 03:13:16 +0100 Subject: [PATCH] Changed roles to new docker backup procedure --- roles/backup-docker-to-local/tasks/main.yml | 13 +++-- roles/docker-akaunting/templates/db.env.j2 | 8 +-- roles/docker-akaunting/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 21 ++------ roles/docker-attendize/vars/main.yml | 7 ++- roles/docker-bigbluebutton/vars/main.yml | 7 ++- .../templates/docker-compose.yml.j2 | 27 ++-------- roles/docker-gitea/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 24 +++------ roles/docker-joomla/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 52 ++++++++----------- roles/docker-listmonk/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 21 +------- roles/docker-mailu/templates/mailu.env.j2 | 16 +++--- roles/docker-mailu/vars/main.yml | 7 ++- .../templates/.env.production.j2 | 8 +-- roles/docker-mastodon/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 29 +++-------- roles/docker-matomo/vars/main.yml | 7 ++- .../templates/docker-compose.yml.j2 | 8 +-- roles/docker-matrix-compose/vars/main.yml | 7 ++- .../templates/docker-compose.yml.j2 | 21 ++------ roles/docker-mybb/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 18 +++---- roles/docker-nextcloud/vars/main.yml | 7 ++- roles/docker-openproject/templates/env.j2 | 4 +- roles/docker-openproject/vars/main.yml | 7 ++- roles/docker-peertube/templates/env.j2 | 8 +-- roles/docker-peertube/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 17 ++---- roles/docker-pixelfed/vars/main.yml | 5 ++ .../templates/docker-compose.yml.j2 | 29 +++-------- roles/docker-wordpress/vars/main.yml | 5 ++ roles/docker-yourls/vars/main.yml | 7 ++- templates/docker-mariadb-service.yml.j2 | 18 +++++++ 35 files changed, 215 insertions(+), 228 deletions(-) create mode 100644 templates/docker-mariadb-service.yml.j2 diff --git a/roles/backup-docker-to-local/tasks/main.yml b/roles/backup-docker-to-local/tasks/main.yml index da87eeb9..9eab4fc0 100644 --- a/roles/backup-docker-to-local/tasks/main.yml +++ b/roles/backup-docker-to-local/tasks/main.yml @@ -34,10 +34,15 @@ notify: restart backup-docker-to-local.timer when: run_once_backup_docker_to_local is not defined -- name: create {{backup_docker_to_local_folder}}databases.csv - copy: - src: "{{ inventory_dir }}/files/{{ inventory_hostname }}{{backup_docker_to_local_folder}}databases.csv" - dest: "{{backup_docker_to_local_folder}}databases.csv" +- name: seed database values + command: + cmd: "python database_entry_seeder.py databases.csv {{database_instance}} {{database_host}} {{database_databasename}} {{database_username}} {{database_password}}" + chdir: "{{backup_docker_to_local_folder}}" + +- name: Set file permissions for databases.csv to be readable, writable, and executable by root only + ansible.builtin.file: + path: "{{ backup_docker_to_local_folder }}databases.csv" + mode: '0700' owner: root group: root when: run_once_backup_docker_to_local is not defined diff --git a/roles/docker-akaunting/templates/db.env.j2 b/roles/docker-akaunting/templates/db.env.j2 index 7ef2704d..6065ffbb 100644 --- a/roles/docker-akaunting/templates/db.env.j2 +++ b/roles/docker-akaunting/templates/db.env.j2 @@ -1,9 +1,9 @@ # These could be changed -MYSQL_DATABASE=akaunting -MYSQL_USER=admin +MYSQL_DATABASE={{database_databasename}} +MYSQL_USER={{database_username}} # This should definitely be changed to something long and random -MYSQL_PASSWORD={{akaunting_database_password}} +MYSQL_PASSWORD={{database_password}} # You should probably leave this -MYSQL_ROOT_PASSWORD={{akaunting_database_password}} +MYSQL_ROOT_PASSWORD={{database_password}} diff --git a/roles/docker-akaunting/vars/main.yml b/roles/docker-akaunting/vars/main.yml index 4644f7d3..d9e15d6d 100644 --- a/roles/docker-akaunting/vars/main.yml +++ b/roles/docker-akaunting/vars/main.yml @@ -1 +1,6 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}akaunting/" +database_instance: "akaunting" +database_host: "akaunting-db" +database_databasename: "{{database_instance}}" +database_username: "admin" +database_password: "{{akaunting_database_password}}" diff --git a/roles/docker-attendize/templates/docker-compose.yml.j2 b/roles/docker-attendize/templates/docker-compose.yml.j2 index 1af999f3..5b3bbdf1 100644 --- a/roles/docker-attendize/templates/docker-compose.yml.j2 +++ b/roles/docker-attendize/templates/docker-compose.yml.j2 @@ -24,24 +24,9 @@ services: volumes: - .:/usr/share/nginx/html - .:/var/www - database: - logging: - driver: journald - image: mariadb - restart: always - environment: - MYSQL_DATABASE: "attendize" - MYSQL_USER: "attendize" - MYSQL_PASSWORD: "{{attendize_database_password}}" - MYSQL_ROOT_PASSWORD: "{{attendize_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=attendize --password={{attendize_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 + +{% include 'templates/docker-mariadb-service.yml.j2' %} + maildev: image: maildev/maildev ports: diff --git a/roles/docker-attendize/vars/main.yml b/roles/docker-attendize/vars/main.yml index e3e8c7cb..44ce6b96 100644 --- a/roles/docker-attendize/vars/main.yml +++ b/roles/docker-attendize/vars/main.yml @@ -1,3 +1,8 @@ --- docker_compose_instance_directory: "{{path_docker_compose_instances}}attendize/" -mail_interface_domain: "mail.{{domain}}" +mail_interface_domain: "mail.{{domain}}" +database_instance: "attendize" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{attendize_database_password}}" diff --git a/roles/docker-bigbluebutton/vars/main.yml b/roles/docker-bigbluebutton/vars/main.yml index 9b40ea81..1c54abff 100644 --- a/roles/docker-bigbluebutton/vars/main.yml +++ b/roles/docker-bigbluebutton/vars/main.yml @@ -1 +1,6 @@ -docker_compose_instance_directory: "{{path_docker_compose_instances}}bigbluebutton/" \ No newline at end of file +docker_compose_instance_directory: "{{path_docker_compose_instances}}bigbluebutton/" +database_instance: "bigbluebutton" +database_host: "postgres" +database_databasename: "greenlight-v3" +database_username: "postgres" +database_password: "" \ No newline at end of file diff --git a/roles/docker-gitea/templates/docker-compose.yml.j2 b/roles/docker-gitea/templates/docker-compose.yml.j2 index d6b911f6..d437ec53 100644 --- a/roles/docker-gitea/templates/docker-compose.yml.j2 +++ b/roles/docker-gitea/templates/docker-compose.yml.j2 @@ -10,10 +10,10 @@ services: - USER_UID=1000 - USER_GID=1000 - DB_TYPE=mysql - - DB_HOST=database:3306 - - DB_NAME=gitea - - DB_USER=gitea - - DB_PASSWD={{gitea_database_password}} + - DB_HOST={{database_host}}:3306 + - DB_NAME={{database_databasename}} + - DB_USER={{database_username}} + - DB_PASSWD={{database_password}} - SSH_PORT={{ssh_port}} - SSH_LISTEN_PORT=22 - DOMAIN={{domain}} @@ -31,24 +31,7 @@ services: - /etc/localtime:/etc/localtime:ro depends_on: - database - database: - logging: - driver: journald - image: mariadb - restart: always - environment: - MYSQL_DATABASE: "gitea" - MYSQL_USER: "gitea" - MYSQL_PASSWORD: "{{gitea_database_password}}" - MYSQL_ROOT_PASSWORD: "{{gitea_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=gitea --password={{gitea_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 +{% include 'templates/docker-mariadb-service.yml.j2' %} volumes: database: data: diff --git a/roles/docker-gitea/vars/main.yml b/roles/docker-gitea/vars/main.yml index a029ab64..71b2d12c 100644 --- a/roles/docker-gitea/vars/main.yml +++ b/roles/docker-gitea/vars/main.yml @@ -1 +1,6 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}gitea/" +database_instance: "gitea" +database_host: "{{database_instance}}" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{gitea_database_password}}" \ No newline at end of file diff --git a/roles/docker-joomla/templates/docker-compose.yml.j2 b/roles/docker-joomla/templates/docker-compose.yml.j2 index a374aef8..a9e7f4d1 100644 --- a/roles/docker-joomla/templates/docker-compose.yml.j2 +++ b/roles/docker-joomla/templates/docker-compose.yml.j2 @@ -6,10 +6,10 @@ services: logging: driver: journald environment: - JOOMLA_DB_HOST: "database:3306" - JOOMLA_DB_USER: "joomla" - JOOMLA_DB_PASSWORD: "{{joomla_database_password}}" - JOOMLA_DB_NAME: "joomla" + JOOMLA_DB_HOST: "{{database_host}}:3306" + JOOMLA_DB_USER: "{{database_username}}" + JOOMLA_DB_PASSWORD: "{{database_password}}" + JOOMLA_DB_NAME: "{{database_databasename}}" restart: always links: - database @@ -17,19 +17,9 @@ services: - data:/var/www/html ports: - "127.0.0.1:{{http_port}}:80" - database: - image: mariadb - logging: - driver: journald - environment: - MYSQL_DATABASE: "joomla" - MYSQL_USER: "joomla" - MYSQL_PASSWORD: "{{joomla_database_password}}" - MYSQL_ROOT_PASSWORD: "{{joomla_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - restart: always + +{% include 'templates/docker-mariadb-service.yml.j2' %} + volumes: database: data: \ No newline at end of file diff --git a/roles/docker-joomla/vars/main.yml b/roles/docker-joomla/vars/main.yml index 49af5787..c54d80ad 100644 --- a/roles/docker-joomla/vars/main.yml +++ b/roles/docker-joomla/vars/main.yml @@ -1 +1,6 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}joomla/" +database_instance: "joomla" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{joomla_database_password}}" \ No newline at end of file diff --git a/roles/docker-listmonk/templates/docker-compose.yml.j2 b/roles/docker-listmonk/templates/docker-compose.yml.j2 index f5f8185a..2aa5eaa6 100644 --- a/roles/docker-listmonk/templates/docker-compose.yml.j2 +++ b/roles/docker-listmonk/templates/docker-compose.yml.j2 @@ -1,35 +1,22 @@ version: "3.7" -x-application-defaults: &application-defaults - restart: unless-stopped - image: listmonk/listmonk:latest - ports: - - "127.0.0.1:{{http_port}}:9000" - networks: - - listmonk - environment: - - TZ=Etc/UTC - -x-database-defaults: &database-defaults - image: postgres:13-alpine - ports: - - "9432:5432" - networks: - - listmonk - environment: - - POSTGRES_PASSWORD={{listmonk_database_password}} - - POSTGRES_USER=listmonk - - POSTGRES_DB=listmonk - restart: unless-stopped - healthcheck: - test: ["CMD-SHELL", "pg_isready -U listmonk"] - interval: 10s - timeout: 5s - retries: 6 - services: database: - <<: *database-defaults + image: postgres:13-alpine + ports: + - "9432:5432" + networks: + - listmonk + environment: + - POSTGRES_PASSWORD={{database_password}} + - POSTGRES_USER={{database_username}} + - POSTGRES_DB={{database_databasename}} + restart: unless-stopped + healthcheck: + test: ["CMD-SHELL", "pg_isready -U {{database_username}}"] + interval: 10s + timeout: 5s + retries: 6 container_name: database volumes: - type: volume @@ -37,7 +24,14 @@ services: target: /var/lib/postgresql/data application: - <<: *application-defaults + restart: unless-stopped + image: listmonk/listmonk:latest + ports: + - "127.0.0.1:{{http_port}}:9000" + networks: + - listmonk + environment: + - TZ=Etc/UTC container_name: listmonk_application depends_on: - database diff --git a/roles/docker-listmonk/vars/main.yml b/roles/docker-listmonk/vars/main.yml index 75a5cf4f..673b56c4 100644 --- a/roles/docker-listmonk/vars/main.yml +++ b/roles/docker-listmonk/vars/main.yml @@ -1 +1,6 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}listmonk/" +database_instance: "listmonk" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{listmonk_database_password}}" \ No newline at end of file diff --git a/roles/docker-mailu/templates/docker-compose.yml.j2 b/roles/docker-mailu/templates/docker-compose.yml.j2 index fbfd1701..28105fc4 100644 --- a/roles/docker-mailu/templates/docker-compose.yml.j2 +++ b/roles/docker-mailu/templates/docker-compose.yml.j2 @@ -20,25 +20,8 @@ services: - resolver dns: - 192.168.203.254 - - database: - image: mariadb - restart: always - environment: - MYSQL_DATABASE: "mailu" - MYSQL_USER: "mailu" - MYSQL_PASSWORD: "{{mailu_database_password}}" - MYSQL_ROOT_PASSWORD: "{{mailu_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=mailu --password={{mailu_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 - logging: - driver: journald + +{% include 'templates/docker-mariadb-service.yml.j2' %} depends_on: - resolver dns: diff --git a/roles/docker-mailu/templates/mailu.env.j2 b/roles/docker-mailu/templates/mailu.env.j2 index 910ad914..b52a7f4a 100644 --- a/roles/docker-mailu/templates/mailu.env.j2 +++ b/roles/docker-mailu/templates/mailu.env.j2 @@ -140,15 +140,15 @@ LOG_LEVEL=WARNING # Database settings ################################### DB_FLAVOR=mysql -DB_USER=mailu -DB_PW={{mailu_database_password}} -DB_HOST=database:3306 -DB_NAME=mailu +DB_USER={{database_username}} +DB_PW={{database_password}} +DB_HOST={{database_host}}:3306 +DB_NAME={{database_databasename}} ROUNDCUBE_DB_FLAVOR=mysql -ROUNDCUBE_DB_USER=mailu -ROUNDCUBE_DB_PW={{mailu_database_password}} -ROUNDCUBE_DB_NAME=mailu -ROUNDCUBE_DB_HOST=database:3306 +ROUNDCUBE_DB_USER={{database_username}} +ROUNDCUBE_DB_PW={{database_password}} +ROUNDCUBE_DB_NAME={{database_databasename}} +ROUNDCUBE_DB_HOST={{database_host}}:3306 API_TOKEN={{mailu_api_token}} \ No newline at end of file diff --git a/roles/docker-mailu/vars/main.yml b/roles/docker-mailu/vars/main.yml index 27b1f5a5..2f15502a 100644 --- a/roles/docker-mailu/vars/main.yml +++ b/roles/docker-mailu/vars/main.yml @@ -1 +1,6 @@ -docker_compose_instance_directory: "{{path_docker_compose_instances}}mailu/" \ No newline at end of file +docker_compose_instance_directory: "{{path_docker_compose_instances}}mailu/" +database_instance: "mailu" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{mailu_database_password}}" \ No newline at end of file diff --git a/roles/docker-mastodon/templates/.env.production.j2 b/roles/docker-mastodon/templates/.env.production.j2 index 8fce28c6..aedacfed 100644 --- a/roles/docker-mastodon/templates/.env.production.j2 +++ b/roles/docker-mastodon/templates/.env.production.j2 @@ -5,11 +5,11 @@ SECRET_KEY_BASE={{mastodon_secret_key_base}} OTP_SECRET={{mastodon_otp_secret}} VAPID_PRIVATE_KEY={{mastodon_vapid_private_key}} VAPID_PUBLIC_KEY={{mastodon_vapid_public_key}} -DB_HOST=database +DB_HOST={{database_host}} DB_PORT=5432 -DB_NAME=postgres -DB_USER=postgres -DB_PASS= +DB_NAME={{database_databasename}} +DB_USER={{database_username}} +DB_PASS={{database_password}} REDIS_HOST=redis REDIS_PORT=6379 REDIS_PASSWORD= diff --git a/roles/docker-mastodon/vars/main.yml b/roles/docker-mastodon/vars/main.yml index 4ccb7d3e..7453ec08 100644 --- a/roles/docker-mastodon/vars/main.yml +++ b/roles/docker-mastodon/vars/main.yml @@ -1 +1,6 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}mastodon/" +database_instance: "mastodon" +database_host: "database" +database_databasename: "postgres" # todo: Change this to standart name scheme for future setups +database_username: "postgres" # todo: Change this to standart name scheme for future setups +database_password: "" # todo: Change this to standart name scheme for future setups \ No newline at end of file diff --git a/roles/docker-matomo/templates/docker-compose.yml.j2 b/roles/docker-matomo/templates/docker-compose.yml.j2 index 7c6a7fe0..f7ffd3bb 100644 --- a/roles/docker-matomo/templates/docker-compose.yml.j2 +++ b/roles/docker-matomo/templates/docker-compose.yml.j2 @@ -9,35 +9,20 @@ services: ports: - "127.0.0.1:{{http_port}}:80" environment: - MATOMO_DATABASE_HOST: "database:3306" + MATOMO_DATABASE_HOST: "{{database_host}}:3306" MATOMO_DATABASE_ADAPTER: "mysql" - MATOMO_DATABASE_USERNAME: "matomo" - MATOMO_DATABASE_PASSWORD: "{{matomo_database_password}}" - MATOMO_DATABASE_DBNAME: "matomo" + MATOMO_DATABASE_USERNAME: "{{database_username}}" + MATOMO_DATABASE_PASSWORD: "{{database_password}}" + MATOMO_DATABASE_DBNAME: "{{database_databasename}}" links: - database depends_on: - database volumes: - data:/var/www/html - database: - logging: - driver: journald - image: mariadb - restart: always - environment: - MYSQL_DATABASE: "matomo" - MYSQL_USER: "matomo" - MYSQL_PASSWORD: "{{matomo_database_password}}" - MYSQL_ROOT_PASSWORD: "{{matomo_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=matomo --password={{matomo_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 + +{% include 'templates/docker-mariadb-service.yml.j2' %} + volumes: database: data: diff --git a/roles/docker-matomo/vars/main.yml b/roles/docker-matomo/vars/main.yml index 3adfaaad..e11fc64e 100644 --- a/roles/docker-matomo/vars/main.yml +++ b/roles/docker-matomo/vars/main.yml @@ -1,2 +1,7 @@ --- -docker_compose_instance_directory: "{{path_docker_compose_instances}}matomo/" \ No newline at end of file +docker_compose_instance_directory: "{{path_docker_compose_instances}}matomo/" +database_instance: "matomo" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{matomo_database_password}}" \ No newline at end of file diff --git a/roles/docker-matrix-compose/templates/docker-compose.yml.j2 b/roles/docker-matrix-compose/templates/docker-compose.yml.j2 index 26cdb4dc..b63ea2a6 100644 --- a/roles/docker-matrix-compose/templates/docker-compose.yml.j2 +++ b/roles/docker-matrix-compose/templates/docker-compose.yml.j2 @@ -26,12 +26,12 @@ services: volumes: - database:/var/lib/postgresql/data environment: - - POSTGRES_DB=matrix - - POSTGRES_USER=matrix - - POSTGRES_PASSWORD={{matrix_database_password}} + - POSTGRES_DB={{database_databasename}} + - POSTGRES_USER={{database_username}} + - POSTGRES_PASSWORD={{database_password}} - POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale=C healthcheck: - test: ["CMD-SHELL", "pg_isready -U matrix"] + test: ["CMD-SHELL", "pg_isready -U {{database_username}}"] interval: 10s timeout: 5s retries: 6 diff --git a/roles/docker-matrix-compose/vars/main.yml b/roles/docker-matrix-compose/vars/main.yml index 4161111b..72b3ac94 100644 --- a/roles/docker-matrix-compose/vars/main.yml +++ b/roles/docker-matrix-compose/vars/main.yml @@ -1,2 +1,7 @@ --- -docker_compose_instance_directory: "{{path_docker_compose_instances}}matrix/" \ No newline at end of file +docker_compose_instance_directory: "{{path_docker_compose_instances}}matrix/" +database_instance: "matrix" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{matrix_database_password}}" \ No newline at end of file diff --git a/roles/docker-mybb/templates/docker-compose.yml.j2 b/roles/docker-mybb/templates/docker-compose.yml.j2 index edf8d0e2..cea2b610 100644 --- a/roles/docker-mybb/templates/docker-compose.yml.j2 +++ b/roles/docker-mybb/templates/docker-compose.yml.j2 @@ -25,24 +25,9 @@ services: volumes: - "{{docker_compose_instance_confd_directory}}:{{target_mount_conf_d_directory}}:ro" - "data:/var/www/html:ro" - database: - logging: - driver: journald - image: mariadb - restart: always - environment: - MYSQL_DATABASE: "mybb" - MYSQL_USER: "mybb" - MYSQL_PASSWORD: "{{mybb_database_password}}" - MYSQL_ROOT_PASSWORD: "{{mybb_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=mybb --password={{mybb_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 + +{% include 'templates/docker-mariadb-service.yml.j2' %} + volumes: database: data: diff --git a/roles/docker-mybb/vars/main.yml b/roles/docker-mybb/vars/main.yml index c464ebd3..e3ff2315 100644 --- a/roles/docker-mybb/vars/main.yml +++ b/roles/docker-mybb/vars/main.yml @@ -4,3 +4,8 @@ docker_compose_instance_confd_directory: "{{docker_compose_instance_directory}}c docker_compose_instance_confd_defaultconf_file: "{{docker_compose_instance_confd_directory}}default.conf" target_mount_conf_d_directory: "{{nginx_servers_directory}}" source_domain: "mybb.{{top_domain}}" +database_instance: "mybb" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{mybb_database_password}}" \ No newline at end of file diff --git a/roles/docker-nextcloud/templates/docker-compose.yml.j2 b/roles/docker-nextcloud/templates/docker-compose.yml.j2 index a47cc6f4..7b505c59 100644 --- a/roles/docker-nextcloud/templates/docker-compose.yml.j2 +++ b/roles/docker-nextcloud/templates/docker-compose.yml.j2 @@ -11,26 +11,26 @@ services: volumes: - data:/var/www/html environment: - MYSQL_DATABASE: "nextcloud" - MYSQL_USER: "nextcloud" - MYSQL_PASSWORD: "{{nextcloud_database_password}}" - MYSQL_HOST: database:3306 + MYSQL_DATABASE: "{{database_databasename}}" + MYSQL_USER: "{{database_username}}" + MYSQL_PASSWORD: "{{database_password}}" + MYSQL_HOST: {{database_host}}:3306 database: logging: driver: journald image: mariadb:10.5 command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" environment: - MYSQL_DATABASE: "nextcloud" - MYSQL_USER: "nextcloud" - MYSQL_PASSWORD: "{{nextcloud_database_password}}" - MYSQL_ROOT_PASSWORD: "{{nextcloud_database_password}}" + MYSQL_DATABASE: "{{database_databasename}}" + MYSQL_USER: "{{database_username}}" + MYSQL_PASSWORD: "{{database_password}}" + MYSQL_ROOT_PASSWORD: "{{database_password}}" MARIADB_AUTO_UPGRADE: "1" volumes: - database:/var/lib/mysql restart: always healthcheck: - test: "/usr/bin/mariadb --user=nextcloud --password={{nextcloud_database_password}} --execute \"SHOW DATABASES;\"" + test: "/usr/bin/mariadb --user={{database_username}} --password={{database_password}} --execute \"SHOW DATABASES;\"" interval: 3s timeout: 1s retries: 5 diff --git a/roles/docker-nextcloud/vars/main.yml b/roles/docker-nextcloud/vars/main.yml index 7b09fc97..309c9e28 100644 --- a/roles/docker-nextcloud/vars/main.yml +++ b/roles/docker-nextcloud/vars/main.yml @@ -1,2 +1,7 @@ --- -docker_compose_instance_directory: "{{path_docker_compose_instances}}nextcloud/" \ No newline at end of file +docker_compose_instance_directory: "{{path_docker_compose_instances}}nextcloud/" +database_instance: "nextcloud" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{nextcloud_database_password}}" \ No newline at end of file diff --git a/roles/docker-openproject/templates/env.j2 b/roles/docker-openproject/templates/env.j2 index d1b77b44..056dc098 100644 --- a/roles/docker-openproject/templates/env.j2 +++ b/roles/docker-openproject/templates/env.j2 @@ -12,8 +12,8 @@ OPENPROJECT_HOST__NAME={{domain}} PORT=127.0.0.1:{{http_port}} OPENPROJECT_RAILS__RELATIVE__URL__ROOT= IMAP_ENABLED=false -POSTGRES_PASSWORD="{{ openproject_database_password }}" -DATABASE_URL="postgres://postgres:{{ openproject_database_password }}@db/openproject?pool=20&encoding=unicode&reconnect=true" +POSTGRES_PASSWORD="{{ database_password }}" +DATABASE_URL="postgres://{{ database_username }}:{{ database_password }}@{{database_host}}/{{database_databasename}}?pool=20&encoding=unicode&reconnect=true" RAILS_MIN_THREADS=4 RAILS_MAX_THREADS=16 diff --git a/roles/docker-openproject/vars/main.yml b/roles/docker-openproject/vars/main.yml index fff8f0bd..2f78deee 100644 --- a/roles/docker-openproject/vars/main.yml +++ b/roles/docker-openproject/vars/main.yml @@ -1,4 +1,9 @@ repository_directory: "{{ path_docker_compose_instances }}openproject/" docker_compose_instance_directory: "{{repository_directory}}compose/" docker_compose_file_path: "{{docker_compose_instance_directory}}docker-compose.yml" -docker_compose_backup_path: "/tmp/openproject-docker-compose-backup.yml" \ No newline at end of file +docker_compose_backup_path: "/tmp/openproject-docker-compose-backup.yml" +database_instance: "openproject" +database_host: "db" +database_databasename: "{{database_instance}}" +database_username: "postgres" +database_password: "{{openproject_database_password}}" \ No newline at end of file diff --git a/roles/docker-peertube/templates/env.j2 b/roles/docker-peertube/templates/env.j2 index 5f2f5bdb..5119991a 100644 --- a/roles/docker-peertube/templates/env.j2 +++ b/roles/docker-peertube/templates/env.j2 @@ -1,11 +1,11 @@ # Database / Postgres service configuration -POSTGRES_USER=peertube +POSTGRES_USER={{database_username}} POSTGRES_PASSWORD={{peertube_database_password}} -POSTGRES_DB=peertube -PEERTUBE_DB_USERNAME=peertube +POSTGRES_DB={{database_databasename}} +PEERTUBE_DB_USERNAME={{database_username}} PEERTUBE_DB_PASSWORD={{peertube_database_password}} PEERTUBE_DB_SSL=false -PEERTUBE_DB_HOSTNAME=database +PEERTUBE_DB_HOSTNAME={{database_host}} # PeerTube server configuration PEERTUBE_WEBSERVER_HOSTNAME={{domain}} diff --git a/roles/docker-peertube/vars/main.yml b/roles/docker-peertube/vars/main.yml index 2eec12de..90aa77e9 100644 --- a/roles/docker-peertube/vars/main.yml +++ b/roles/docker-peertube/vars/main.yml @@ -1 +1,6 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}peertube/" +database_instance: "peertube" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{peertube_database_password}}" \ No newline at end of file diff --git a/roles/docker-pixelfed/templates/docker-compose.yml.j2 b/roles/docker-pixelfed/templates/docker-compose.yml.j2 index e7b910c4..73c30fc7 100644 --- a/roles/docker-pixelfed/templates/docker-compose.yml.j2 +++ b/roles/docker-pixelfed/templates/docker-compose.yml.j2 @@ -38,20 +38,9 @@ services: interval: 60s timeout: 5s retries: 1 - database: - logging: - driver: journald - image: mariadb - restart: always - env_file: - - ./env - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=pixelfed --password={{pixelfed_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 + +{% include 'templates/docker-mariadb-service.yml.j2' %} + redis: image: redis:alpine restart: always diff --git a/roles/docker-pixelfed/vars/main.yml b/roles/docker-pixelfed/vars/main.yml index 18e0fd57..784e64d4 100644 --- a/roles/docker-pixelfed/vars/main.yml +++ b/roles/docker-pixelfed/vars/main.yml @@ -1,2 +1,7 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}pixelfed/" nginx_docker_reverse_proxy_extra_configuration: "client_max_body_size 512M;" +database_instance: "pixelfed" +database_host: "{{database_instance}}" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{pixelfed_database_password}}" diff --git a/roles/docker-wordpress/templates/docker-compose.yml.j2 b/roles/docker-wordpress/templates/docker-compose.yml.j2 index dc8f9ec9..3f4d6946 100644 --- a/roles/docker-wordpress/templates/docker-compose.yml.j2 +++ b/roles/docker-wordpress/templates/docker-compose.yml.j2 @@ -11,34 +11,19 @@ services: ports: - "127.0.0.1:{{http_port}}:80" environment: - WORDPRESS_DB_HOST: database:3306 - WORDPRESS_DB_USER: "wordpress" - WORDPRESS_DB_PASSWORD: "{{wordpress_database_password}}" - WORDPRESS_DB_NAME: "wordpress" + WORDPRESS_DB_HOST: "{{database_host}}:3306" + WORDPRESS_DB_USER: "{{database_username}}" + WORDPRESS_DB_PASSWORD: "{{database_password}}" + WORDPRESS_DB_NAME: "{{database_databasename}}" links: - database volumes: - data:/var/www/html depends_on: - database - database: - logging: - driver: journald - image: mariadb - restart: always - environment: - MYSQL_DATABASE: "wordpress" - MYSQL_USER: "wordpress" - MYSQL_PASSWORD: "{{wordpress_database_password}}" - MYSQL_ROOT_PASSWORD: "{{wordpress_database_password}}" - MARIADB_AUTO_UPGRADE: "1" - volumes: - - database:/var/lib/mysql - healthcheck: - test: "/usr/bin/mariadb --user=wordpress --password={{wordpress_database_password}} --execute \"SHOW DATABASES;\"" - interval: 3s - timeout: 1s - retries: 5 + +{% include 'templates/docker-mariadb-service.yml.j2' %} + volumes: database: data: diff --git a/roles/docker-wordpress/vars/main.yml b/roles/docker-wordpress/vars/main.yml index 61f40599..fd355179 100644 --- a/roles/docker-wordpress/vars/main.yml +++ b/roles/docker-wordpress/vars/main.yml @@ -1,2 +1,7 @@ docker_compose_instance_directory: "{{path_docker_compose_instances}}wordpress/" wordpress_max_upload_size: "64M" +database_instance: "wordpress" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{wordpress_database_password}}" \ No newline at end of file diff --git a/roles/docker-yourls/vars/main.yml b/roles/docker-yourls/vars/main.yml index 02676317..0efb2c45 100644 --- a/roles/docker-yourls/vars/main.yml +++ b/roles/docker-yourls/vars/main.yml @@ -1 +1,6 @@ -docker_compose_instance_directory: "{{path_docker_compose_instances}}yourls/" \ No newline at end of file +docker_compose_instance_directory: "{{path_docker_compose_instances}}yourls/" +database_instance: "yourls" +database_host: "database" +database_databasename: "{{database_instance}}" +database_username: "{{database_instance}}" +database_password: "{{yourls_database_password}}" \ No newline at end of file diff --git a/templates/docker-mariadb-service.yml.j2 b/templates/docker-mariadb-service.yml.j2 new file mode 100644 index 00000000..38130425 --- /dev/null +++ b/templates/docker-mariadb-service.yml.j2 @@ -0,0 +1,18 @@ + database: + logging: + driver: journald + image: mariadb + restart: always + environment: + MYSQL_DATABASE: "{{database_databasename}}" + MYSQL_USER: "{{database_username}}" + MYSQL_PASSWORD: "{{database_password}}" + MYSQL_ROOT_PASSWORD: "{{database_password}}" + MARIADB_AUTO_UPGRADE: "1" + volumes: + - database:/var/lib/mysql + healthcheck: + test: "/usr/bin/mariadb --user={{database_username}} --password={{database_password}} --execute \"SHOW DATABASES;\"" + interval: 3s + timeout: 1s + retries: 5 \ No newline at end of file