mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
4fc0ca5110
Replace TZ env var with /etc/localtime bind-mount in docker-compose and inject timezone spec opts into containerd bot containers.
27 lines
725 B
Go
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
|
|
}
|