From ea430e69b317366ff9ae62f7f1feb22f419117e9 Mon Sep 17 00:00:00 2001 From: flounder5 <25795672+flounder5@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:53:27 -0500 Subject: [PATCH] Remove the created builder --- src/dockerBuild.sh | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/dockerBuild.sh b/src/dockerBuild.sh index 4a210a4..55e7ff0 100755 --- a/src/dockerBuild.sh +++ b/src/dockerBuild.sh @@ -20,6 +20,28 @@ function dockerBuildUsage echo $'\t\t-h - Show this help.' } +function createBuilder +{ + local createBuilderCmd="docker buildx create --use" + eval "$createBuilderCmd" + local status=$? + if [ "$status" -ne 0 ]; then + echo "Error creating builder instance" + exit 1 + fi +} + +function removeBuilder +{ + local removeBuilderCmd="docker buildx rm --force" + eval "$removeBuilderCmd" + local status=$? + if [ "$status" -ne 0 ]; then + echo "Error removing builder instance" + exit 1 + fi +} + # Builds and tags a docker image. function dockerBuild { @@ -169,13 +191,7 @@ function dockerBuild buildCmd="${buildCmd} -f $DOCKER_FILE $BUILD_CONTEXT_DIR 2>&1" #Create a new builder instance - local createBuilderCmd="docker buildx create --use" - eval "$createBuilderCmd" - local status=$? - if [ "$status" -ne 0 ]; then - echo "Error creating builder instance" - exit 1 - fi + createBuilder #Build echo "Building: $buildCmd" @@ -184,9 +200,14 @@ function dockerBuild local buildSuccess=${PIPESTATUS[0]} if [ "$buildSuccess" -ne 0 ]; then echo "Docker build error. Exiting." + #Remove builder before exiting instance + removeBuilder exit "$buildSuccess" fi + #Remove builder instance + removeBuilder + exit 0 }