[build] embed IANA tzdata so named time zones work in minimal images (STAR-57)#22
Merged
Conversation
β¦(STAR-57)
starcli's time module resolves named zones (parse_time location=, in_location,
is_valid_timezone) via time.LoadLocation, which needs the IANA tz database. The
binary relied on the host's /usr/share/zoneinfo β fine on the ubuntu Docker
image, but a slim binary or a scratch/distroless/alpine image has no tz data, so
named zones would fail there. With v0.2 heading toward goreleaser binaries and
minimal images, embed the database via `import _ "time/tzdata"` so the CLI is
self-contained and "runs anywhere".
Proof (linux/amd64 static binary in plain alpine, which has no zoneinfo):
with the import -> is_valid_timezone("America/New_York") == True
without it -> == False
Cost: +400 KiB stripped (32.8 -> 33.2 MB), negligible against the existing size.
- main.go: blank import of time/tzdata with the rationale.
- e2e: two golden cases (is_valid_timezone + in_location conversion) guard that
named zones keep resolving through the real binary.
Full -race green; Docker golang:1.25 floor green; gofmt/vet clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Embed the IANA time-zone database into the binary via
import _ "time/tzdata"so named zones resolve without a host/usr/share/zoneinfo.Why
starcli's
timemodule resolves named zones (parse_time(location=β¦),in_location,is_valid_timezone) throughtime.LoadLocation, which needs the IANA tz data. The binary relied on the host's/usr/share/zoneinfoβ fine on the current ubuntu Docker image, but a slim binary or a scratch/distroless/alpine image has no tz data, so named zones fail there. v0.2 is heading toward goreleaser binaries + minimal images, so embedding keeps the CLI self-contained and "runs anywhere".Proof (linux/amd64 static binary in plain
alpine, which has no zoneinfo)is_valid_timezone("America/New_York")Cost: +400 KiB stripped (32.8 β 33.2 MB) β negligible against the existing size.
Changes
main.go: blank import oftime/tzdatawith the rationale.e2e: two golden cases (is_valid_timezone+ anin_locationconversion) guard that named zones keep resolving through the real binary.Verification
-racegreen; Dockergolang:1.25(go floor) green;gofmt/vetclean.Tracks STAR-57 (the tzdata half). CA certs for scratch/distroless images are handled in the goreleaser/Docker step (P1-b) β system cert pool covers real OSes.