From 1ae02b81c462ca79a8e7c172dc08290289d607a2 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 8 Nov 2020 17:41:18 +0100 Subject: [PATCH] Use multi-service entrypoint --- compose.yml | 25 +++++++++++++++++++------ entrypoint.sh.tmpl | 34 ++++++++++------------------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/compose.yml b/compose.yml index 94fc38f..ca24cd7 100644 --- a/compose.yml +++ b/compose.yml @@ -36,8 +36,9 @@ services: - FOODCOOP_STREET - FOODCOOP_TIME_ZONE - FOODCOOP_ZIP_CODE - - MYSQL_HOST=db + - FOODSOFT_SERVICE=app - MYSQL_DB=foodsoft + - MYSQL_HOST=db - MYSQL_PORT=3306 - MYSQL_USER=foodsoft - QUEUE=foodsoft_notifier @@ -67,8 +68,8 @@ services: cron: image: "foodcoops/foodsoft:4.7.0" - command: ./proc-start cron environment: + - FOODSOFT_SERVICE=cron - MYSQL_DB - MYSQL_HOST - MYSQL_PORT @@ -76,6 +77,10 @@ services: configs: - source: db_config target: /usr/src/app/config/database.yml + - source: entrypoint + target: /usr/src/app/docker-entrypoint.sh + mode: 0555 + entrypoint: /usr/src/app/docker-entrypoint.sh secrets: - db_password networks: @@ -83,8 +88,8 @@ services: worker: image: "foodcoops/foodsoft:4.7.0" - command: ./proc-start worker environment: + - FOODSOFT_SERVICE=worker - MYSQL_DB - MYSQL_HOST - MYSQL_PORT @@ -92,6 +97,10 @@ services: configs: - source: db_config target: /usr/src/app/config/database.yml + - source: entrypoint + target: /usr/src/app/docker-entrypoint.sh + mode: 0555 + entrypoint: /usr/src/app/docker-entrypoint.sh secrets: - db_password networks: @@ -99,19 +108,23 @@ services: smtp: image: "foodcoops/foodsoft:4.7.0" - command: ./proc-start mail configs: - source: db_config target: /usr/src/app/config/database.yml + - source: entrypoint + target: /usr/src/app/docker-entrypoint.sh + mode: 0555 + entrypoint: /usr/src/app/docker-entrypoint.sh secrets: - db_password environment: - - SMTP_SERVER_PORT - - SMTP_SERVER_HOST + - FOODSOFT_SERVICE=worker - MYSQL_DB - MYSQL_HOST - MYSQL_PORT - MYSQL_USER + - SMTP_SERVER_HOST + - SMTP_SERVER_PORT networks: - internal diff --git a/entrypoint.sh.tmpl b/entrypoint.sh.tmpl index 3a80df0..c9eb839 100644 --- a/entrypoint.sh.tmpl +++ b/entrypoint.sh.tmpl @@ -23,31 +23,17 @@ file_env() { unset "$fileVar" } -load_vars() { - file_env "SECRET_KEY_BASE" - file_env "SMTP_PASSWORD" -} +file_env "SECRET_KEY_BASE" +file_env "SMTP_PASSWORD" -re_use() { - if [ -f tmp/pids/server.pid ]; then - rm tmp/pids/server.pid - fi -} - -db_setup() { +if [ "$FOODSOFT_SERVICE" == "app" ]; then bundle exec rake db:setup -} - -db_migrate() { bundle exec rake db:migrate -} - -run_web(){ ./proc-start web -} - -re_use -load_vars -db_setup -db_migrate -run_web +elif [ "$FOODSOFT_SERVICE" == "cron" ]; then + ./proc-start cron +elif [ "$FOODSOFT_SERVICE" == "worker" ]; then + ./proc-start worker +elif [ "$FOODSOFT_SERVICE" == "mail" ]; then + ./proc-start mail +fi