Skip to content

Commit b262c38

Browse files
committed
feat: Add support for zstd compression of slim binaries
1 parent 6d0579d commit b262c38

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ build: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name
3535
# build slim artifacts and copy them to the site output directory
3636
./scripts/build_go_slim.sh \
3737
--version "$(VERSION)" \
38+
--compress 22 \
3839
--output ./dist/ \
3940
linux:amd64,armv7,arm64 \
4041
windows:amd64,arm64 \

scripts/build_go_slim.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
2323

2424
version=""
2525
output_path=""
26+
compress=""
2627

27-
args="$(getopt -o "" -l version:,output: -- "$@")"
28+
args="$(getopt -o "" -l version:,output:,compress: -- "$@")"
2829
eval set -- "$args"
2930
while true; do
3031
case "$1" in
@@ -36,6 +37,10 @@ while true; do
3637
output_path="$2"
3738
shift 2
3839
;;
40+
--compress)
41+
compress="$2"
42+
shift 2
43+
;;
3944
--)
4045
shift
4146
break
@@ -48,6 +53,13 @@ done
4853

4954
# Check dependencies
5055
dependencies go
56+
if [[ -n $compress ]]; then
57+
dependencies tar zstd
58+
59+
if [[ ! $compress == [0-9]* ]] || ((compress > 22)) || ((compress < 1)); then
60+
error "Invalid value for compress, must in in the range of [1, 22]"
61+
fi
62+
fi
5163

5264
# Remove the "v" prefix.
5365
version="${version#v}"
@@ -92,3 +104,12 @@ for f in ./coder-slim_*; do
92104
dest="$dest_dir/$hyphenated"
93105
cp "$f" "$dest"
94106
done
107+
108+
if [[ -n $compress ]]; then
109+
(
110+
cd "$dest_dir"
111+
tar cf coder.tar coder-*
112+
rm coder-*
113+
zstd --ultra --long -"${compress}" --rm --no-progress coder.tar -o coder.tar.zst
114+
)
115+
fi

0 commit comments

Comments
 (0)