Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Set timezone to Europe/London (successfully, this time) #229

Merged
merged 2 commits into from
Apr 15, 2021
Merged

Conversation

sldblog
Copy link
Contributor

@sldblog sldblog commented Apr 8, 2021

What does this pull request do?

This PR fixes a 🐛 about setting the timezone to Europe/London in the Docker build.

As part of a set of conversations with @mahalrmoj we've discovered that the UI app is currently running on UTC:

$ k exec -ti hmpps-interventions-ui-5fc67cffcd-z4kgx --namespace=hmpps-interventions-dev -- date
Thu Apr  8 14:48:13 UTC 2021

How?

  • b6dc7cb adds a "build-time test" -- verifies that the timezone file in fact exists
  • 774f922 then installs the package that provides that timezone file

Result:

$ docker build --tag=ui .
...<snip>...

$ docker run --rm -ti ui date
Thu Apr  8 15:47:44 BST 2021

What is the intent behind these changes?

To make sure the service is running in Europe/London timezone. It has no material impact on our APIs, but it's the least surprising default :) -- At least it doesn't look like we're setting the timezone when we aren't.

We are currently running the application on UTC timezone because there
isn't any `/etc/localtime` file on the server

This change adds a (currently failing) build-time check for existence of
the timezone file we are trying to use
Fixes the build check introduced in the previous commit
@sldblog sldblog requested a review from a team April 8, 2021 14:52
@@ -7,7 +7,10 @@ FROM node:14-alpine3.13 as base
LABEL maintainer="HMPPS Digital Studio <[email protected]>"

ENV TZ=Europe/London
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
RUN apk add --no-cache tzdata && \
test -e "/usr/share/zoneinfo/$TZ" && \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this line, we could also add a "docker build test" that would test the timezone by running the date command:

$ docker run --rm -ti <built_tag> date | egrep "(GMT|BST)"
Thu Apr  8 15:55:29 BST 2021
# exit status 0

vs

$ k exec -ti hmpps-interventions-ui-5fc67cffcd-z4kgx -- date | egrep "(GMT|BST)"
# exit status 1, thus failing the build

However, this isn't trivial to chain after the docker build, before the push at the moment

@sldblog sldblog enabled auto-merge April 8, 2021 15:01
@lawrence-forooghian
Copy link
Contributor

lawrence-forooghian commented Apr 9, 2021

What impact does this have on the application? Do you have an example of how the container's time zone is affecting its behaviour?

Edit: I guess that from this you mean it doesn't affect the UI app?

It has no material impact on our APIs

@tomsmyers
Copy link
Contributor

without properly understanding the context - it doesn't seem appropriate to rely on the TZ of the container for anything at all. we have libraries already in use in this repo that allow formatting in whatever TZ you like. e.g.

    const ukDate = getZonedTime(date, findTimeZone('Europe/London'))

@sldblog
Copy link
Contributor Author

sldblog commented Apr 12, 2021

Apologies, I skimmed over a few important points

  1. The most important bit is fixing the false promise of the Dockerfile: it sets TZ to London, so if it does that, that should work.
  2. The second is that the service inherited this setting from the Kotlin template and it bothers my sense of consistency. It does have a suggestion open to switch to UTC by default. (Consider changing default timezone to UTC hmpps-template-kotlin#29)
  3. Distant third (I'm not precious about this) is what we get back from the "now" instant. We're deployed in the London region, not having to work in other countries, so it can be the same time we see on the clock. This is really minor though.

I'm perfectly happy to switch this to be explicitly UTC (and open a similar in the service) -- what do you prefer?

Copy link
Contributor

@tomsmyers tomsmyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with your comments david. we shouldn't rely on this, but setting it correctly can't be a bad thing.

@sldblog sldblog merged commit ec17cb7 into main Apr 15, 2021
@sldblog sldblog deleted the timezone branch April 15, 2021 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants