Loading .gitlab-ci.d/funcs.shdeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line # Copyright (c) 2020 Dom Sekotill <dom.sekotill@kodo.org.uk> # # 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 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. CACHE_IMG=${CI_REGISTRY_IMAGE}/cache RW_CACHE1=${CACHE_IMG}:latest RW_CACHE2=${CACHE_IMG}:${CI_COMMIT_REF_NAME} RW_CACHE3=${CACHE_IMG}:${CI_COMMIT_SHA} RO_CACHE1=${CACHE_IMG}:${CI_COMMIT_BEFORE_SHA} cache_arg() { arg="--cache-from=${RW_CACHE1},${RW_CACHE2},${RW_CACHE3},${RO_CACHE1}" sed -n 's/FROM \([^ ]*:[^ ]*\).*/\1/p' Dockerfile | while read image; do arg+=",$image"; done echo "$arg" } push_cache() ( for tag in ${RW_CACHE1} ${RW_CACHE2} ${RW_CACHE3}; do docker tag ${1? Please specify a source image} ${tag} docker push ${tag} done ) .gitlab-ci.yml +16 −34 Original line number Diff line number Diff line image: docker:stable variables: DOCKER_HOST: "tcp://docker:2375/" DOCKER_DRIVER: "overlay2" DOCKER_BUILDKIT: "1" DOCKER_TLS_CERTDIR: "" CONTACT_REGISTRY: "yes" services: - docker:dind before_script: - docker info - docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" "$CI_REGISTRY" - . .gitlab-ci.d/funcs.sh REPO: ${CI_REGISTRY_IMAGE}:pipeline-${CI_PIPELINE_IID} build: except: [tags] variables: REPO: ${CI_REGISTRY_IMAGE}/build:${CI_PIPELINE_ID} Build: stage: build image: docker.kodo.org.uk/ci-images/buildkit/buildctl:latest tags: [buildkit] script: - docker build . --tag=${REPO} --target=scripts --build-arg BUILDKIT_INLINE_CACHE=1 $(cache_arg) - docker push ${REPO} - push_cache ${REPO} - buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --opt target=scripts --output type=image,name=$REPO,push=true build:tag: Push Tags: image: docker.kodo.org.uk/ci-images/docker-reg:latest only: variables: - $CI_COMMIT_TAG =~ /^v[0-9]/ except: [] extends: [build] after_script: - docker tag ${REPO} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG#v} - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG#v} - docker tag ${REPO} ${CI_REGISTRY_IMAGE}:latest - docker push ${CI_REGISTRY_IMAGE}:latest script: - docker-reg $REPO retag ${CI_COMMIT_TAG#v} - docker-reg $REPO retag latest Loading
.gitlab-ci.d/funcs.shdeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line # Copyright (c) 2020 Dom Sekotill <dom.sekotill@kodo.org.uk> # # 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 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. CACHE_IMG=${CI_REGISTRY_IMAGE}/cache RW_CACHE1=${CACHE_IMG}:latest RW_CACHE2=${CACHE_IMG}:${CI_COMMIT_REF_NAME} RW_CACHE3=${CACHE_IMG}:${CI_COMMIT_SHA} RO_CACHE1=${CACHE_IMG}:${CI_COMMIT_BEFORE_SHA} cache_arg() { arg="--cache-from=${RW_CACHE1},${RW_CACHE2},${RW_CACHE3},${RO_CACHE1}" sed -n 's/FROM \([^ ]*:[^ ]*\).*/\1/p' Dockerfile | while read image; do arg+=",$image"; done echo "$arg" } push_cache() ( for tag in ${RW_CACHE1} ${RW_CACHE2} ${RW_CACHE3}; do docker tag ${1? Please specify a source image} ${tag} docker push ${tag} done )
.gitlab-ci.yml +16 −34 Original line number Diff line number Diff line image: docker:stable variables: DOCKER_HOST: "tcp://docker:2375/" DOCKER_DRIVER: "overlay2" DOCKER_BUILDKIT: "1" DOCKER_TLS_CERTDIR: "" CONTACT_REGISTRY: "yes" services: - docker:dind before_script: - docker info - docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" "$CI_REGISTRY" - . .gitlab-ci.d/funcs.sh REPO: ${CI_REGISTRY_IMAGE}:pipeline-${CI_PIPELINE_IID} build: except: [tags] variables: REPO: ${CI_REGISTRY_IMAGE}/build:${CI_PIPELINE_ID} Build: stage: build image: docker.kodo.org.uk/ci-images/buildkit/buildctl:latest tags: [buildkit] script: - docker build . --tag=${REPO} --target=scripts --build-arg BUILDKIT_INLINE_CACHE=1 $(cache_arg) - docker push ${REPO} - push_cache ${REPO} - buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --opt target=scripts --output type=image,name=$REPO,push=true build:tag: Push Tags: image: docker.kodo.org.uk/ci-images/docker-reg:latest only: variables: - $CI_COMMIT_TAG =~ /^v[0-9]/ except: [] extends: [build] after_script: - docker tag ${REPO} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG#v} - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG#v} - docker tag ${REPO} ${CI_REGISTRY_IMAGE}:latest - docker push ${CI_REGISTRY_IMAGE}:latest script: - docker-reg $REPO retag ${CI_COMMIT_TAG#v} - docker-reg $REPO retag latest