From 9bd03e122e9c0e9c4dc3c4683b834c4a3bd673ea Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 1 Aug 2023 14:47:53 +0200 Subject: [PATCH] [feature] Set timezone in Docker using TZ env variable (#2050) --- .goreleaser.yml | 2 ++ docs/getting_started/installation/container.md | 11 +++++++++++ example/docker-compose/docker-compose.yaml | 2 ++ scripts/build.sh | 3 ++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index e0ad1e5b1..743918c2c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -24,6 +24,8 @@ builds: - netgo - osusergo - static_build + - kvformat + - timetzdata env: - CGO_ENABLED=0 goos: diff --git a/docs/getting_started/installation/container.md b/docs/getting_started/installation/container.md index 9fd70485b..25e634607 100644 --- a/docs/getting_started/installation/container.md +++ b/docs/getting_started/installation/container.md @@ -51,6 +51,17 @@ If desired, update the GoToSocial Docker image tag to the version of GtS you wan Change the `GTS_HOST` environment variable to the domain you are running GoToSocial on. +### Server Timezone (optional but recommended) + +To ensure that your GoToSocial server displays the correct time on posts and in logs, you can set the timezone of the server by editing the `TZ` environment variable. + +1. Remove the `#` before `TZ: UTC` in the environment section. +2. Change the `UTC` part to your timezone identifier. For a list of these identifiers, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. + +For example, if you are running your server in Minsk, you would set `TZ: Europe/Minsk`, Japan would be `TZ: Japan`, Dubai would be `TZ: Asia/Dubai`, etc. + +If you don't set this, the default `UTC` will be used. + ### User (optional / probably not necessary) By default, Dockerized GoToSocial runs with Linux user/group `1000:1000`, which is fine in most cases. If you want to run as a different user/group, you should change the `user` field in the docker-compose.yaml accordingly. diff --git a/example/docker-compose/docker-compose.yaml b/example/docker-compose/docker-compose.yaml index 429088934..fc80348b2 100644 --- a/example/docker-compose/docker-compose.yaml +++ b/example/docker-compose/docker-compose.yaml @@ -15,6 +15,8 @@ services: GTS_LETSENCRYPT_EMAIL_ADDRESS: "" ## For reverse proxy setups: # GTS_TRUSTED_PROXIES: "172.x.x.x" + ## Set the timezone of your server: + #TZ: UTC ports: - "443:8080" ## For letsencrypt: diff --git a/scripts/build.sh b/scripts/build.sh index 490f68038..5e95b5988 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -6,7 +6,7 @@ set -e log_exec() { echo "$ ${*}"; "$@"; } # Grab environment variables and set defaults + requirements. -GO_BUILDTAGS="${GO_BUILDTAGS-} netgo osusergo static_build kvformat" +GO_BUILDTAGS="${GO_BUILDTAGS-} netgo osusergo static_build kvformat timetzdata" GO_LDFLAGS="${GO_LDFLAGS-} -s -w -extldflags '-static' -X 'main.Version=${VERSION:-$(git describe --tags --abbrev=0)}'" GO_GCFLAGS=${GO_GCFLAGS-} @@ -16,6 +16,7 @@ GO_GCFLAGS=${GO_GCFLAGS-} # Available Go build tags, with explanation, followed by benefits of enabling it: # - kvformat: enables prettier output of log fields (slightly better performance) +# - timetzdata: embed timezone database inside binary (allow setting local time inside Docker containers, at cost of 450KB) # - notracing: disables compiling-in otel tracing support (reduced binary size, better performance) # - noerrcaller: disables caller function prefix in errors (slightly better performance, at cost of err readability) # - debug: enables /debug/pprof endpoint (adds debug, at performance cost)