[igt-dev] [PATCH i-g-t 4/8] .gitalb-ci: Use only the necessary tags

Arkadiusz Hiler arkadiusz.hiler at intel.com
Tue Sep 3 08:36:10 UTC 2019


Tag build-* images only with dockerfile-$FILE_SHA1 for changes detection
and commit-$COMMIT_SHA1, so we know which set of images we have to use
for any given commit.

The igt container needs only ref (e.g. master) and commit-$COMMIT_SHA1
tags, as the dockerfile-$FILE_SHA1 one is irrelevant - we build build
every time anyway.

Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
 .gitlab-ci.yml                | 14 +++++------
 .gitlab-ci/pull-or-rebuild.sh | 47 +++++++++++++++++++++--------------
 2 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c5611138..5b983618 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,10 +30,10 @@ build-containers:build-debian:
     DOCKER_DRIVER: overlay2
   script:
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile.build-debian-minimal build-debian-minimal
+    - .gitlab-ci/pull-or-rebuild.sh base Dockerfile.build-debian-minimal build-debian-minimal
     - docker pull $CI_REGISTRY/$CI_PROJECT_PATH/build-debian-minimal:commit-$CI_COMMIT_SHA
     - docker tag $CI_REGISTRY/$CI_PROJECT_PATH/build-debian-minimal:commit-$CI_COMMIT_SHA build-debian-minimal:commit-$CI_COMMIT_SHA
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile.build-debian build-debian
+    - .gitlab-ci/pull-or-rebuild.sh base Dockerfile.build-debian build-debian
 
 build-containers:build-debian-armhf:
   stage: build-containers
@@ -45,7 +45,7 @@ build-containers:build-debian-armhf:
     DOCKER_DRIVER: overlay2
   script:
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile.build-debian-armhf build-debian-armhf
+    - .gitlab-ci/pull-or-rebuild.sh base Dockerfile.build-debian-armhf build-debian-armhf
 
 build-containers:build-debian-arm64:
   stage: build-containers
@@ -57,7 +57,7 @@ build-containers:build-debian-arm64:
     DOCKER_DRIVER: overlay2
   script:
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile.build-debian-arm64 build-debian-arm64
+    - .gitlab-ci/pull-or-rebuild.sh base Dockerfile.build-debian-arm64 build-debian-arm64
 
 build-containers:build-debian-mips:
   stage: build-containers
@@ -69,7 +69,7 @@ build-containers:build-debian-mips:
     DOCKER_DRIVER: overlay2
   script:
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile.build-debian-mips build-debian-mips
+    - .gitlab-ci/pull-or-rebuild.sh base Dockerfile.build-debian-mips build-debian-mips
 
 build-containers:build-fedora:
   stage: build-containers
@@ -81,7 +81,7 @@ build-containers:build-fedora:
     DOCKER_DRIVER: overlay2
   script:
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile.build-fedora build-fedora
+    - .gitlab-ci/pull-or-rebuild.sh base Dockerfile.build-fedora build-fedora
 
 #################### BUILD #########################
 
@@ -296,4 +296,4 @@ containers:igt:
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
     - docker pull $CI_REGISTRY/$CI_PROJECT_PATH/build-fedora:commit-$CI_COMMIT_SHA
     - docker tag $CI_REGISTRY/$CI_PROJECT_PATH/build-fedora:commit-$CI_COMMIT_SHA build-fedora:commit-$CI_COMMIT_SHA
-    - .gitlab-ci/pull-or-rebuild.sh Dockerfile igt
+    - .gitlab-ci/pull-or-rebuild.sh igt Dockerfile igt
diff --git a/.gitlab-ci/pull-or-rebuild.sh b/.gitlab-ci/pull-or-rebuild.sh
index 7e69477e..3f00e831 100755
--- a/.gitlab-ci/pull-or-rebuild.sh
+++ b/.gitlab-ci/pull-or-rebuild.sh
@@ -21,9 +21,10 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
-DOCKERFILE=$1
-NAME=$2
-REF=${3:-${CI_COMMIT_REF_NAME:-latest}}
+TYPE=$1
+DOCKERFILE=$2
+NAME=$3
+REF=${4:-${CI_COMMIT_REF_NAME:-latest}}
 
 REF=$(echo $REF | tr / - )
 IMAGENAME=$CI_REGISTRY/$CI_PROJECT_PATH/$NAME
@@ -33,21 +34,31 @@ REFNAME=$IMAGENAME:$REF
 DOCKERNAME=$IMAGENAME:dockerfile-$DOCKERFILE_CHECKSUM
 COMMITNAME=$IMAGENAME:commit-$CI_COMMIT_SHA
 
-docker pull $DOCKERNAME
-IMAGE_PRESENT=$?
+if [ "$TYPE" = "base" ]; then
+	# base container (building, etc) - we rebuild only if changed or forced
+	docker pull $DOCKERNAME
+	IMAGE_PRESENT=$?
 
-set -e
-if [ $IMAGE_PRESENT -eq 0 ] && [ ${FORCE_REBUILD:-0} -eq 0 ] ; then
-	echo "Skipping, already built"
-	docker tag $DOCKERNAME $NAME
-	docker tag $DOCKERNAME $REFNAME
-	docker tag $DOCKERNAME $COMMITNAME
-else
-	echo "Building!"
+	set -e
+	if [ $IMAGE_PRESENT -eq 0 ] && [ ${FORCE_REBUILD:-0} -eq 0 ] ; then
+		echo "Skipping, already built"
+		docker tag $DOCKERNAME $COMMITNAME
+	else
+		echo "Building!"
+		docker build --build-arg=CI_COMMIT_SHA=$CI_COMMIT_SHA \
+			     -t $DOCKERNAME -t $COMMITNAME -f $DOCKERFILE .
+		docker push $DOCKERNAME
+    fi
+    docker push $COMMITNAME
+elif [ "$TYPE" = "igt" ]; then
+	# container with IGT, we don't care about Dockerfile changes
+	# we always rebuild
+	set -e
 	docker build --build-arg=CI_COMMIT_SHA=$CI_COMMIT_SHA \
-			 -t $DOCKERNAME -t $NAME \
-			 -t $REFNAME -t $COMMITNAME -f $DOCKERFILE .
-	docker push $DOCKERNAME
+		     -t $REFNAME -t $COMMITNAME -f $DOCKERFILE .
+	docker push $REFNAME
+	docker push $COMMITNAME
+else
+	echo "unknown build type $TYPE"
+	exit 1
 fi
-docker push $REFNAME
-docker push $COMMITNAME
-- 
2.21.0



More information about the igt-dev mailing list