From 6f77e662d58d5b12443e108782ab2815f63ad393 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Wed, 23 Sep 2020 13:35:54 +0200 Subject: [PATCH] Working postgres container --- compose.yml | 67 +++++++++++++++++++++++++++++++++++++++++++--- entrypoint.sh.tmpl | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 entrypoint.sh.tmpl diff --git a/compose.yml b/compose.yml index cd8c989..dba1d73 100644 --- a/compose.yml +++ b/compose.yml @@ -1,12 +1,24 @@ -version: '3.3' +--- +version: '3.8' services: + postgres: + image: "postgres:9.6.5" + volumes: + - "postgres:/var/lib/postgresql/data" + networks: + - internal + environment: + POSTGRES_USER: selfoss + POSTGRES_PASSWORD_FILE: /run/secrets/db_password + POSTGRES_DB: selfoss + secrets: + - db_password + selfoss: image: akito13/selfoss volumes: - selfoss:/selfoss/data - networks: - - proxy deploy: labels: - traefik.enable=true @@ -18,10 +30,59 @@ services: - traefik.http.routers.${STACK_NAME}-https.tls=true - traefik.http.routers.${STACK_NAME}-https.tls.certresolver=${LETS_ENCRYPT_ENV} - traefik.http.services.${STACK_NAME}.loadbalancer.server.port=8888 + update_config: + failure_action: rollback + order: start-first + environment: + - SELFOSS_USERNAME + - SELFOSS_PASSWORD + #- SELFOSS_PASSWORD_FILE=/run/secrets/selfoss_password + - SELFOSS_DB_TYPE + - SELFOSS_LOGGER_LEVEL + - SELFOSS_DB_HOST="postgres" + - SELFOSS_DB_NAME="selfoss" + - SELFOSS_DB_USERNAME="selfoss" + - SELFOSS_DB_PASSWORD_FILE=/run/secrets/db_password + secrets: + - db_password + #- selfoss_password + entrypoint: /docker-entrypoint.sh + #entrypoint: ['tail', '-f', '/dev/null'] + configs: + - source: entrypoint_conf + target: /docker-entrypoint.sh + mode: 0555 + networks: + - proxy + - internal + depends_on: + - postgres + #healthcheck: + # test: ["CMD", "wget", "-f" "http://localhost:8888"] + # interval: 30s + # timeout: 10s + # retries: 10 + # start_period: 1m networks: proxy: external: true + internal: volumes: selfoss: + postgres: + +secrets: + db_password: + external: true + name: ${STACK_NAME}_db_password_${DB_PASSWORD_VERSION} + #selfoss_password: + # external: true + # name: ${STACK_NAME}_selfoss_password_${SELFOSS_PASSWORD_VERSION} + +configs: + entrypoint_conf: + name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_CONF_VERSION} + file: entrypoint.sh.tmpl + template_driver: golang diff --git a/entrypoint.sh.tmpl b/entrypoint.sh.tmpl new file mode 100644 index 0000000..da48e3c --- /dev/null +++ b/entrypoint.sh.tmpl @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +configure_php() { + if ! grep -q '^clear_env = no' /etc/php7/php-fpm.d/www.conf; then + sed -i 's/;clear_env = no/clear_env = no/' /etc/php7/php-fpm.d/www.conf + fi + if ! grep -q '^clear_env = no' /etc/php7/php-fpm.conf; then + echo 'clear_env = no' >> /etc/php7/php-fpm.conf + fi + if ! grep -q 'variables_order = "EGPCS"' /etc/php7/php.ini; then + sed -i 's/variables_order = "GPCS"/variables_order = "EGPCS"/g' \ + /etc/php7/php.ini + fi +} + +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + export "$var"="$val" + unset "$fileVar" +} + +load_vars() { + file_env "SELFOSS_PASSWORD" + file_env "SELFOSS_DB_PASSWORD" +} + +main() { + set -eu + + configure_php + load_vars +} + +main + +run.sh