publish Trait

Attributes

name

required?

default

type

explanation

dockerimages

yes

None

Dict[str, PublishDockerImageDescriptor]

specifies the container images to be built

oci-builder

no

docker

OciBuilder

specifies the container image builder to use

no-buildkit

no

False

bool

if using docker as oci-builder, force to not use buildkit - ignored otherwise

platforms

no

None

list

if defined, all image-builds will be done for each of the specified platforms, which may result in cross-platform builds. Only supported if using docker-buildx as oci-builder.

As an implementation detail that may change in the future, multiarch/quemu-user-static (see) is used. As the underlying CICD nodes use Linux as kernel, only the architecture may be chosen. The following platforms are supported:

  • linux/386

  • linux/amd64 # aka x86_64

  • linux/arm/v6

  • linux/arm/v7

  • linux/arm64

  • linux/ppc64le

  • linux/riscv64

  • linux/s390x

The resulting images will receive tags derived from the default tag (single-image case) with a suffix containing the platform.

The default tag will be published as multi-arch image, referencing all platform-variants. This will also hold true if only one platform is specified.

Note

if specifying a list of platforms, _all_ platforms (including the default platform) must be explicitly specified.

dockerimages.<user-chosen> (PublishDockerImageDescriptor) Attributes

name

required?

default

type

explanation

registry

no

None

str

name of the registry config to use when pushing the image.

image

no

None

str

image reference to publish the created container image to. required if on targets are set

extra_push_targets

no

[]

list

additional targets to publish built images to. Entries _may_ contain a tag (which is honoured, if present). Entries without a tag will use the same tag as the “main” image (defined by image attribute). only supported for docker or docker-buildx OCI-Builder. Must not be used in conjunction with targets.

inputs

no

repos: null
steps: {}

dict

configures the inputs that are made available to image build

prebuild_hook

no

None

str

if configured, a callback is executed prior to running image-build. the value is interpreted as relative path to main-repository root directory, and must be an executable file. It can be used, for example, to preprocess the “Dockerfile” to use, or to prepare contents within the build directory. The following environment variables are passed (all paths are absolute): - BUILD_DIR # path to build directory - DOCKERFILE # path to dockerfile

Only supported for oci-builder docker or docker-buildx. dockerd will be available and running (docker excecutable accessible from PATH).

tag_as_latest

no

False

bool

whether or not published container images should also be labeled as latest

tag_template

no

${EFFECTIVE_VERSION}

str

the template to use for the image-tag (only variable: EFFECTIVE_VERSION)

dockerfile

no

Dockerfile

str

the file to use for building the container image

dir

no

None

str

the relative path to the container image build file

target

no

None

str

only for multistage builds: the target up to which to build. must not be used if targets is defined.

targets

no

None

list

if set, the given targets are built in the given order in the same build environment. This is useful to reduce resource consumption for multiple builds sharing common prerequisite build steps. Only supported if oci-builder is set to docker-buildx or docker

resource_labels

no

[]

List[Label]

labels to add to the resource declaration for this image in base-component-descriptor

build_args

no

{}

Dict[str, str]

build-time arguments to pass to docker-build

platforms

no

None

list

If platforms is defined at toplevel, then defining it again for a single image-build can be done in order to only build this image for a subset of platforms.

see toplevel documentation for platforms for reference.

oci-builder Enumeration Values

  • kaniko

  • docker

  • docker-buildx

Dependencies

This trait requires the following traits to be declared:

Used to build and publish container images in the declaring build jobs. An arbitrary amount of container images may be specified (at least one).

The effective version is used as image tag. Optionally, created images may be tagged as ‘latest’.

Each container image build is run in a directory with definable contents (see inputs attribute) using the specified Dockerfile.

inputs Attribute

By default, the main repository’s work tree is copied into the build directory. This behaviour may be changed by defining different logical repository names for inputs.repos.

To consume (build) results created by other build steps, those outputs are specified with the inputs.steps attribute.

Build steps that are specified as inputs may declare the optional output_dir attribute. They are expected to place their outputs into a directory indicated by an environment variable named <OUTPUT_DIR>_PATH (defaults to BINARY_PATH).

implicitly injected build steps

Defining this trait will implicitly add two build steps, named prepare, publish. Thus, those step names are not allowed to be used in job definitions with this trait.

The publish step is guaranteed to always run _after_ the prepare step.

By default, both publish and prepare steps are run _after_ all other steps, with the notable exception of the release step (from the release trait).

Example

steps:
  build:
    output_dir: 'build_result'  # 'build' must cp to ${BUILD_RESULT_PATH}
traits:
  publish:
    dockerimages:
      first_image: # logical image name
        image: 'eu.grc.io/gardener-project/example/image'
        dockerfile: 'Dockerfile'
        tag_as_latest: True
        inputs:
          repos:
            source: ~  # this is the default (--> use main repository)
          steps:
            build: ~   # copy results of step 'build' over source tree
      second_image:
        image: 'eu.gcr.io/gardener-project/example/second_image
        dockerfile: 'AnotherDockerfile'