-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Dockerfile-crossplatform
78 lines (66 loc) · 3.57 KB
/
Dockerfile-crossplatform
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
FROM alpine:edge
LABEL maintainer "Ali Mosajjal <[email protected]>"
RUN apk add --no-cache git go zig file --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/
ARG PROJECT=dnsmonster
ARG GOTAG=nolibpcap
ARG GOLDFLAGS='-s -w'
# OUTDIR is also used in the second layer for copying the folder.
ARG OUTDIR="/tmp/bins"
RUN mkdir /${PROJECT} && mkdir ${OUTDIR}
COPY . /${PROJECT}
WORKDIR /${PROJECT}
env GOBUILD="go build -ldflags=-s -tags ${GOTAG} -o ${OUTDIR}/${PROJECT}_${GOTAG}"
env BASEDIR="./cmd/dnsmonster"
# Linux
RUN echo "Building Linux binaries"
RUN export GOOS=linux && export CGO_ENABLED=1 && \
export GOARCH=amd64 && CC="zig cc -target x86_64-${GOOS}-musl" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=386 && CC="zig cc -target i386-${GOOS}-musl" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm && CC="zig cc -target arm-${GOOS}-musleabihf" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm64 && CC="zig cc -target aarch64-${GOOS}-musl" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=riscv64 && CC="zig cc -target riscv64-${GOOS}-musl" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# MIPS and PPC are pending patches from Zig #10979, #11829
# Windows
RUN echo "Building Windows binaries"
RUN export GOOS=windows && export CGO_ENABLED=1 && \
export GOARCH=amd64 && CC="zig cc -target x86_64-${GOOS}-gnu" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=386 && CC="zig cc -target i386-${GOOS}-gnu" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm && CC="zig cc -target arm-${GOOS}-gnu" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm64 && CC="zig cc -target aarch64-${GOOS}-gnu" ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# Darwin
RUN echo "Building Darwin binaries"
RUN export GOOS=darwin && export CGO_ENABLED=0 && \
export GOARCH=amd64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# FreeBSD
RUN echo "Building FreeBSD binaries"
RUN export GOOS=freebsd && export CGO_ENABLED=0 && \
export GOARCH=arm64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=amd64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=386 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# NetBSD
RUN echo "Building NetBSD binaries"
RUN export GOOS=netbsd && export CGO_ENABLED=0 && \
export GOARCH=arm64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=amd64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=386 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# OpenBSD
RUN echo "Building OpenBSD binaries"
RUN export GOOS=openbsd && export CGO_ENABLED=0 && \
export GOARCH=arm64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=amd64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=arm && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR} && \
export GOARCH=386 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# Android
RUN echo "Building Android binaries"
RUN export GOOS=android && export CGO_ENABLED=0 && \
export GOARCH=arm64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
# DragonflyBSD
RUN echo "Building Dragonfly binaries"
RUN export GOOS=dragonfly && export CGO_ENABLED=0 && \
export GOARCH=amd64 && ${GOBUILD}_${GOOS}_${GOARCH}.bin ${BASEDIR}
FROM scratch
COPY --from=0 /tmp/bins/*.bin /
ENTRYPOINT ["/dnsmonster"]