-
Notifications
You must be signed in to change notification settings - Fork 0
/
Containerfile
43 lines (36 loc) · 1.18 KB
/
Containerfile
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 docker.io/golang:1.23 AS build
ARG ARCH=amd64
ARG VERSION=0.0.0
ARG COMMIT=nil
ARG UPX_VERSION=4.2.4
# hadolint ignore=DL3008
RUN set -xeu; \
apt-get update; \
apt-get install -y --no-install-recommends xz-utils curl; \
curl -#Lo upx.tar.xz \
"https://github.com/upx/upx/releases/download/v$UPX_VERSION/upx-$UPX_VERSION-${ARCH}_linux.tar.xz"; \
tar -xvf upx.tar.xz --strip-components=1 "upx-$UPX_VERSION-${ARCH}_linux/upx"; \
chmod +x upx; \
mv upx /usr/local/bin/upx; \
rm -f upx.tar.xz
WORKDIR /src/dayz-exporter
COPY go.mod go.sum ./
RUN go mod download
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOFLAGS="-buildvcs=false -trimpath"
ENV GOARCH=$ARCH
COPY ./cli ./cli
COPY ./pkg ./pkg
RUN set -eux;\
pkg="$(grep -Po 'module \K.*$' go.mod)/pkg/config"; \
version="$pkg.Version=$VERSION"; \
commit="$pkg.Commit=$COMMIT"; \
date="$pkg.BuildTime=$(date -uIs)"; \
go build -ldflags="-s -w -X '$version' -X '$commit' -X '$date'" \
-o "./dayz-exporter" "cli/"*.go; \
upx --lzma --best ./dayz-exporter; \
upx -t ./dayz-exporter
FROM scratch
COPY --from=build /src/dayz-exporter/dayz-exporter /dayz-exporter
ENTRYPOINT ["/dayz-exporter"]