ci: Add no-cache option to run-docker.sh script
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 17 Feb 2023 11:33:44 +0000 (11:33 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Fri, 17 Feb 2023 12:24:09 +0000 (12:24 +0000)
Use `run-docker.sh build --no-cache` to discard the cached layers if you
need to rebuild the image without modifying the Dockerfile.

.gitlab-ci/run-docker.sh

index c911e6afe180a306c01bc99b4bc5c25d51b9e0f2..6574a4f4af3d21d5d81c4667260d7e55801fd624 100755 (executable)
@@ -23,6 +23,7 @@ push=0
 list=0
 print_help=0
 no_login=0
+no_cache=0
 
 while (($# > 0)); do
         case "${1%%=*}" in
@@ -34,6 +35,7 @@ while (($# > 0)); do
                 --base|-b) read_arg base "$@" || shift;;
                 --version|-v) read_arg base_version "$@" || shift;;
                 --no-login) no_login=1;;
+                --no-cache) no_cache=1;;
                 *) echo -e "\e[1;31mERROR\e[0m: Unknown option '$1'"; exit 1;;
         esac
         shift
@@ -103,11 +105,21 @@ TAG="${REGISTRY}/gnome/gtk/${base}:${base_version}"
 
 if [ $build == 1 ]; then
         echo -e "\e[1;32mBUILDING\e[0m: ${base} as ${TAG}"
-        ${CMD} build \
-                ${format} \
-                --build-arg HOST_USER_ID="$UID" \
-                --tag "${TAG}" \
-                --file "${base}.Dockerfile" .
+        if [ $no_cache == 0 ]; then
+                ${CMD} build \
+                        ${format} \
+                        --build-arg HOST_USER_ID="$UID" \
+                        --tag "${TAG}" \
+                        --file "${base}.Dockerfile" .
+        else
+                ${CMD} build \
+                        ${format} \
+                        --no-cache \
+                        --build-arg HOST_USER_ID="$UID" \
+                        --tag "${TAG}" \
+                        --file "${base}.Dockerfile" .
+        fi
+
         exit $?
 fi