forked from kubernetes-retired/kpng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.static
43 lines (33 loc) · 1 KB
/
Dockerfile.static
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from alpine:3.16 as gomods
copy . /src/
run cd /src/ && find -type f \! \( -name go.work -o -name go.mod -o -name go.sum \) -exec rm {} +
from golang:1.19.2-alpine3.16 as build
# install dependencies
run apk add --update --no-cache \
gcc musl-dev \
linux-headers
# build static dependencies
run apk add bison flex make
# - libnl3
workdir /deps/libnl-3
run wget -O libnl3.tar.gz https://github.com/thom311/libnl/releases/download/libnl3_7_0/libnl-3.7.0.tar.gz
run tar zxvf libnl3.tar.gz --strip-components=1
run ./configure --prefix=/usr --sysconfdir=/etc --enable-cli=no --disable-shared
run make && make install
workdir /src
# go mod args
arg GOPROXY
arg GONOSUMDB
# cache dependencies, they don't change as much as the code
copy --from=gomods /src/ /src/
run go mod download
# test and build
add . ./
#run go test ./...
run go install -trimpath \
-ldflags "-extldflags '-static -pthread'" \
./cmd/...
# the real image
from scratch
entrypoint ["/bin/kpng"]
copy --from=build /go/bin/kpng /bin/