rog-golang-buddies / golang-template-repository

Kickstarter repository for a golang service
Apache License 2.0
17 stars 7 forks source link

Dockerfile require statically building the binary #32

Closed haani-niyaz closed 2 years ago

haani-niyaz commented 2 years ago

Adding CGO_ENABLED=0 as a sensible default to produce a statically-linked binary.

This setting is also used as the default for the distroless image: https://github.com/GoogleContainerTools/distroless/blob/main/examples/go/Dockerfile

Further Context

cgo is enabled by default. In the repo Dockerfile, the dynamic linking occurs on golang:1.18 image and runs on gcr.io/distroless/static image where the libraries don't exist. This can cause it to fail.