How to create a binary that contains zoneinfo.zip

9/25/2018

I'm using Docker to create a container application and then deploy it to kubernetes engine but when the application is been initialized I get this error:

err: open C:\Go/lib/time/zoneinfo.zip: no such file or directory

enter image description here

enter image description here

-- John Balvin Arias
containers
go
google-kubernetes-engine
kubernetes

3 Answers

9/26/2018

When using Go's time package, specifically the LoadLocation method, it looks for time zone database information in various locations. This is explained in the comments for LoadLocation in the source code at https://golang.org/src/time/zoneinfo.go. Specifically it looks in these places:

  1. A location specified by a ZONEINFO environment variable
  2. Known locations where time zone database files are kept on Unix operating systems
  3. The zoneinfo.zip file in your $GOROOT

When you're programming on a Windows machine, Go is most likely defaulting to the 3rd option. However, there is no $GOROOT when you're working with a binary, so that won't work in your container. On most versions of Linux the 2nd option would work fine as they would have the necessary time zone database files. However, I have a strong suspicion that the optimized container you reference does not. This leaves you with option 1, which essentially consists of putting your own time zone database files on the container and then referencing their location with the ZONEINFO environment variable. This is both kind of a pain in the ass and I've also found that it fails silently when you request a time zone file that doesn't exist.

In my own addressing of this problem I ended up creating a package that utilizes the LoadLocationFromTZData method and tries to simplify the process of providing and working with your own copy of the time zone database. You can see my own stack overflow question here: Detect if ZONEINFO fails in Go. And you can see the repository for my time zone package here: https://github.com/slotheroo/knozone

-- Slotheroo
Source: StackOverflow

9/25/2018

Looks like you are trying to build your Golang exec on a Windows environment container? You can try to build with the right GOOS=linux (Goose) and GOARCH=amd64 (Gorch). If that doesn't work I recommend you build it natively on a Linux container.

-- Rico
Source: StackOverflow

7/29/2019

I faced that same problem a week ago and ended up resolving like this on the Dockerfile.

First, you need to locate the zoneinfo.zip file. For instance on a MacOS having Go installed via brew can get tricky.

tztest$ go env GOROOT
/usr/local/Cellar/go/1.12.7/libexec
tztest$ ls -l /usr/local/Cellar/go/1.12.7/libexec/lib/time/zoneinfo.zip
-rwxr-xr-x  1 mau  staff  365447 Jul  8 16:29 /usr/local/Cellar/go/1.12.7/libexec/lib/time/zoneinfo.zip

So the workaround is copying zoneinfo.zip and include in the same directory of the Dockerfile. From there, is just a matter of ADD the file to the docker build process and override the environment variable

ADD zoneinfo.zip /zoneinfo.zip
ENV ZONEINFO /zoneinfo.zip
-- coffekid
Source: StackOverflow