build: Add tzdata to Docker container final image. (#26794)

Nomad's periodic block includes a "time_zone" parameter which lets
operators set the time zone at which the next launch interval is
checked against. For this to work, Nomad needs to use the
"time.LoadLocation" which in-turn can use multiple TZ data sources.

When using the Docker image to trigger Nomad job registrations, it
currently does not have access to any TZ data, meaning it is only
aware of UTC. Adding the tzdata package contents to the release
image provides the required data for this to work.

It would have also been possible to set the "-tags" build tag when
releasing Nomad which would embed a copy of the timezone database
in the code. We decided against using the build tag approach as it
is a subtle way that we could introduce bugs that are very
difficult to track down and we prefer the commit approach.
This commit is contained in:
James Rasell
2025-09-19 08:55:57 +01:00
committed by GitHub
parent 6ea57a589d
commit 8e553ad95b
2 changed files with 13 additions and 1 deletions

3
.changelog/26794.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
build: Add tzdata to Docker container final image
```

View File

@@ -1,9 +1,15 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
# We use a multi-stage build, so we can add tzdata to the final image but still
# produce a Busybox image.
FROM alpine@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1 AS builder
RUN apk add --no-cache tzdata
# docker.io/library/busybox:1.36.0
# When pinning use the multi-arch manifest list, `docker buildx imagetools inspect ...`
FROM docker.io/library/busybox@sha256:9e2bbca079387d7965c3a9cee6d0c53f4f4e63ff7637877a83c4c05f2a666112 as release
FROM docker.io/library/busybox@sha256:9e2bbca079387d7965c3a9cee6d0c53f4f4e63ff7637877a83c4c05f2a666112 AS release
ARG PRODUCT_NAME=nomad
ARG PRODUCT_VERSION
@@ -25,6 +31,9 @@ LABEL maintainer="Nomad Team <nomad@hashicorp.com>" \
org.opencontainers.image.vendor="HashiCorp" \
org.opencontainers.image.licenses="BUSL-1.1"
# Copy over the TZ data from the builder stage into the release image.
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
RUN mkdir -p /usr/share/doc/nomad
COPY LICENSE /usr/share/doc/nomad/LICENSE.txt