diff --git a/Dockerfile b/Dockerfile index d4d9ba0..c9ee8a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,9 @@ COPY dockerbuild/vhost.conf /etc/apache2/sites-enabled/ # ErrorLog inside a VirtualHost block is ineffective for unknown reasons RUN sed -i -E 's@ErrorLog .*@ErrorLog /proc/self/fd/2@i' /etc/apache2/apache2.conf +ADD https://github.com/silinternational/config-shim/releases/latest/download/config-shim.gz config-shim.gz +RUN gzip -d config-shim.gz && chmod 755 config-shim && mv config-shim /usr/local/bin + EXPOSE 80 CMD ["/data/run.sh"] diff --git a/README.md b/README.md index 98f833b..bb65fac 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,26 @@ Simple service to queue and send emails 2. `make` 3. Upon successful initialization, the API will be available locally at `http://localhost:8080/email` +## Configuration +By default, configuration is read from environment variables. These are documented +in the `local.env.dist` file. Optionally, you can define configuration in AWS AppConfig. +To do this, set the following environment variables to point to the configuration in +AWS: + +* `AWS_REGION` - the AWS region in use +* `APP_ID` - the application ID or name +* `CONFIG_ID` - the configuration profile ID or name +* `ENV_ID` - the environment ID or name + +In addition, the AWS API requires authentication. It is best to use an access role +such as an [ECS Task Role](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html). +If that is not an option, you can specify an access token using the `AWS_ACCESS_KEY_ID` and +`AWS_SECRET_ACCESS_KEY` variables. + +The content of the configuration profile takes the form of a typical .env file, using +`#` for comments and `=` for variable assignment. Any variables read from AppConfig +will overwrite variables set in the execution environment. + ## API See [api.raml](api.raml) for API docs. diff --git a/application/common/config/main.php b/application/common/config/main.php index 58343b0..9572973 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -15,7 +15,7 @@ $mysqlDatabase = Env::requireEnv('MYSQL_DATABASE'); $mysqlUser = Env::requireEnv('MYSQL_USER'); $mysqlPassword = Env::requireEnv('MYSQL_PASSWORD'); -$notificationEmail = Env::requireEnv('NOTIFICATION_EMAIL'); +$notificationEmail = Env::get('NOTIFICATION_EMAIL'); $emailQueueBatchSize = Env::get('EMAIL_QUEUE_BATCH_SIZE', 10); $mailerUseFiles = Env::get('MAILER_USEFILES', false); @@ -71,6 +71,7 @@ 'exportInterval' => 1, ], [ + 'enabled' => !empty($notificationEmail), 'class' => EmailTarget::class, 'except' => [ 'yii\web\HttpException:400', diff --git a/application/run-cron.sh b/application/run-cron.sh index 3ea3f71..58a15e8 100755 --- a/application/run-cron.sh +++ b/application/run-cron.sh @@ -35,5 +35,8 @@ if [[ $rc != 0 ]]; then fi # Run apache in foreground -apache2ctl -D FOREGROUND - +if [[ -z "${APP_ID}" ]]; then + apache2ctl -k start -D FOREGROUND +else + config-shim --app $APP_ID --config $CONFIG_ID --env $ENV_ID apache2ctl -k start -D FOREGROUND +fi diff --git a/application/run.sh b/application/run.sh index ef62ffb..9fbb667 100755 --- a/application/run.sh +++ b/application/run.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash # Run apache in foreground -apache2ctl -D FOREGROUND +if [[ -z "${APP_ID}" ]]; then + apache2ctl -k start -D FOREGROUND +else + config-shim --app $APP_ID --config $CONFIG_ID --env $ENV_ID apache2ctl -k start -D FOREGROUND +fi diff --git a/local.env.dist b/local.env.dist index 9cba792..1a9ac2a 100644 --- a/local.env.dist +++ b/local.env.dist @@ -12,6 +12,22 @@ API_ACCESS_KEYS=abc123 APP_NAME=email-service + +# === AWS AppConfig (optional) === + +# The AWS region in use +#AWS_REGION= + +# The AppConfig Application ID (or name) +#APP_ID= + +# The AppConfig Configuration Profile ID (or name) +#CONFIG_ID= + +# The AppConfig Environment ID (or name) +#ENV_ID= + + # mailer configuration for SMTP MAILER_HOST= MAILER_USERNAME=