diff --git a/README.md b/README.md index fff118cec2a6008e77026026ff44ab2073310b06..6649fa9bbbe025e0970a7913de5084723f453312 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ If you use **different registries** for snapshot and release images, you shall u There might be cases where you need to provide the complete [Docker configuration file](https://docs.docker.com/engine/reference/commandline/cli/#configuration-files): -* need to declare authentication credentials for other registries than the 2 predefined ones (snapshot & release), +* need to declare authentication credentials for other registries than the 2 predefined ones (snapshot & release), * need to declare a [credentials store](https://docs.docker.com/engine/reference/commandline/login/#credentials-store) (ex: in order to [publish to Amazon ECR](https://github.com/GoogleContainerTools/kaniko#pushing-to-amazon-ecr) with Kaniko for instance), * need to declare [proxies](https://docs.docker.com/engine/reference/commandline/cli/#automatic-proxy-configuration-for-containers), * ... @@ -136,7 +136,7 @@ If you are in one of those cases, you will need to use the `DOCKER_CONFIG_FILE` | ------------------------- | --------------------- | ------------------------------------------------- | | `DOCKER_CONFIG_FILE` | Path to the Docker configuration file (JSON) | `.docker/config.json` | -Moreover, this file supports **dynamic environment variables replacement**. +Moreover, this file supports **dynamic environment variables replacement**. That means it may contain references to other environment variables (in the format `${variable_name}`) that will be dynamically replaced by the template before evaluation. In addition to you own defined variables, you may use the following variables (provided and managed by the template): @@ -294,12 +294,13 @@ This job builds the image and publishes it to the _snapshot_ repository. It is bound to the `package-build` stage, and uses the following variables: -| Name | Description | Default value | -| ------------------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------ | -| `DOCKER_BUILD_ARGS` | Additional `docker/kaniko/buildah` `build` arguments | _(none)_ | -| `DOCKER_REGISTRY_MIRROR` | URL of a Docker registry mirror to use during the image build (instead of default `https://index.docker.io`) <br>:warning: Used by the `kaniko` and `dind` options only | _(none)_ | -| `CONTAINER_REGISTRIES_CONFIG_FILE` | The [`registries.conf`](https://www.redhat.com/sysadmin/manage-container-registries) configuration to be used<br>:warning: Used by the `buildah` build only | _(none)_ | -| `DOCKER_METADATA` | Additional `docker build`/`kaniko` arguments to set label | OCI Image Format Specification | +| Name | Description | Default value | +| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | +| `DOCKER_BUILD_ARGS` | Additional `docker/kaniko/buildah` `build` arguments | _(none)_ | +| `DOCKER_REGISTRY_MIRROR` | URL of a Docker registry mirror to use during the image build (instead of default `https://index.docker.io`) <br>:warning: Used by the `kaniko` and `dind` options only | _(none)_ | +| `CONTAINER_REGISTRIES_CONFIG_FILE` | The [`registries.conf`](https://www.redhat.com/sysadmin/manage-container-registries) configuration to be used<br>:warning: Used by the `buildah` build only | _(none)_ | +| `DOCKER_METADATA` | Additional `docker build`/`kaniko` arguments to set label | OCI Image Format Specification | +| `KANIKO_SNAPSHOT_IMAGE_CACHE` | Snapshot image repository that will be used to store cached layers<br>:warning: Used by the `kaniko` build only | `${DOCKER_SNAPSHOT_IMAGE%:*}/cache` | This job produces _output variables_ that are propagated to downstream jobs (using [dotenv artifacts](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#artifactsreportsdotenv)): diff --git a/kicker.json b/kicker.json index 9014da6161fd53fe20f03be5016a1fce6aef225d..70a5ea78e159a360fc4bd2cc8e8b061cb1dc445e 100644 --- a/kicker.json +++ b/kicker.json @@ -107,6 +107,12 @@ "name": "CONTAINER_REGISTRIES_CONFIG_FILE", "description": "The [registries.conf](https://www.redhat.com/sysadmin/manage-container-registries) configuration to be used\n\n_Used by the `buildah` build only_", "advanced": true + }, + { + "name": "KANIKO_SNAPSHOT_IMAGE_CACHE", + "description": "Snapshot image repository that will be used to store cached layers.\n\n_Used by the `kaniko` build only_", + "default": "${DOCKER_SNAPSHOT_IMAGE%:*}/cache", + "advanced": true } ], "features": [ diff --git a/templates/gitlab-ci-docker.yml b/templates/gitlab-ci-docker.yml index a5eea29add2a598c7eb49c686d6f66b910c9db47..735a0d73a591442a99d0f9ab096ff2743185457e 100644 --- a/templates/gitlab-ci-docker.yml +++ b/templates/gitlab-ci-docker.yml @@ -420,7 +420,7 @@ stages: function run_build_kaniko() { docker_image=$1 - kaniko_registry_repository="${DOCKER_SNAPSHOT_IMAGE%:*}" + kaniko_snapshot_image_cache="${KANIKO_SNAPSHOT_IMAGE_CACHE:-${DOCKER_SNAPSHOT_IMAGE%:*}/cache}" shift if [[ -n "$DOCKER_REGISTRY_MIRROR" ]] then @@ -428,9 +428,9 @@ stages: kaniko_registry_mirror_option="--registry-mirror $(echo ${DOCKER_REGISTRY_MIRROR} | sed "s|^https*://||")" fi log_info "Build & deploy image $docker_image" - log_info "Kaniko command: /kaniko/executor --context $(docker_context_path) --dockerfile $DOCKER_FILE --destination $docker_image --cache --cache-dir=${CI_PROJECT_DIR}/.cache --cache-repo=$kaniko_registry_repository --verbosity $DOCKER_KANIKO_VERBOSITY $kaniko_registry_mirror_option $DOCKER_METADATA $DOCKER_BUILD_ARGS $*" + log_info "Kaniko command: /kaniko/executor --context $(docker_context_path) --dockerfile $DOCKER_FILE --destination $docker_image --cache --cache-dir=${CI_PROJECT_DIR}/.cache --cache-repo=${kaniko_snapshot_image_cache} --verbosity $DOCKER_KANIKO_VERBOSITY $kaniko_registry_mirror_option $DOCKER_METADATA $DOCKER_BUILD_ARGS $*" # shellcheck disable=SC2086 - /kaniko/executor --context "$(docker_context_path)" --dockerfile "$DOCKER_FILE" --destination "$docker_image" --cache --cache-dir="${CI_PROJECT_DIR}/.cache" --cache-repo="$kaniko_registry_repository" --verbosity $DOCKER_KANIKO_VERBOSITY $kaniko_registry_mirror_option $DOCKER_METADATA $DOCKER_BUILD_ARGS "$@" + /kaniko/executor --context "$(docker_context_path)" --dockerfile "$DOCKER_FILE" --destination "$docker_image" --cache --cache-dir="${CI_PROJECT_DIR}/.cache" --cache-repo="${kaniko_snapshot_image_cache}" --verbosity $DOCKER_KANIKO_VERBOSITY $kaniko_registry_mirror_option $DOCKER_METADATA $DOCKER_BUILD_ARGS "$@" } # Used by containers tools like buildah, skopeo.