Skip to content

Commit

Permalink
feat(golang-cobra): shrink the Dockerfile binary through UPX
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Aug 24, 2024
1 parent 89bd11f commit a03cf07
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions golang-cobra/{{ cookiecutter.project_name }}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM golang AS builder
ARG GIT_COMMIT
ARG GIT_REPO="{{ cookiecutter.repo }}"
ARG UPX_VERSION=4.2.4
ARG VERSION
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates xz-utils \
&& curl -Ls https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz -o - | tar xvJf - -C /tmp \
&& cp /tmp/upx-${UPX_VERSION}-amd64_linux/upx /usr/local/bin/ \
&& chmod +x /usr/local/bin/upx
WORKDIR /app
ADD . .
ENV CGO_ENABLED=0
Expand All @@ -11,10 +16,11 @@ RUN go build \
-ldflags \
"-w -s -X $GIT_REPO/cmd.Version=$VERSION -X $GIT_REPO/cmd.GitCommit=$GIT_COMMIT" \
-o /app/app
RUN upx --ultra-brute -qq /app/app && upx -t /app/app
ENTRYPOINT /app/app

FROM alpine
RUN apk --no-cache add ca-certificates
WORKDIR /app
FROM scratch
WORKDIR /appq
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/app /app
ENTRYPOINT [ "/app/app" ]

0 comments on commit a03cf07

Please sign in to comment.