51 lines
1.3 KiB
Bash
51 lines
1.3 KiB
Bash
#!/bin/bash
|
|
set -euxo pipefail
|
|
GOI="golang:1.19.3-bullseye"
|
|
CII="golangci/golangci-lint:v1.50.1"
|
|
BII="sneak/mfer-build"
|
|
|
|
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
|
|
|
|
if [[ ! -e "$DICD/build.tzst" ]]; then
|
|
go mod download -x
|
|
cd buildimage
|
|
cp ../go.mod ../go.sum .
|
|
docker build -t $BII . && rm -rf go.mod go.sum && \
|
|
cd .. && \
|
|
docker save $BII | pv | zstdmt -19 > $DICD/build.tzst.tmp && \
|
|
mv $DICD/build.tzst.tmp $DICD/build.tzst
|
|
fi
|
|
}
|
|
|
|
function loadImageCache() {
|
|
docker image ls $CII || \
|
|
zstdmt -d --stdout $DICD/ci.tzst | pv | docker load
|
|
|
|
docker image ls $GOI || \
|
|
zstdmt -d --stdout $DICD/go.tzst | pv | docker load
|
|
|
|
docker image ls $BII || \
|
|
zstdmt -d --stdout $DICD/build.tzst | pv | docker load
|
|
}
|
|
|
|
buildImageCache
|
|
|
|
loadImageCache
|