summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@gmail.com>2019-03-21 09:35:40 +0100
committerPeter Hutterer <peter.hutterer@who-t.net>2019-04-09 10:31:05 +1000
commit0ae355ad5961fda5fc09c3ceeb1a686f660384ec (patch)
tree04112e8a5a0382247ba134ed433b8170c3da4c59
parent6e7a52b87f579bf6c7cf9696cdf3d228c63efe79 (diff)
CI: simplify the logic for rebuilding the containers
right now the check_if_older_than_a_week rule does (in pseudo-code): - get timestamp of current image or 0 - get timestamp of upstream image or 0 - if upstream image is newer than current image copy upstream image into current - if we are in a scheduled pipeline, or if there is no current image (timestamp of 0), rebuild the current image The ci-templates if-not-exists rule does: - if there is a current image, exit - if there is an upstream image, copy it to current and exit - rebuild Having the following is equivalent to the current behaviour and can be used instead of check_if_older_than_a_week: - if there is an upstream image, copy it to current and exit - if there is a current image, exit - rebuild Because what matters is: forks should be running the upstream image if available forks should be running the latest upstream image in the libinput case forks should be able to rebuild the images if there is no upstream (change of the image tag) Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> (cherry picked from commit 6d96d417a01f53a62675c6804316d5fa760ea0c1)
-rw-r--r--.gitlab-ci.yml46
1 files changed, 16 insertions, 30 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5fa5a2de..6ce5ba0e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -117,7 +117,7 @@ variables:
# is too old or if it is missing some dependencies.
#
-.check_if_older_than_a_week: &check_if_older_than_a_week
+.pull_upstream_or_rebuild: &pull_upstream_or_rebuild
before_script:
# log in to the registry
- podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
@@ -125,31 +125,17 @@ variables:
# get the full container image name (DISTRIB_VERSION still has indirections)
- IMAGE=$(eval echo "$DISTRIB_FLAVOR/$DISTRIB_VERSION:$TAG")
- # check if our image is already in the current registry and get its date
- - LOCAL_IMG_DATE=$(skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE | jq -r '.Created' | cut -dT -f1 ||
- echo 1970-01-01)
-
- # get the date of the upstream image
- - UPSTREAM_IMG_DATE=$(skopeo inspect docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE | jq -r '.Created' | cut -dT -f1 ||
- echo 1970-01-01)
-
- - TODAY_SECS=$(date -u +%s)
- - LOCAL_IMG_SECS=$(date -u --date="$LOCAL_IMG_DATE" +%s)
- - UPSTREAM_IMG_SECS=$(date -u --date="$UPSTREAM_IMG_DATE" +%s)
- - echo "today $TODAY_SECS, local image $LOCAL_IMG_SECS, upstream image $UPSTREAM_IMG_SECS"
- - echo "image ages $(($TODAY_SECS - $LOCAL_IMG_SECS))s and $(($TODAY_SECS - $UPSTREAM_IMG_SECS))s"
-
- # if the upstream image is more recent, use it
- - if [[ $UPSTREAM_IMG_SECS -gt $LOCAL_IMG_SECS ]] ;
+ - |
+ # force rebuild if schedule, reuse otherwise
+ if [[ $CI_PIPELINE_SOURCE != "schedule" ]] ;
then
- skopeo copy docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE
- docker://$CI_REGISTRY_IMAGE/$IMAGE ;
- LOCAL_IMG_SECS=UPSTREAM_IMG_SECS ;
- fi
-
- # if the image exists and we are not in the scheduled pipeline, exit
- - test $LOCAL_IMG_SECS -gt 0 -a $CI_PIPELINE_SOURCE != "schedule" && exit 0
+ # pull the latest upstream image if it exists
+ skopeo copy docker://$CI_REGISTRY/$UPSTREAM_REPO/$IMAGE \
+ docker://$CI_REGISTRY_IMAGE/$IMAGE && exit 0 || true ;
+ # check if our image is already in the current registry
+ skopeo inspect docker://$CI_REGISTRY_IMAGE/$IMAGE > /dev/null && exit 0 || true ;
+ fi
fedora:28@container-prep:
extends: .fedora@container-build
@@ -160,7 +146,7 @@ fedora:28@container-prep:
DISTRIB_FLAVOR: fedora
DISTRIB_VERSION: $FEDORA_VERSION
TAG: $FEDORA_TAG
- <<: *check_if_older_than_a_week
+ <<: *pull_upstream_or_rebuild
fedora:29@container-prep:
extends: .fedora@container-build
@@ -171,7 +157,7 @@ fedora:29@container-prep:
DISTRIB_FLAVOR: fedora
DISTRIB_VERSION: $FEDORA_VERSION
TAG: $FEDORA_TAG
- <<: *check_if_older_than_a_week
+ <<: *pull_upstream_or_rebuild
ubuntu:18.10@container-prep:
@@ -183,7 +169,7 @@ ubuntu:18.10@container-prep:
DISTRIB_FLAVOR: ubuntu
DISTRIB_VERSION: $UBUNTU_VERSION
TAG: $UBUNTU_TAG
- <<: *check_if_older_than_a_week
+ <<: *pull_upstream_or_rebuild
ubuntu:18.04@container-prep:
extends: .ubuntu@container-build
@@ -194,7 +180,7 @@ ubuntu:18.04@container-prep:
DISTRIB_FLAVOR: ubuntu
DISTRIB_VERSION: $UBUNTU_VERSION
TAG: $UBUNTU_TAG
- <<: *check_if_older_than_a_week
+ <<: *pull_upstream_or_rebuild
arch:rolling@container-prep:
@@ -206,12 +192,12 @@ arch:rolling@container-prep:
DISTRIB_FLAVOR: archlinux
DISTRIB_VERSION: $ARCH_VERSION
TAG: $ARCH_TAG
- <<: *check_if_older_than_a_week
+ <<: *pull_upstream_or_rebuild
.freebsd@container-prep:
stage: container_prep
image: $BUILDAH_IMAGE
- <<: *check_if_older_than_a_week
+ <<: *pull_upstream_or_rebuild
script:
- buildcntr=$(buildah from --quiet myfreeweb/freebsd-cross:latest)
- buildah run $buildcntr apk add --no-cache $FREEBSD_BUILD_PKGS