imagebuilder: optionally support custom tag names

This commit is contained in:
Starbeamrainbowlabs 2021-09-11 02:19:38 +01:00
parent c2cff1c2fc
commit 1010751721
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -58,8 +58,8 @@ if [[ -z "${subcommand}" ]]; then
echo -e " ${HC}${FGRN}./imagebuilder.sh${RS} ${CACTION}{action}${RS} ${LC}[${RS}${CARG}{arguments}${RS}${LC}]${RS}" >&2;
echo -e "" >&2;
echo -e "${CHEADING}Actions:${RS}" >&2;
echo -e " ${CACTION}build${RS} ${CARG}{imagename}${RS}" >&2;
echo -e " Build the given image and upload it to the docker registry" >&2;
echo -e " ${CACTION}build${RS} ${CARG}{imagename}${RS} [${CARG}{imagetag}${RS}]" >&2;
echo -e " Build the given image and upload it to the docker registry, optionally assigning a custom tag name" >&2;
echo -e " ${CACTION}list${RS}" >&2;
echo -e " List available images" >&2;
echo -e "" >&2;
@ -99,6 +99,7 @@ case "${subcommand}" in
# ██████ ██████ ██ ███████ ██████
build)
imagename="${1}";
imagetag="${2}";
if [[ -z "${imagename}" ]]; then
echo "Error: No image name specified.":
@ -117,6 +118,12 @@ case "${subcommand}" in
exit 3;
fi
# Determine the fully qualified tag that we're going to push to
docker_tag="${IMAGEBUILDER_REGISTRY}/${imagename}";
if [[ ! -z "${imagetag}" ]]; then
docker_tag="${docker_tag}:${imagetag}";
fi
imagetype="$(tr -d "[:blank:]" <"${imagedir}/type.txt")";
case "${imagetype}" in
@ -139,7 +146,6 @@ case "${subcommand}" in
task_end "$?";
fi
docker_tag="${IMAGEBUILDER_REGISTRY}/${imagename}";
task_begin "Building docker image";
echo "Tag: ${docker_tag}";
execute docker build --no-cache --pull --tag "${docker_tag}" --build-arg "REPO_LOCATION=${IMAGEBUILDER_REGISTRY}/" .;
@ -194,12 +200,11 @@ case "${subcommand}" in
task_begin "Importing resulting image into Docker";
image_filepath="$(find "${output_dir}" -iname "*.tar.gz" -printf '%p' -quit)";
docker_tag="$(docker import - <"${image_filepath}")";
docker_tag_local="$(docker import - <"${image_filepath}")";
task_end "$?";
task_begin "Tagging and pushing to registry";
docker_tag_push="${IMAGEBUILDER_REGISTRY}/${imagename}"
execute docker tag "${docker_tag}" "${docker_tag_push}";
execute docker tag "${docker_tag_local}" "${docker_tag}";
execute docker push "${docker_tag_push}";
task_end "$?";
;;