Files
Memoh/internal/containerd/timezone.go
T
BBQ 4fc0ca5110 fix(container): propagate host timezone to all containers
Replace TZ env var with /etc/localtime bind-mount in docker-compose
and inject timezone spec opts into containerd bot containers.
2026-02-20 03:22:31 +08:00

27 lines
725 B
Go

package containerd
import (
"os"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/opencontainers/runtime-spec/specs-go"
)
// TimezoneSpecOpts returns OCI spec options that propagate the host timezone
// into the container via /etc/localtime bind-mount and TZ environment variable.
func TimezoneSpecOpts() []oci.SpecOpts {
var opts []oci.SpecOpts
if _, err := os.Stat("/etc/localtime"); err == nil {
opts = append(opts, oci.WithMounts([]specs.Mount{{
Destination: "/etc/localtime",
Type: "bind",
Source: "/etc/localtime",
Options: []string{"rbind", "ro"},
}}))
}
if tz := os.Getenv("TZ"); tz != "" {
opts = append(opts, oci.WithEnv([]string{"TZ=" + tz}))
}
return opts
}