85
build.sh
Executable file
85
build.sh
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
print_usage()
|
||||
{
|
||||
echo "USAGE: $0 <slim|full> [rust version] [cross version]"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo -e "\t<slim|full>\tSlim build (without targets) or Full build (with targets)"
|
||||
echo -e "\t[rust version]\tVersion of rust (https://github.com/rust-lang/rust)"
|
||||
echo -e "\t[cross version]\tVersion of cross (https://github.com/cross-rs/cross)"
|
||||
echo
|
||||
echo "Both versions default to the latest version."
|
||||
}
|
||||
|
||||
get_latest_release() {
|
||||
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
|
||||
grep '"tag_name":' | # Get tag line
|
||||
sed -E 's/.*"v?([^"]+)".*/\1/' # Pluck JSON value
|
||||
}
|
||||
|
||||
|
||||
if command -v podman &> /dev/null
|
||||
then
|
||||
BUILDER=podman
|
||||
elif command -v docker &> /dev/null
|
||||
then
|
||||
BUILDER=docker
|
||||
else
|
||||
echo "Prerequisite failed: either podman or docker must be installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v envsubst &> /dev/null
|
||||
then
|
||||
echo "Prerequisite failed: envsubst must be installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case ${1} in
|
||||
full | slim)
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "ERROR: The first argument mus either be 'full' or 'slim'."
|
||||
echo
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
RUST_VERSION=$(get_latest_release 'rust-lang/rust')
|
||||
else
|
||||
RUST_VERSION=$2
|
||||
fi
|
||||
|
||||
if [ -z "$3" ]; then
|
||||
CROSS_VERSION=$(get_latest_release 'cross-rs/cross')
|
||||
else
|
||||
CROSS_VERSION=$3
|
||||
fi
|
||||
|
||||
echo "Creating a ${1} build with Rust ${RUST_VERSION} and cross ${CROSS_VERSION}"
|
||||
|
||||
export RUST_VERSION
|
||||
export CROSS_VERSION
|
||||
|
||||
IMAGE="img.kie.rs/jjkiers/rust-dind-cross:rust${RUST_VERSION}-cross${CROSS_VERSION}-${1}"
|
||||
|
||||
envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
|
||||
-t ${IMAGE} \
|
||||
.
|
||||
|
||||
echo "Built image ${IMAGE}"
|
||||
|
||||
${BUILDER} push ${IMAGE}
|
||||
|
||||
echo "Pushed image ${IMAGE}"
|
||||
Reference in New Issue
Block a user