Skip to content

Commit

Permalink
Remove the created builder
Browse files Browse the repository at this point in the history
  • Loading branch information
flounderpinto committed Dec 12, 2023
1 parent 84f0321 commit ea430e6
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/dockerBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand Down

0 comments on commit ea430e6

Please sign in to comment.