Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created May 29, 2019 00:07
Show Gist options
  • Save choonkeat/850dda9aaf87acad21df6db3236b940c to your computer and use it in GitHub Desktop.
Save choonkeat/850dda9aaf87acad21df6db3236b940c to your computer and use it in GitHub Desktop.
FROM golang:1.12.5-alpine3.9 as builder
RUN apk --no-cache add tzdata
COPY . /src
RUN go build -o /bin/timenow /src/timenow.go
FROM scratch
COPY --from=builder /bin/timenow /bin/timenow
# without these, TZ env is useless
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
# https://golang.org/src/time/zoneinfo_unix.go
# COPY --from=builder /usr/share/lib/zoneinfo /usr/share/lib/zoneinfo
# COPY --from=builder /usr/lib/locale/TZ /usr/lib/locale/TZ
module github.com/choonkeat/timenow
go 1.12
run:
docker build . -t timenow
docker run --rm -it -e TZ=$(TZ) timenow /bin/timenow
package main
import (
"log"
"os"
"time"
)
func main() {
log.Println(os.Getenv("TZ"))
log.Println(time.Now().Format(time.RFC3339))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment