chore: use trimpath for Dockefile go
parent
ce86eebeae
commit
cccd577afd
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue