Initial version new build pattern

This commit is contained in:
Lukas Eipert 2022-02-21 14:49:55 +01:00
parent 51e4dea7ac
commit c3e3882320
8 changed files with 75 additions and 2 deletions

View file

@ -2,6 +2,7 @@
include:
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
- local: '.gitlab/ci/*.yml'
- local: '.gitlab/**/.gitlab-ci.yml'
default:
image: docker:20.10.9-git
@ -14,6 +15,7 @@ default:
- gitlab-org-docker
stages:
- kaniko
- test
- deploy
- automation

View file

@ -30,7 +30,6 @@ gitlab-qa-ruby-3.0 test: *test_build
gitlab-qa-alpine-ruby-2.7 test: *test_build
gitlab-qa-alpine-ruby-3.0 test: *test_build
gitlab-puppeteer test: *test_build
kaniko test: *test_build
omnibus-gitlab-bionic test: *test_build
omnibus-gitlab-centos7 test: *test_build
omnibus-gitlab-centos8 test: *test_build
@ -77,7 +76,6 @@ gitlab-qa-ruby-3.0 push: *build_and_deploy
gitlab-qa-alpine-ruby-2.7 push: *build_and_deploy
gitlab-qa-alpine-ruby-3.0 push: *build_and_deploy
gitlab-puppeteer push: *build_and_deploy
kaniko push: *build_and_deploy
omnibus-gitlab-bionic push: *build_and_deploy
omnibus-gitlab-centos7 push: *build_and_deploy
omnibus-gitlab-centos8 push: *build_and_deploy

View file

@ -23,3 +23,19 @@
script:
- ./scripts/custom-docker-build --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL"
- ./scripts/custom-docker-push
.build-with-kaniko:
needs: []
tags:
- gitlab-org
stage: kaniko
resource_group: ${CI_COMMIT_REF_SLUG}_${CI_JOB_NAME}
image: registry.gitlab.com/gitlab-org/frontend/frontend-build-images/build-image
script:
- ./scripts/kaniko-image-build "$CI_JOB_NAME"
rules:
- changes:
- ${CI_JOB_NAME}/*
- scripts/kaniko-image-build
when: always
- when: manual

0
kaniko/.gitlab-ci.yml Normal file
View file

3
kaniko/README.md Normal file
View file

@ -0,0 +1,3 @@
# registry.gitlab.com/gitlab-org/gitlab-build-images/kaniko
This is a image around the `kaniko` executor

1
kaniko/VERSION Normal file
View file

@ -0,0 +1 @@
1.0.0

53
scripts/kaniko-image-build Executable file
View file

@ -0,0 +1,53 @@
#!/usr/bin/env sh
set -e
if [ -z "$1" ] || [ ! -d "$1" ]; then
echo "Please supply an image that you want to build as an argument"
echo "Valid images are:"
ls -d -- */
exit 1
fi
IMAGE_BASE=${CI_REGISTRY_IMAGE:-frontend-build-images}
IMAGE_NAME=$(echo "$1" | sed "s#/##g")
COMMIT_REF=${CI_COMMIT_REF_NAME:-unstable}
IMAGE_TAG=$(cat "$IMAGE_NAME/VERSION")
if [ "$COMMIT_REF" = "$CI_DEFAULT_BRANCH" ]; then
DOCKER_IMAGE="$IMAGE_BASE/$IMAGE_NAME:$IMAGE_TAG"
else
IMAGE_POSTFIX=${CI_COMMIT_SHORT_SHA:-unstable}
DOCKER_IMAGE="$IMAGE_BASE/unstable/$IMAGE_NAME:$IMAGE_TAG-$IMAGE_POSTFIX"
fi
KANIKO_ARGS=${KANIKO_ARGS:-}
if [ "$CI" = "true" ]; then
echo "Running on CI, so we check if the image already exists"
if crane manifest "$DOCKER_IMAGE" >/dev/null; then
echo "Image $DOCKER_IMAGE already exists, skip building"
exit 0
fi
else
echo "Not running on CI, so not pushing"
KANIKO_ARGS="$KANIKO_ARGS --no-push"
fi
echo "Building image $DOCKER_IMAGE"
/kaniko/executor \
--context "$IMAGE_NAME" \
--dockerfile "$IMAGE_NAME/Dockerfile" \
--destination "$DOCKER_IMAGE" \
--single-snapshot \
$KANIKO_ARGS
if [ "$CI" = "true" ]; then
echo "Running on CI, so we push the built image"
crane push image.tar "$DOCKER_IMAGE"
if [ "$COMMIT_REF" = "$CI_DEFAULT_BRANCH" ]; then
echo "Tagging $DOCKER_IMAGE as latest"
crane tag "$DOCKER_IMAGE" latest
fi
fi