ptth/build_and_minimize.bash

32 lines
931 B
Bash
Raw Normal View History

2020-11-09 01:06:53 +00:00
#!/usr/bin/env bash
# Use: ./build-and-minimize.bash
# Makes a docker image, saves it as .tar, unpacks the tar, removes
# the base Debian layer, and repacks it so I can upload to servers a little
# faster.
2020-11-30 15:57:14 +00:00
set -euo pipefail
2020-11-09 01:06:53 +00:00
TEMP_GIBBERISH="ptth_build_L6KLMVS6"
TEMP_TAR="$TEMP_GIBBERISH/ptth.tar"
UPLOADABLE_TAR="$PWD/ptth_latest.tar.gz"
GIT_COMMITISH=$(git rev-parse main)
2020-11-09 01:06:53 +00:00
# This is magic and will need to be updated whenever we update the
# Debian layer.
BOTTOM_LAYER="7900806df64cc5adea32b37d8484569598376cac1c66f0810c01b7ad2458e9fd"
2020-11-09 01:06:53 +00:00
rm -rf "$TEMP_GIBBERISH"
2020-11-09 01:06:53 +00:00
mkdir -p "$TEMP_GIBBERISH/ptth"
git archive --format=tar "$GIT_COMMITISH" | sudo docker build -t ptth:latest --build-arg "git_version=$GIT_COMMITISH" -
2020-11-09 01:06:53 +00:00
sudo docker image save ptth:latest | pv > "$TEMP_TAR"
tar -C "$TEMP_GIBBERISH/ptth" -xf "$TEMP_TAR"
rm -rf "$TEMP_GIBBERISH/ptth/$BOTTOM_LAYER"
pushd "$TEMP_GIBBERISH/ptth"
tar -czf "$UPLOADABLE_TAR" .
popd