Skip to content

Commit

Permalink
feat: minimize binary size (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerman authored Feb 28, 2023
1 parent 608e20c commit e39e36b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# syntax=docker/dockerfile:1

# Go version is also in .github/workflows/CI&CD.yml.
FROM golang:1.20.1-alpine3.17 AS builder
SHELL ["/bin/ash","-e","-o","pipefail","-x","-c"]

LABEL org.opencontainers.image.source="https://github.com/powerman/dockerize"

RUN apk add --no-cache openssl=~3 git=~2
# hadolint ignore=DL3019
RUN apk update; \
apk add openssl=~3 git=~2; \
apk add upx=~4 || :; \
rm -f /var/cache/apk/*

COPY . /src
WORKDIR /src

RUN CGO_ENABLED=0 go install -ldflags "-s -X 'main.ver=$(git describe --match='v*' --exact-match)'"
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 go install -ldflags "-s -w -X 'main.ver=$(git describe --match='v*' --exact-match)'" && \
! which upx >/dev/null || upx /go/bin/dockerize && \
dockerize --version

FROM alpine:3.17.2

Expand Down
3 changes: 2 additions & 1 deletion scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ GH_REPO="${GH##*/}"
mkdir -p $DIST_DIR
while read -r suffix GOOS GOARCH GOARM; do
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM \
go build -o "$DIST_DIR/${GH_REPO}-$suffix" -ldflags "-X 'main.ver=$TAG'"
go build -o "$DIST_DIR/${GH_REPO}-$suffix" -ldflags "-s -w -X 'main.ver=$TAG'"
pushd "$DIST_DIR"
upx "${GH_REPO}-$suffix"
sha256sum "${GH_REPO}-$suffix" >"${GH_REPO}-$suffix.sha256"
#gpg --armor --output "${GH_REPO}-$suffix.asc" --detach-sign "${GH_REPO}-$suffix"
popd
Expand Down

0 comments on commit e39e36b

Please sign in to comment.