From bfefa513312e8919265b777203e516d9b561bcd9 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 25 Apr 2023 16:19:31 -0700 Subject: [PATCH] feat(build): decrease shipped binary size with upx --- Earthfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index b0ae756c1..819d16972 100644 --- a/Earthfile +++ b/Earthfile @@ -17,7 +17,7 @@ docker-all: crosscompiler: # This image is missing a few platforms, so we'll add them locally FROM --platform=linux/amd64 bdwyertech/go-crosscompile - RUN apk add --update --no-cache tar gzip >> /dev/null + RUN apk add --update --no-cache tar gzip upx >> /dev/null RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/armv7l-linux-musleabihf-cross.tgz" | tar zxf - -C /usr/ --strip-components=1 RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/i686-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1 RUN curl -sfL "https://owncast-infra.nyc3.cdn.digitaloceanspaces.com/build/x86_64-linux-musl-cross.tgz" | tar zxf - -C /usr/ --strip-components=1 @@ -76,6 +76,11 @@ build: # MacOSX disallows static executables, so we omit the static flag on this platform RUN go build -a -installsuffix cgo -ldflags "$([ "$GOOS"z != darwinz ] && echo "-linkmode external -extldflags -static ") -s -w -X github.com/owncast/owncast/config.GitCommit=$EARTHLY_GIT_HASH -X github.com/owncast/owncast/config.VersionNumber=$version -X github.com/owncast/owncast/config.BuildPlatform=$NAME" -tags sqlite_omit_load_extension -o owncast main.go + # Decrease the size of the shipped binary + RUN upx --best --lzma owncast + # Test the binary + RUN upx -t owncast + SAVE ARTIFACT owncast owncast package: