diff --git a/Dockerfile b/Dockerfile index 075ee32..28593c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ ENV SAFEWAY_ACCOUNT_USERNAME= ENV SAFEWAY_ACCOUNT_PASSWORD= ENV SAFEWAY_ACCOUNT_MAIL_FROM= ENV SAFEWAY_ACCOUNT_MAIL_TO= +ENV SAFEWAY_ACCOUNTS_FILE= RUN apk add --no-cache tini COPY docker/entrypoint / diff --git a/README.md b/README.md index b7a7152..d89f409 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ so they don't have to each be clicked manually. ## Installation and usage with Docker A Docker container is provided which runs safeway-coupons with cron. The cron -schedule and your Safeway account details should be configured using environment -variables. +schedule and your Safeway account details may be configured using environment +variables, or with an accounts file. -Example `docker-compose.yaml`: +Example `docker-compose.yaml` with configuration via environment variables: ```yaml version: "3.7" @@ -34,6 +34,23 @@ services: restart: unless-stopped ``` +Example `docker-compose.yaml` with configuration via accounts file: + +```yaml +version: "3.7" + +services: + safeway-coupons: + image: ghcr.io/smkent/safeway-coupons:latest + environment: + CRON_SCHEDULE: "0 2 * * *" # Run at 2:00 AM each day + SMTPHOST: your.smtp.host + SAFEWAY_ACCOUNTS_FILE: /accounts_file + restart: unless-stopped + volumes: + - path/to/safeway_accounts_file:/accounts_file:ro +``` + Start the container by running: ```console diff --git a/docker-compose.accounts-config.yaml b/docker-compose.accounts-config.yaml new file mode 100644 index 0000000..3ea7c62 --- /dev/null +++ b/docker-compose.accounts-config.yaml @@ -0,0 +1,12 @@ +version: "3.7" + +services: + safeway-coupons: + image: ghcr.io/smkent/safeway-coupons:latest + environment: + CRON_SCHEDULE: "0 2 * * *" + SMTPHOST: your.smtp.host + SAFEWAY_ACCOUNTS_FILE: /accounts_file + restart: unless-stopped + volumes: + - path/to/safeway_accounts_file:/accounts_file:ro diff --git a/docker/entrypoint b/docker/entrypoint index d48ba74..c5d21ec 100755 --- a/docker/entrypoint +++ b/docker/entrypoint @@ -2,25 +2,30 @@ set -ex -if [ -z "${SAFEWAY_ACCOUNT_MAIL_TO}" ] \ - && [ -n "${SAFEWAY_ACCOUNT_USERNAME}" ]; then - export SAFEWAY_ACCOUNT_MAIL_TO="${SAFEWAY_ACCOUNT_USERNAME}" -fi - -if [ -n "${SAFEWAY_ACCOUNT_MAIL_FROM}" ]; then - export MAILFROM="${SAFEWAY_ACCOUNT_MAIL_FROM}" -fi -if [ -n "${SAFEWAY_ACCOUNT_MAIL_TO}" ]; then - export MAILFROM="${SAFEWAY_ACCOUNT_MAIL_TO}" +args= +if [ -n "${SAFEWAY_ACCOUNTS_FILE}" ]; then + echo "Using accounts file at ${SAFEWAY_ACCOUNTS_FILE} for configuration" + args="--accounts-config ${SAFEWAY_ACCOUNTS_FILE}" +else + echo "Using environment variables for configuration" + if [ -z "${SAFEWAY_ACCOUNT_MAIL_TO}" ] \ + && [ -n "${SAFEWAY_ACCOUNT_USERNAME}" ]; then + export SAFEWAY_ACCOUNT_MAIL_TO="${SAFEWAY_ACCOUNT_USERNAME}" + fi + if [ -n "${SAFEWAY_ACCOUNT_MAIL_FROM}" ]; then + export MAILFROM="${SAFEWAY_ACCOUNT_MAIL_FROM}" + fi + if [ -n "${SAFEWAY_ACCOUNT_MAIL_TO}" ]; then + export MAILFROM="${SAFEWAY_ACCOUNT_MAIL_TO}" + fi + env | grep -vie 'password' | grep -e '^SAFEWAY_' -e '^SMTPHOST=' fi mkdir /etc/cron.d ( - echo "${CRON_SCHEDULE?} safeway-coupons >/proc/1/fd/1 2>/proc/1/fd/2" + echo "${CRON_SCHEDULE?} safeway-coupons ${args} >/proc/1/fd/1 2>/proc/1/fd/2" ) > /var/spool/cron/crontabs/root -env | grep -vie 'password' | grep -e '^SAFEWAY_' -e '^SMTPHOST=' - crontab -l exec crond -f -d 8