Last active
June 26, 2024 09:54
-
-
Save loliee/8275474dcba37a0e03ffe7041d439368 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this template to build a docker image | |
# You should add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. | |
--- | |
spec: | |
inputs: | |
context: | |
image_name: | |
image_tag: | |
slug_name: | |
git_author: | |
git_hash: | |
label_prefix: | |
registry: | |
default: myreg.io | |
--- | |
stages: | |
- build | |
- analyse | |
- push | |
- test | |
variables: | |
TEST_IMAGE_NAME: $CI_REGISTRY_IMAGE/$[[ inputs.image_name ]]:$CI_COMMIT_REF_SLUG | |
IMAGE_ARCHIVE_PATH: builds/$[[ inputs.image_name ]]-$[[ inputs.image_tag ]].tar | |
docker:build:$[[ inputs.context ]]: | |
stage: build | |
image: | |
name: myreg.io/kaniko-project/executor:v1.15.0-debug | |
before_script: | |
- > | |
cd "${CI_PROJECT_DIR}/docker/$[[ inputs.context ]]/"; | |
if [[ -f pre-build ]]; then sh ./pre-build ; fi; | |
echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"},\"$(echo -n $CI_DEPENDENCY_PROXY_SERVER | awk -F[:] '{print $1}')\":{\"auth\":\"$(printf "%s:%s" ${CI_DEPENDENCY_PROXY_USER} "${CI_DEPENDENCY_PROXY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json; | |
cd - | |
script: | |
- /kaniko/executor | |
--context "${CI_PROJECT_DIR}/docker/$[[ inputs.context ]]" | |
--dockerfile "${CI_PROJECT_DIR}/docker/$[[ inputs.context ]]/Dockerfile" | |
--no-push | |
--destination "${CI_REGISTRY_IMAGE}/$[[ inputs.image_name ]]:${CI_COMMIT_REF_SLUG}" | |
--tar-path "builds/$[[ inputs.image_name ]]-$[[ inputs.image_tag ]].tar" | |
artifacts: | |
paths: | |
- builds/* | |
when: on_success | |
docker:analyse:$[[ inputs.context ]]: | |
stage: analyse | |
image: | |
name: myreg.io/wagoodman/dive:v0.11 | |
before_script: | |
- echo "Analyse image ${CI_PROJECT_DIR}/builds/$[[ inputs.image_name ]]-$[[ inputs.image_tag ]].tar" | |
script: | |
- CI=true dive "docker-archive:///${CI_PROJECT_DIR}/builds/$[[ inputs.image_name ]]-$[[ inputs.image_tag ]].tar" | |
needs: | |
- docker:build:$[[ inputs.context ]] | |
docker:push-test-image:$[[ inputs.context ]]: | |
stage: push | |
image: | |
name: myreg.io/go-containerregistry/crane:debug | |
entrypoint: [""] | |
before_script: | |
- echo "Publish image ${CI_REGISTRY_IMAGE}/$[[ inputs.image_name ]]:${CI_COMMIT_REF_SLUG} builds/$[[ inputs.image_name ]]-$[[ inputs.image_tag ]].tar" | |
script: | |
- crane auth login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} | |
- crane push "builds/$[[ inputs.image_name ]]-$[[ inputs.image_tag ]].tar" "${CI_REGISTRY_IMAGE}/$[[ inputs.image_name ]]:${CI_COMMIT_REF_SLUG}" | |
needs: | |
- docker:build:$[[ inputs.context ]] | |
- docker:analyse:$[[ inputs.context ]] | |
docker:test:$[[ inputs.context ]]: | |
stage: test | |
# TODO this stage from image .tar.gz when possilbe by Gitlab | |
image: | |
name: "${CI_REGISTRY_IMAGE}/$[[ inputs.image_name ]]:${CI_COMMIT_REF_SLUG}" | |
pull_policy: always | |
before_script: | |
- echo "Test image ${CI_REGISTRY_IMAGE}/$[[ inputs.image_name ]]:${CI_COMMIT_REF_SLUG}" | |
script: | |
- # TODO run goss | |
dependencies: [] | |
needs: | |
- docker:push-test-image:$[[ inputs.context ]] | |
# Crane push if tests are ok ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment