From a716639a6c1468eec11f0b930c825c2991e99412 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Fri, 6 Mar 2020 20:58:32 +0100 Subject: [PATCH] Implement time zone support. --- CHANGELOG.md | 7 +++++++ Dockerfile | 6 +++++- README.md | 14 ++++++++++++++ docker-compose.yml | 1 + dora-banner.sh | 1 + set-timezone.sh | 6 ++++++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 set-timezone.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index c726497..5e0e1f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # dora changelog +## Version 1.2.0 (2020-03-06) + +### New feature + +- Configure the container's time zone using the `$TIMEZONE` environment + variable. + ## Version 1.1.0 (2020-03-06) ### New feature diff --git a/Dockerfile b/Dockerfile index bcbe756..6edd95c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ ENV RAILS_DB_HOST "" ENV RAILS_DB_NAME ${APP_NAME} ENV RAILS_DB_USER ${APP_NAME} ENV RAILS_DB_PASS "" +ENV TIMEZONE="UCT" ENV WKHTMLTOPDF "" ENV WKHTMLTOPDF_URL "https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb" ENV WKHTMLTOPDF_SUM "db48fa1a043309c4bfe8c8e0e38dc06c183f821599dd88d4e3cea47c5a5d4cd3" @@ -30,7 +31,8 @@ RUN /pd_build/nodejs.sh # Install yarn RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\ echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list &&\ - apt-get update && apt-get install yarn + apt-get update &&\ + apt-get install -y --no-install-recommends yarn tzdata # This is from passenger-docker's README. ENV HOME /root @@ -57,6 +59,8 @@ ADD bootstrap-container.sh /etc/my_init.d/10_bootstrap_container.sh RUN chmod +x /etc/my_init.d/10_bootstrap_container.sh ADD install-wkhtmltopdf.sh /etc/my_init.d/90_install_wkhtmltopdf.sh RUN chmod +x /etc/my_init.d/90_install_wkhtmltopdf.sh +ADD set-timezone.sh /etc/my_init.d/01_set_timezone.sh +RUN chmod +x /etc/my_init.d/01_set_timezone.sh RUN mkdir -p /etc/service/sidekiq ADD run-sidekiq.sh /etc/service/sidekiq/run diff --git a/README.md b/README.md index 37c34ef..be645a0 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Customization is mostly done with environment variables. | `RAILS_SMTP_USER` | SMTP user name | `$APP_NAME` | `RAILS_SMTP_PASS` | SMTP password | | `SECRET_KEY_BASE` | Rails' secret key base | +| `TIMEZONE` | Time zone of the container | `UCT` | `NO_WKHTMLTOPDF` | Do not attempt to install [wkhtmltopdf][] | (empty) | `WKHTMLTOPDF_URL` | Download URL for [wkhtmltopdf][] | @@ -332,6 +333,19 @@ via environment variables. A `.env` file lends itself well to this configuration. The composition consists of the rails app, Postgres, and Redis. See `sample.env` for usage instructions. +## Container time zone + +`passenger-docker` does not configure a time zone for the container. Dora does +do it by installing the `tzdata` package and supporting a `$TIMEZONE` variable. +This variable _must_ be set to a directory and file unter `/usr/share/zoneinfo`, +e.g. `Europe/Berlin`. + +To see all possible values for `$TIMEZONE`, issue: + +```bash +find /usr/share/zoneinfo -follow | sed -E 's_(/[^/]+){3}/__' +``` + ## Troubleshooting ### Sending mail diff --git a/docker-compose.yml b/docker-compose.yml index d007f04..bfddee9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,7 @@ services: - RAILS_DB_NAME - RAILS_DB_USER - RAILS_DB_PASS + - TIMEZONE depends_on: - db - redis diff --git a/dora-banner.sh b/dora-banner.sh index 830de6d..3c4ccc6 100755 --- a/dora-banner.sh +++ b/dora-banner.sh @@ -29,6 +29,7 @@ echo "= RAILS_DB_PASS: $RAILS_DB_PASS" echo "= RAILS_SMTP_HOST: $RAILS_SMTP_HOST" echo "= RAILS_SMTP_USER: $RAILS_SMTP_USER" echo "= RAILS_SMTP_PASS: $RAILS_SMTP_PASS" +echo "= TIMEZONE: $TIMEZONE" echo "= NO_WKHTMLTOPDF: $NO_WKHTMLTOPDF" echo "= \`which wkhtmltopdf\`: $(which wkhtmltopdf)" echo diff --git a/set-timezone.sh b/set-timezone.sh new file mode 100644 index 0000000..7057f72 --- /dev/null +++ b/set-timezone.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +if [ "$TIMEZONE" != "" ]; then + echo "Setting time zone to $TIMEZONE" + ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime +fi