57 lines
1.3 KiB
Bash
Executable File
57 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
DOCKER_IMAGE="zefie/llvm-mingw"
|
|
CURDIR="$(realpath "$(dirname "${0}")")"
|
|
|
|
get_latest() {
|
|
# Find all tags for ${DOCKER_IMAGE}, sort by creation timestamp (descending), return the newest
|
|
latest_image=$(docker images --format '{{.CreatedAt}}\t{{.Repository}}:{{.Tag}}' ${DOCKER_IMAGE} \
|
|
| sort -r \
|
|
| cut -f2- \
|
|
| grep -v latest \
|
|
| head -n 1)
|
|
|
|
if [[ -z "$latest_image" ]]; then
|
|
echo "No images found for repository '${DOCKER_IMAGE}'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "$latest_image"
|
|
}
|
|
|
|
if [ "${1}" == "build" ]; then
|
|
THETAG=$(date +%Y%m%d)
|
|
cd "$(realpath "$(dirname "${0}")")"
|
|
docker buildx build --tag "${DOCKER_IMAGE}:${THETAG}" .
|
|
elif [ "${1}" == "mklatest" ]; then
|
|
LATEST=$(get_latest)
|
|
if [ -z "${LATEST}" ]; then
|
|
exit 1;
|
|
fi
|
|
docker tag "${LATEST}" ${DOCKER_IMAGE}:latest
|
|
echo "Set ${DOCKER_IMAGE}:latest to ${LATEST}"
|
|
elif [ "${1}" == "run" ]; then
|
|
shift
|
|
IMAGE=$(get_latest)
|
|
if [ -z "${IMAGE}" ]; then
|
|
exit 1;
|
|
fi
|
|
export EMBEDDED=1
|
|
CMD=(docker run --rm -it "${IMAGE}" "${@}")
|
|
echo "Executing ${CMD[@]}"
|
|
"${CMD[@]}"
|
|
elif [ "${1}" == "push" ]; then
|
|
# push dated one first, then latest
|
|
"${0}" mklatest
|
|
IMAGE=$(get_latest)
|
|
echo "Pushing ${IMAGE}"
|
|
docker push "${IMAGE}"
|
|
echo "Pushing ${DOCKER_IMAGE}:latest"
|
|
docker push "${DOCKER_IMAGE}:latest"
|
|
else
|
|
echo "Usage: ${0} [build|run|mklatest]"
|
|
exit 1;
|
|
fi
|
|
|