diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5e47b9..ad699d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/.gitlab/ci/custom.images.yml b/.gitlab/ci/custom.images.yml index 1fd9ce4..56f37c3 100644 --- a/.gitlab/ci/custom.images.yml +++ b/.gitlab/ci/custom.images.yml @@ -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 diff --git a/.gitlab/ci/definitions.yml b/.gitlab/ci/definitions.yml index ff0d3ad..06e63f7 100644 --- a/.gitlab/ci/definitions.yml +++ b/.gitlab/ci/definitions.yml @@ -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 \ No newline at end of file diff --git a/kaniko/.gitlab-ci.yml b/kaniko/.gitlab-ci.yml new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile.kaniko b/kaniko/Dockerfile similarity index 100% rename from Dockerfile.kaniko rename to kaniko/Dockerfile diff --git a/kaniko/README.md b/kaniko/README.md new file mode 100644 index 0000000..0d9b3b3 --- /dev/null +++ b/kaniko/README.md @@ -0,0 +1,3 @@ +# registry.gitlab.com/gitlab-org/gitlab-build-images/kaniko + +This is a image around the `kaniko` executor \ No newline at end of file diff --git a/kaniko/VERSION b/kaniko/VERSION new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/kaniko/VERSION @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/scripts/kaniko-image-build b/scripts/kaniko-image-build new file mode 100755 index 0000000..4cdc05d --- /dev/null +++ b/scripts/kaniko-image-build @@ -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