-
Notifications
You must be signed in to change notification settings - Fork 18
/
Dockerfile
41 lines (36 loc) · 1.14 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang as builder
WORKDIR /app
COPY go.mod .
RUN go mod download
COPY . .
RUN <<EOF
set -ex
tag=$(git describe --tags --always --abbrev=8 --dirty)
if echo "$tag" | grep -q dirty; then exit 1; fi
file_prefix=$(go env GOMODCACHE)/cache/download/github.com/zhsj/wghttp/@v/$tag
mkdir -p $(dirname "$file_prefix")
echo "{\"Version\": \"$tag\"}" > "$file_prefix".info
cp go.mod "$file_prefix".mod
git archive --prefix=github.com/zhsj/wghttp@"$tag"/ -o "$file_prefix".zip HEAD
EOF
ARG TARGETARCH TARGETVARIANT
RUN <<EOF
set -ex
export CGO_ENABLED=0
export GOPROXY=file://$(go env GOMODCACHE)/cache/download
export GOSUMDB=off
export GOARCH="$TARGETARCH"
case "$TARGETARCH" in
arm|arm64)
export GOARM=$(echo "$TARGETVARIANT"|sed 's/^v//')
;;
esac
tag=$(git describe --tags --abbrev=8 --always)
go install -trimpath -ldflags="-w -s" github.com/zhsj/wghttp@"$tag"
cross_bin=/go/bin/$(go env GOOS)_$(go env GOARCH)/wghttp
if [ -e "$cross_bin" ]; then mv "$cross_bin" /go/bin/wghttp; fi
EOF
FROM scratch
COPY --from=builder /go/bin/wghttp /
ENTRYPOINT ["/wghttp"]