Skip to content

Instantly share code, notes, and snippets.

@debdutdeb
Last active July 11, 2023 17:14
Show Gist options
  • Save debdutdeb/b08e0d3e7ca7711db762d77fa4b1fddb to your computer and use it in GitHub Desktop.
Save debdutdeb/b08e0d3e7ca7711db762d77fa4b1fddb to your computer and use it in GitHub Desktop.
Prepare archive for airgapped installation

use bash <script_name> [tag]

example: bash prepare_rocketchat_archive.sh 6.2.9

#!/bin/bash
_tag=${1:-latest}
_dir="$(mktemp -d)"
trap "rm -rf $_dir" EXIT
pushd "$_dir" >/dev/null
cat <<EDOCKERFILE >Dockerfile
from rocketchat/rocket.chat:$_tag as upstream
from scratch
copy --from=upstream /app/bundle /rocket.chat
EDOCKERFILE
echo "info: preparing archive"
if ! _id="$(docker build -q .)"; then
echo "error: failed to build new image"
exit 1
fi
echo "info: image id $_id"
echo "info: saving image"
docker save "$_id" >rocketchat.tar
if ! [[ -f rocketchat.tar ]]; then
echo "error: failed to save image"
exit 1
fi
if ! tar xf rocketchat.tar; then
echo "error: failed to extract archive"
exit 1
fi
if ! _to_extract="$(jq '.[0].Layers[0]' -r manifest.json)"; then
echo "error: no layer found in image"
exit 1
fi
if ! tar xf "$_to_extract"; then
echo "error: failed to extract main layer"
exit 1
fi
if ! [[ -d rocket.chat ]]; then
echo "error: no rocket.chat bundle found"
exit 1
fi
if ! tar -czf "rocket.chat.$_tag.tar.gz" rocket.chat; then
echo "error: failed to archive final archive"
exit 1
fi
popd >/dev/null
mv "${_dir%/}/rocket.chat.$_tag.tar.gz" .
echo "info: your rocket.chat version $_tag archive is ready to be used"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment