no cache option to build image

This commit is contained in:
Tomas Mirchev 2025-03-03 12:25:32 +01:00
parent fc60ad72e3
commit f11123e0bb

View File

@ -2,13 +2,19 @@
set -e
if [ $# -eq 0 ]; then
echo "Usage: $0 <image-name>"
echo "Example: $0 base-debian"
if [ $# -lt 1 ]; then
echo "Usage: $0 <image-name> [--no-cache]"
echo "Example: $0 base-debian --no-cache"
exit 1
fi
IMAGE_NAME=${1:-base-debian}
IMAGE_NAME=$1
NO_CACHE=false
if [[ "$2" == "--no-cache" ]]; then
NO_CACHE=true
fi
echo "Building Docker image: $IMAGE_NAME"
if ! command -v dpkg &> /dev/null; then
@ -36,11 +42,16 @@ COMMIT_ID=$(git rev-parse --short HEAD)
IMAGE_ARCH="${REPO}/${IMAGE_NAME}:${COMMIT_ID}-${ARCH}"
IMAGE_LATEST="${REPO}/${IMAGE_NAME}:${TAG_LATEST}-${ARCH}"
docker build \
-t ${IMAGE_ARCH} \
--build-arg UID=${_UID} \
--build-arg GID=${_GID} \
${BUILD_DIR}
echo "📦 Running Docker build..."
DOCKER_BUILD_CMD=("docker" "build" "-t" "${IMAGE_ARCH}" "--build-arg" "UID=${_UID}" "--build-arg" "GID=${_GID}")
if [ "$NO_CACHE" = true ]; then
DOCKER_BUILD_CMD+=("--no-cache")
fi
DOCKER_BUILD_CMD+=("${BUILD_DIR}")
"${DOCKER_BUILD_CMD[@]}"
docker tag ${IMAGE_ARCH} ${IMAGE_LATEST}