From 10137f355b169dd6da6d4dc6a41a86897ad112e6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 1 Nov 2020 10:35:30 +0100 Subject: [PATCH] Further thrasing with env var and config passing --- .envrc.sample | 38 +++++++++++++++++++++++++++++++++- app_config.yml.tmpl | 20 +++++++++--------- compose.yml | 50 +++++++++++++++++++++++++++++++++++++-------- database.yml.tmpl | 7 +++++++ 4 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 database.yml.tmpl diff --git a/.envrc.sample b/.envrc.sample index 31d87be..2f1488c 100644 --- a/.envrc.sample +++ b/.envrc.sample @@ -1 +1,37 @@ -export FOODSOFT_VERSION=4.7.0 +export APP=foodsoft + +export DOMAIN=order.biobulkbende.org +export LETS_ENCRYPT_ENV=production + +export FOODCOOP_NAME=biobulkbende +export FOODCOOP_CITY=Rotterdam +export FOODCOOP_COUNTRY=The Netherlands +export FOODCOOP_EMAIL=info@biobulkbende.org +export FOODCOOP_PHONE="+31684233964" +export FOODCOOP_STREET="Almondestraat 157" +export FOODCOOP_ZIP_CODE=3032CD +export FOODCOOP_HOMEPAGE=https://order.biobulkbende.org +export FOODCOOP_HELP_URL=https://order.biobulkbende.org +export FOODCOOP_TIME_ZONE=Amsterdam +export FOODCOOP_FOOTER="Biobulkbende hosted by Autonomic Cooperative." + +export MYSQL_NAME=foodsoft +export MYSQL_HOST=mariadb +export MYSQL_PORT=3306 +export MYSQL_USER=foodsoft + +export EMAIL_SENDER=foodsoft@biobulkbende.org +export EMAIL_REPLY=foodsoft@biobulkbende.org +export ERROR_EMAIL=systems@biobulkbende.org + +export SHARED_LISTS_DB_TYPE=mysql2 +export SHARED_LISTS_HOST=order.voedselcollectief.org +export SHARED_LISTS_DB_NAME=sharedlists +export SHARED_LISTS_USER=biobulkbende + +export DB_PASSWORD_VERSION=v1 +export DB_ROOT_PASSWD_VERSION=v1 +export SHARED_LISTS_DB_PASSWD_VERSION=v1 + +export APP_CONFIG_VERSION=v1 +export DB_CONFIG_VERSION=v1 diff --git a/app_config.yml.tmpl b/app_config.yml.tmpl index 3ad0b78..c8ee6d8 100644 --- a/app_config.yml.tmpl +++ b/app_config.yml.tmpl @@ -121,10 +121,10 @@ default: &defaults # ...... # email address to be used as sender - email_sender: "{{ env "FOODCOOP_EMAIL_SENDER" }}" + email_sender: "{{ env "EMAIL_SENDER" }}" # domain to be used for reply emails - reply_email_domain: "{{ env "FOODCOOP_EMAIL_REPLY" }}" + reply_email_domain: "{{ env "EMAIL_REPLY" }}" # If your foodcoop uses a mailing list instead of internal messaging system #mailing_list: list@example.org @@ -133,13 +133,13 @@ default: &defaults # Config for the exception_notification plugin notification: error_recipients: - - "{{ env "FOODCOOP_ERROR_MAIL" }}" - sender_address: "\"Foodsoft Error\" <{{ env "FOODCOP_EMAIL_SENDER" }}>" + - "{{ env "EMAIL_ERROR" }}" + sender_address: "\"Foodsoft Error\" <{{ env "EMAIL_SENDER" }}>" email_prefix: "[Foodsoft]" # http config for this host to generate links in emails (uses environment config when not set) protocol: https - host: "{{ env "FOODCOOP_HOST" }}" + host: "{{ env "DOMAIN" }}" #port: 3000 # Access to sharedlists, the external article-database. @@ -147,11 +147,11 @@ default: &defaults # and makes it possible to share data with several foodcoops. Using this requires installing # an additional application with a separate database. shared_lists: - adapter: "{{ env "FOODCOOP_SHARED_LISTS_DB_TYPE" }}" - host: "{{ env "FOODCOOP_SHARED_LISTS_HOST" }}" - database: "{{ env "FOODCOOP_SHARED_LISTS_DB_NAME" }}" - username: "{{ env "FOODCOOP_SHARED_LISTS_USERNAME" }}" - password: "{{ secret "shared_lists_db_password" }}" + adapter: "{{ env "SHARED_LISTS_DB_TYPE" }}" + host: "{{ env "SHARED_LISTS_HOST" }}" + database: "{{ env "SHARED_LISTS_DB_NAME" }}" + username: "{{ env "SHARED_LISTS_USER" }}" + password: "{{ secret "shared_lists_db_passwd" }}" # don't remove this, required to run the app production: diff --git a/compose.yml b/compose.yml index c9ada99..4a990be 100644 --- a/compose.yml +++ b/compose.yml @@ -3,10 +3,37 @@ version: "3.8" services: app: - image: foodcoops/foodsoft:${FOODSOFT_VERSION} + image: "foodcoops/foodsoft:4.7.0" networks: - internal - proxy + secrets: + - db_passwd + - shared_lists_db_passwd + environment: + - DOMAIN + - EMAIL_ERROR + - EMAIL_REPLY + - EMAIL_SENDER + - FOODCOOP_CITY + - FOODCOOP_COUNTRY + - FOODCOOP_EMAIL + - FOODCOOP_FOOTER + - FOODCOOP_HELP_URL + - FOODCOOP_HOMEPAGE + - FOODCOOP_NAME + - FOODCOOP_PHONE + - FOODCOOP_STREET + - FOODCOOP_TIME_ZONE + - FOODCOOP_ZIP_CODE + - MYSQL_HOST=db + - MYSQL_NAME=foodsoft + - MYSQL_PORT=3306 + - MYSQL_USER=foodsoft + - SHARED_LISTS_DB_NAME + - SHARED_LISTS_DB_TYPE + - SHARED_LISTS_HOST + - SHARED_LISTS_USER deploy: update_config: failure_action: rollback @@ -16,16 +43,16 @@ services: - "traefik.http.routers.foodsoft.rule=Host(`${DOMAIN}`)" - "traefik.http.routers.foodsoft.entrypoints=web-secure" - "traefik.http.services.foodsoft.loadbalancer.server.port=3000" - - "traefik.http.routers.foodsoft.tls.certresolver=production" + - "traefik.http.routers.foodsoft.tls.certresolver=${LETS_ENCRYPT_ENV}" cron: - image: foodcoops/foodsoft:${FOODSOFT_VERSION} + image: "foodcoops/foodsoft:4.7.0" command: ./proc-start cron networks: - internal worker: - image: foodcoops/foodsoft:${FOODSOFT_VERSION} + image: "foodcoops/foodsoft:4.7.0" command: ./proc-start worker networks: - internal @@ -48,7 +75,7 @@ services: - internal cache: - image: redis:6 + image: "redis:6" networks: internal: @@ -60,14 +87,21 @@ volumes: configs: app_config: - name: ${APP_CONFIG_VERSION} + name: ${STACK_NAME}_app_config_${APP_CONFIG_VERSION} file: app_config.yml.tmpl template_driver: golang + db_config: + name: ${STACK_NAME}_db_config_${DB_CONFIG_VERSION} + file: database.yml.tmpl + template_driver: golang secrets: db_passwd: - name: ${DB_PASSWD_VERSION} + name: ${STACK_NAME}_db_passwd_${DB_PASSWORD_VERSION} external: true db_root_passwd: - name: ${DB_ROOT_PASSWD_VERSION} + name: ${STACK_NAME}_db_root_passwd_${DB_ROOT_PASSWD_VERSION} + external: true + shared_lists_db_passwd: + name: ${STACK_NAME}_shared_lists_db_passwd_${SHARED_LISTS_DB_PASSWD_VERSION} external: true diff --git a/database.yml.tmpl b/database.yml.tmpl new file mode 100644 index 0000000..a4b989d --- /dev/null +++ b/database.yml.tmpl @@ -0,0 +1,7 @@ +production: + adapter: mysql2 + database: "{{ env "MYSQL_NAME" }}" + host: "{{ env "MYSQL_HOST" }}" + password: "{{ secret "db_passwd" }}" + port: "{{ env "MYSQL_PORT" }}" + username: "{{ env "MYSQL_USER" }}"