Re: [igt-dev] [PATCH v3 5/6] gitlab-ci: rebuild images only on Dockerfile changes

Arkadiusz Hiler
2019-08-26T13:58:02Z

On Mon, Aug 26, 2019 at 04:12:47PM +0300, Oleg Vasilev wrote:
> diff --git a/gitlab-ci/pull-or-rebuild.sh b/gitlab-ci/pull-or-rebuild.sh
> new file mode 100755
> index 00000000..3bf9296f
> --- /dev/null
> +++ b/gitlab-ci/pull-or-rebuild.sh
> @@ -0,0 +1,51 @@
> +#!/bin/sh
> +#
> +# Copyright © 2019 Intel Corporation
> +#
> +# Permission is hereby granted, free of charge, to any person obtaining a
> +# copy of this software and associated documentation files (the "Software"),
> +# to deal in the Software without restriction, including without limitation
> +# the rights to use, copy, modify, merge, publish, distribute, sublicense,
> +# and/or sell copies of the Software, and to permit persons to whom the
> +# Software is furnished to do so, subject to the following conditions:
> +#
> +# The above copyright notice and this permission notice (including the next
> +# paragraph) shall be included in all copies or substantial portions of the
> +# Software.
> +#
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> +# IN THE SOFTWARE.
> +
> +DOCKERFILE=$1
> +NAME=$2
> +TAG=${3:-${CI_COMMIT_REF_NAME:-latest}}
> +
> +TAG=$(echo $TAG | tr / - )

The issue here is that ref may contain '/' (and it does for the CI
tags), so we have to do that translation here, but we cannot just use
CI_COMMIT_REF_NAME in the `image:` in the .gitlab-ci.yml.

I am fine with keeping the ref tags up to date, but I think we should
additionally use just the commit's SHA1 for tagging.

I think that we should tag the images in 3 ways:
a) dockerfile-$(sha1sum Dockerfile...)
b) commit-${CI_COMMIT_SHA}
c) $(echo ${CI_COMMIT_REF_NAME}-latest | tr / -)

We would use (a) for checking whether we have anything to build, and (b)
for `image:` in .gitlab-ci.yml. (c) is purely for human convenience.

--
Cheers,
Arek