Skip to content

Fix container timezone#1768

Merged
sameersbn merged 3 commits intosameersbn:masterfrom
gjrtimmer:fix-timezone
Jul 3, 2021
Merged

Fix container timezone#1768
sameersbn merged 3 commits intosameersbn:masterfrom
gjrtimmer:fix-timezone

Conversation

@gjrtimmer
Copy link
Contributor

@gjrtimmer gjrtimmer commented Nov 8, 2018

Gitlab can have a different timezone in relation to the container

Introduction

Default the containers run with timezone set to UTC, which means that the cron daemon can be using a different timezone than gitlab, because the timezone from gitlab can be configured with GITLAB_TIMEZONE.

Use case

My current TimeZone is Europe/Amsterdam Gitlab has the corrent time, but because the container time is UTC it means that the cron daemon which runs the backups does this ` hour to early.

Provided solution

  • ADDED
    • configure_container_timezone() -> assets/runtime/functions
  • MODIFY
    • Added configure_container_timezone() to function configure_system() before the function install_configuration_templates because timezone is a lower level then templates.
    • README
      • ADD: Variable TZ
      • UPD: Variable GITLAB_TIMZONE

configure_container_timezone()

The provided function has a sanity check which will use UTC as default. The sanity check will check that the user provided value is a valid timezone, by checking if the provided timezone exists within the tzdata zoneinfo.

Configuration

Container TimeZone will use the environment variable TZ, and defaults to UTC. The variable TZ expects values in Canonical format. Link to acceptable values has been added to the README. The format which is expected causes that the GITLAB_TIMEZONE cannot be used here because GITLAB_TIMEZONE can accept timezone in different formats.

@gjrtimmer
Copy link
Contributor Author

@solidnerd Request review

@splattael
Copy link
Contributor

@gjrtimmer Thanks for the PR!

Would mounting /etc/localtime into the container have the same effect? E.g. -v /etc/localtime:/etc/localtime:ro?

@gjrtimmer
Copy link
Contributor Author

@splattael Never tested that, and I don't know if it would be a solution. I think there would be quite a few situations where there is a complete different timezone between the containers and the host. With this fix it the container will get the correct timezone. Got this fix from docker on how to set the container timezone correctly by using the TZ variable.

This image might even be used by parties that are hosting gitlab environments for clients in different timezone. So I don't want to mount the localtime from the host I want to set it correctly.

@gjrtimmer gjrtimmer changed the title Fix: container timezone Fix container timezone Nov 10, 2018
@gjrtimmer
Copy link
Contributor Author

@solidnerd @sameersbn Any Update

@gjrtimmer
Copy link
Contributor Author

Rebased on new master

@gjrtimmer
Copy link
Contributor Author

@solidnerd Rebased on new master

@gjrtimmer
Copy link
Contributor Author

@solidnerd Rebased to 11.5.0

@gjrtimmer
Copy link
Contributor Author

Rebased to 11.5.1

@gjrtimmer
Copy link
Contributor Author

@solidnerd rebased

gjrtimmer referenced this pull request in gjrtimmer/docker-gitlab Dec 13, 2018
@gjrtimmer gjrtimmer force-pushed the fix-timezone branch 2 times, most recently from 90759c9 to 2a00b8a Compare January 10, 2019 11:38
@gjrtimmer
Copy link
Contributor Author

@solidnerd Rebased

@drubin
Copy link
Contributor

drubin commented Feb 27, 2019

@gjrtimmer Hi is there a reason you don't just set the TZ env variable?
http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

We have been using this since we started and we don't have issues with timezones/cron.

@sameersbn
Copy link
Owner

sorry about the delay in attending to this PR. I really have no issues getting it merged but I am just curious to know if there is a use-case that just setting the TZ env variable is not suffice?

@gjrtimmer
Copy link
Contributor Author

gjrtimmer commented Oct 2, 2020

sorry about the delay in attending to this PR. I really have no issues getting it merged but I am just curious to know if there is a use-case that just setting the TZ env variable is not suffice?

Sorry for the delay; I have environment variable TZ=Europe/Amsterdam set on the container. Still the shell is not reporting the current correct time which results that for example my backup files have an offset of 2 hours because of GMT+2 (Daylight Saving Time).

Proposed PR would fix that; as noted in the change in the README; this PR will also fix the timestamp being used within the CRON.

@gjrtimmer
Copy link
Contributor Author

@solidnerd @sameersbn Rebased & Implemented conversation suggestion

@gjrtimmer
Copy link
Contributor Author

@solidnerd @sameersbn Why is the build not completing ?

@sameersbn
Copy link
Owner

needs a rebase.

Fix Container TimeZone


Fix Container TimeZone
@gjrtimmer
Copy link
Contributor Author

@sameersbn Rebased, very sorry for the delay

@sameersbn sameersbn merged commit 0341e15 into sameersbn:master Jul 3, 2021
@gjrtimmer gjrtimmer deleted the fix-timezone branch November 26, 2023 04:15
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.

4 participants