feat: show version in stats

This commit is contained in:
Shengjing Zhu
2022-07-24 21:09:07 +08:00
parent 74a362f803
commit 6962a4bdc6
4 changed files with 39 additions and 4 deletions

View File

@@ -1,10 +1,36 @@
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang as builder
WORKDIR /app
COPY . .
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
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH go build -v -trimpath -ldflags="-w -s" .
RUN <<EOF
set -ex
export CGO_ENABLED=0
export GOARCH=$TARGETARCH
export GOPROXY=file://$(go env GOMODCACHE)/cache/download
export GOSUMDB=off
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 /app/wghttp /
COPY --from=builder /go/bin/wghttp /
ENTRYPOINT ["/wghttp"]