chore: use trimpath for Dockefile go

main
sudo pacman -Syu 2022-06-19 18:03:14 +07:00
parent ce86eebeae
commit cccd577afd
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
1 changed files with 7 additions and 3 deletions

View File

@ -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