From cccd577afda736d6e4edd9fb976abb01ea7a92a7 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Sun, 19 Jun 2022 18:03:14 +0700 Subject: [PATCH] chore: use trimpath for Dockefile go --- posts/2022-06-08-dockerfile-go.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/posts/2022-06-08-dockerfile-go.md b/posts/2022-06-08-dockerfile-go.md index cf13805..9f04bfe 100644 --- a/posts/2022-06-08-dockerfile-go.md +++ b/posts/2022-06-08-dockerfile-go.md @@ -18,7 +18,7 @@ COPY go.sum . COPY vendor . COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v3 go build -o ./app main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v3 go build -o ./app -tags timetzdata -trimpath . FROM gcr.io/distroless/base-debian11 @@ -69,15 +69,19 @@ First is `go.mod` and `go.sum` because it defines Go modules. The second is `vendor`, this is optional but I use it because I don't want each time I build Dockerfile, I need to redownload Go modules. ```Dockerfile -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v3 go build -o ./app . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v3 go build -o ./app -tags timetzdata -trimpath . ``` This is where I build Go program. + `CGO_ENABLED=0` because I don't want to mess with C libraries. `GOOS=linux GOARCH=amd64` is easy to explain, Linux with x86-64. -`GOAMD64=v3` is new since [Go 1.18](https://tip.golang.org/doc/go1.18#amd64), +`GOAMD64=v3` is new since [Go 1.18](https://go.dev/doc/go1.18#amd64), I use v3 because I read about AMD64 version in [Arch Linux rfcs](https://gitlab.archlinux.org/archlinux/rfcs/-/blob/master/rfcs/0002-march.rst). TLDR's newer computers are already x86-64-v3. +`-tags timetzdata` to embed timezone database incase base image does not have. +`-trimpath` to support reproduce build. + ```Dockerfile FROM gcr.io/distroless/base-debian11