Skip to content

feat: Compress and extract slim binaries with zstd #2533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Add support for zstd compression of slim binaries
  • Loading branch information
mafredri committed Jun 20, 2022
commit b262c3874d373f95ab6d27d27a9f31ed06c04537
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name
# build slim artifacts and copy them to the site output directory
./scripts/build_go_slim.sh \
--version "$(VERSION)" \
--compress 22 \
--output ./dist/ \
linux:amd64,armv7,arm64 \
windows:amd64,arm64 \
Expand Down
23 changes: 22 additions & 1 deletion scripts/build_go_slim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

version=""
output_path=""
compress=""

args="$(getopt -o "" -l version:,output: -- "$@")"
args="$(getopt -o "" -l version:,output:,compress: -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand All @@ -36,6 +37,10 @@ while true; do
output_path="$2"
shift 2
;;
--compress)
compress="$2"
shift 2
;;
--)
shift
break
Expand All @@ -48,6 +53,13 @@ done

# Check dependencies
dependencies go
if [[ -n $compress ]]; then
dependencies tar zstd

if [[ ! $compress == [0-9]* ]] || ((compress > 22)) || ((compress < 1)); then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ ! $compress == [0-9]* ]] || ((compress > 22)) || ((compress < 1)); then
if [[ "$compress" != [0-9]* ]] || [ "$compress" -gt 22 ] || [ "$compress" -lt 1 ]; then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why we'd want to avoid (( ))? Neither handles non-numbers gracefully (but we've verified that with the glob match).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency, we use lt and gt in other scripts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough. I'd like for us to drop the use of [ though. [[ is superior and also supports -gt and -lt. For instance, with [[ there is no need to quote the right-hand variable to avoid errors when it's empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to change it across all scripts 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't do it in this PR to keep the noise down, but I can do a follow-up tomorrow.

error "Invalid value for compress, must in in the range of [1, 22]"
fi
fi

# Remove the "v" prefix.
version="${version#v}"
Expand Down Expand Up @@ -92,3 +104,12 @@ for f in ./coder-slim_*; do
dest="$dest_dir/$hyphenated"
cp "$f" "$dest"
done

if [[ -n $compress ]]; then
(
cd "$dest_dir"
tar cf coder.tar coder-*
rm coder-*
zstd --ultra --long -"${compress}" --rm --no-progress coder.tar -o coder.tar.zst
)
fi