Commit 07752a18 authored by Simon Weimann's avatar Simon Weimann Committed by Pierre Smeyers
Browse files

feat: add build cache location support for buildah



Allow configuration of the build cache location for buildah the same as for kaniko.

/!\ Replaces $KANIKO_SNAPSHOT_IMAGE_CACHE with $DOCKER_BUILD_CACHE_LOCATION
A partial backward compatibility is ensured for projects using the $KANIKO_SNAPSHOT_IMAGE_CACHE variable but not with the 'kaniko-snapshot-image-cache' input that would fail the pipeline.

Signed-off-by: default avatarWeimann, Simon <simon.weimann@ruv.de>
parent 45d956d7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -345,7 +345,7 @@ It is bound to the `package-build` stage, and uses the following variables:
| :lock: `DOCKER_REGISTRY_MIRROR_PASSWORD`                                | Docker registry password for the mirror registry | _(none)_ |
| `container-registries-config-file` / `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)_                       |
| `metadata` / `DOCKER_METADATA`                                          | Additional `docker build`/`kaniko` arguments to set label                                                                                                                                                                                                                         | OCI Image Format Specification |
| `kaniko-snapshot-image-cache` / `KANIKO_SNAPSHOT_IMAGE_CACHE`           | Snapshot image repository that will be used to store cached layers (leave empty to use default: snapshot image repository + `/cache`)<br>:warning: Used by the `kaniko` build only                                                                                                | _none_ (default cache path)    |
| `build-cache-location` / `DOCKER_BUILD_CACHE_LOCATION`                  | Location to store cached layers when using build-cache (leave empty to use default: snapshot-image + `/cache`)<br>:warning: Used by the `kaniko` and `buildah` build only                                                                                                         | snapshot-image + `/cache`      |
| `build-cache-disabled` / `DOCKER_BUILD_CACHE_DISABLED`                  | Set to `true` to disable the build cache.<br/>Cache can typically be disabled when there is a network latency between the container registry and the runner.                                                                                                                      | _none_ (i.e cache enabled)     |
| `push-args` / `DOCKER_PUSH_ARGS`                                        | Additional `push` arguments for [docker](https://docs.docker.com/reference/cli/docker/image/push/) or [buildah](https://github.com/containers/buildah/blob/main/docs/buildah-push.1.md) (executed right after `build`).<br>Ex: `--compression-format zstd --compression-level 20` | _(none)_                       |

+5 −5
Original line number Diff line number Diff line
@@ -110,17 +110,17 @@
      "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 (leave empty to use default: snapshot image repository + `/cache`)\n\n_Used by the `kaniko` build only_",
      "advanced": true
    },
    {
      "name": "DOCKER_BUILD_CACHE_DISABLED",
      "description": "Set to `true` to disable the build cache.",
      "type": "boolean",
      "advanced": true
    },
    {
      "name": "DOCKER_BUILD_CACHE_LOCATION",
      "description": "Location to store cached layers when using build-cache (leave empty to use default: snapshot-image + `/cache`)\n\n_Used by the `kaniko` and `buildah` build only_",
      "advanced": true
    },
    {
      "name": "DOCKER_PUSH_ARGS",
      "description": "Additional docker/buildah `push` arguments (executed right after `build`).\n\nEx: `--compression-format zstd --compression-level 20`",
+10 −9
Original line number Diff line number Diff line
@@ -87,6 +87,12 @@ spec:
      description: Disable the build cache
      type: boolean
      default: false
    build-cache-location:
      description: |-
        Location to store cached layers when using build-cache (leave empty to use default: snapshot-image + `/cache`)

        _Used by the `kaniko` and `buildah` build only_
      default: ''
    metadata:
      description: Additional metadata to set as labels
      default: >-
@@ -122,12 +128,6 @@ spec:

        _Used by the `buildah` build only_
      default: ''
    kaniko-snapshot-image-cache:
      description: |-
        Snapshot image repository that will be used to store cached layers (leave empty to use default: snapshot image repository + `/cache`)

        _Used by the `kaniko` build only_
      default: ''
    hadolint-disabled:
      description: Disable Hadolint
      type: boolean
@@ -315,11 +315,11 @@ variables:
  DOCKER_RELEASE_EXTRA_TAGS: $[[ inputs.release-extra-tags ]]
  DOCKER_BUILD_ARGS: $[[ inputs.build-args ]]
  DOCKER_BUILD_CACHE_DISABLED: $[[ inputs.build-cache-disabled ]]
  DOCKER_BUILD_CACHE_LOCATION: $[[ inputs.build-cache-location ]]
  DOCKER_PUBLISH_ARGS: $[[ inputs.publish-args ]]
  DOCKER_SEMREL_RELEASE_DISABLED: $[[ inputs.semrel-release-disabled ]]
  DOCKER_REGISTRY_MIRROR: $[[ inputs.registry-mirror ]]
  CONTAINER_REGISTRIES_CONFIG_FILE: $[[ inputs.container-registries-config-file ]]
  KANIKO_SNAPSHOT_IMAGE_CACHE: $[[ inputs.kaniko-snapshot-image-cache ]]
  DOCKER_PUSH_ARGS: $[[ inputs.push-args ]]
  DOCKER_HADOLINT_DISABLED: $[[ inputs.hadolint-disabled ]]
  DOCKER_HADOLINT_ARGS: $[[ inputs.hadolint-args ]]
@@ -827,7 +827,8 @@ stages:
  function run_build_kaniko() {
    docker_image=$1
    if [ "$DOCKER_BUILD_CACHE_DISABLED" != "true" ]; then
      kaniko_snapshot_image_cache="${KANIKO_SNAPSHOT_IMAGE_CACHE:-${DOCKER_SNAPSHOT_IMAGE%:*}/cache}"
      # Backward compatibility until buildah become the default build tool
      kaniko_snapshot_image_cache="${KANIKO_SNAPSHOT_IMAGE_CACHE:-${DOCKER_BUILD_CACHE_LOCATION:-${DOCKER_SNAPSHOT_IMAGE%:*}/cache}}"
      kaniko_cache_args="--cache --cache-dir=${CI_PROJECT_DIR}/.cache --cache-repo=${kaniko_snapshot_image_cache}"
      log_info "Build cache enabled; CLI options: ${kaniko_cache_args}"
    fi
@@ -1130,7 +1131,7 @@ docker-buildah-build:
    # Add build cache related parameters.
    - |
      if [ "$DOCKER_BUILD_CACHE_DISABLED" != "true" ]; then
          buildah_build_cache="${DOCKER_SNAPSHOT_IMAGE%:*}/cache"
          buildah_build_cache="${DOCKER_BUILD_CACHE_LOCATION:-${DOCKER_SNAPSHOT_IMAGE%:*}/cache}"
          buildah_cache_args="--layers --cache-from $buildah_build_cache --cache-to $buildah_build_cache"
          log_info "Build cache enabled; CLI options: ${buildah_cache_args}"
      fi