Skip to content

Instantly share code, notes, and snippets.

@aliihsansepar
Created February 19, 2025 09:09
Show Gist options
  • Select an option

  • Save aliihsansepar/4c603b12e4e68e0e6c032b5dbf66d8e9 to your computer and use it in GitHub Desktop.

Select an option

Save aliihsansepar/4c603b12e4e68e0e6c032b5dbf66d8e9 to your computer and use it in GitHub Desktop.

Revisions

  1. aliihsansepar created this gist Feb 19, 2025.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    FROM golang:1.23.0-bookworm AS build

    ARG upx_version=4.2.4

    RUN apt-get update && apt-get install -y --no-install-recommends 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 && \
    apt-get remove -y xz-utils && \
    rm -rf /var/lib/apt/lists/*

    WORKDIR /app

    COPY go.mod ./
    COPY go.sum ./

    RUN go mod download && go mod verify

    COPY . .

    RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o server -a -ldflags="-s -w" -installsuffix cgo

    RUN upx --ultra-brute -qq server && upx -t server

    FROM scratch

    COPY --from=build /app/server /server

    ENTRYPOINT ["/server"]