mfer/bin/docker-prereqs.sh

48 lines
1.2 KiB
Bash

#!/bin/bash
set -euxo pipefail
GOI="golang:1.19.3-bullseye"
#CII="golangci/golangci-lint:v1.50.1"
if [[ ! -d "$DOCKER_IMAGE_CACHE_DIR" ]]; then
mkdir -p "$DOCKER_IMAGE_CACHE_DIR"
fi
DICD="$DOCKER_IMAGE_CACHE_DIR"
function buildImageCache() {
if [[ ! -e "$DICD/go.tzst" ]]; then
docker pull $GOI
docker save $GOI | pv | zstdmt -19 > $DICD/go.tzst.tmp && \
mv $DICD/go.tzst.tmp $DICD/go.tzst
fi
#if [[ ! -e "$DICD/ci.tzst" ]]; then
# docker pull $CII
# docker save $CII | pv | zstdmt -19 > $DICD/ci.tzst.tmp && \
# mv $DICD/ci.tzst.tmp $DICD/ci.tzst
#fi
}
function loadImageCache() {
# zstdmt -d --stdout $DICD/ci.tzst | pv | docker load
zstdmt -d --stdout $DICD/go.tzst | pv | docker load
#docker image ls $CII
docker image ls $GOI
}
function writeModuleCache() {
if [[ ! -e $DICD/modcache.tar ]]; then
cd $(go env GOMODCACHE)
tar -c . | pv > $DICD/modcache.tar.tmp && mv $DICD/modcache.tar.tmp $DICD/modcache.tar
cd -
fi
cp -av $DICD/modcache.tar ./builddeps/modcache.tar.tmp && mv ./builddeps/modcache.tar.tmp ./builddeps/modcache.tar
}
buildImageCache
loadImageCache
writeModuleCache