From 9e169162b0a4b4b33ad6eba3fc618d0b5a052e1d Mon Sep 17 00:00:00 2001 From: ericdstein Date: Sun, 12 Dec 2021 14:54:46 -0600 Subject: [PATCH 1/3] support kaniko force-build-metadata flag --- cmd/vela-kaniko/image.go | 2 ++ cmd/vela-kaniko/main.go | 15 +++++++++++---- cmd/vela-kaniko/plugin.go | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/vela-kaniko/image.go b/cmd/vela-kaniko/image.go index f211b84..d618031 100644 --- a/cmd/vela-kaniko/image.go +++ b/cmd/vela-kaniko/image.go @@ -20,6 +20,8 @@ type Image struct { Dockerfile string // build stage to target for image Target string + // enable force adding metadata layers to build image + ForceBuildMetadata bool } // Validate verifies the Image is properly configured. diff --git a/cmd/vela-kaniko/main.go b/cmd/vela-kaniko/main.go index 670c5a6..658192b 100644 --- a/cmd/vela-kaniko/main.go +++ b/cmd/vela-kaniko/main.go @@ -122,6 +122,12 @@ func main() { Name: "image.target", Usage: "build stage to target for image", }, + &cli.StringFlag{ + EnvVars: []string{"PARAMETER_FORCE_BUILD_METADATA", "KANIKO_FORCE_BUILD_METADATA"}, + FilePath: "/vela/parameters/kaniko/force_build_metadata,/vela/secrets/kaniko/force_build_metadata", + Name: "image.force_build_metadata", + Usage: "enables force adding metadata layers to build image", + }, // Registry Flags @@ -276,10 +282,11 @@ func run(c *cli.Context) error { }, // image configuration Image: &Image{ - Args: c.StringSlice("image.build_args"), - Context: c.String("image.context"), - Dockerfile: c.String("image.dockerfile"), - Target: c.String("image.target"), + Args: c.StringSlice("image.build_args"), + Context: c.String("image.context"), + Dockerfile: c.String("image.dockerfile"), + Target: c.String("image.target"), + ForceBuildMetadata: c.Bool("image.force_build_metadata"), }, // registry configuration Registry: &Registry{ diff --git a/cmd/vela-kaniko/plugin.go b/cmd/vela-kaniko/plugin.go index 668cefc..a6f2d46 100644 --- a/cmd/vela-kaniko/plugin.go +++ b/cmd/vela-kaniko/plugin.go @@ -129,6 +129,11 @@ func (p *Plugin) Command() *exec.Cmd { flags = append(flags, fmt.Sprintf("--target=%s", p.Image.Target)) } + // check if forcebuildmetadata is set + if p.Image.ForceBuildMetadata { + flags = append(flags, "--force-build-metadata") + } + // add flag for logging verbosity flags = append(flags, fmt.Sprintf("--verbosity=%s", logrus.GetLevel())) From a16143fe001acc2b3e7a4faa6e253ab0f60cc55d Mon Sep 17 00:00:00 2001 From: ericdstein Date: Mon, 13 Dec 2021 00:49:32 -0600 Subject: [PATCH 2/3] add ForceBuildMetadata to Image struct in test --- cmd/vela-kaniko/image_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/vela-kaniko/image_test.go b/cmd/vela-kaniko/image_test.go index 983e972..a8b0f9e 100644 --- a/cmd/vela-kaniko/image_test.go +++ b/cmd/vela-kaniko/image_test.go @@ -9,10 +9,11 @@ import "testing" func TestDocker_Image_Validate(t *testing.T) { // setup types i := &Image{ - Args: []string{}, - Context: ".", - Dockerfile: "Dockerfile", - Target: "", + Args: []string{}, + Context: ".", + Dockerfile: "Dockerfile", + Target: "", + ForceBuildMetadata: false, } err := i.Validate() From 2ebc53258915839507c0024b2c47f4e674c5ad86 Mon Sep 17 00:00:00 2001 From: ericdstein Date: Thu, 10 Feb 2022 22:03:19 -0600 Subject: [PATCH 3/3] update DOCS.md for force_build_metadata parameter --- DOCS.md | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/DOCS.md b/DOCS.md index bd4b80a..2819e35 100644 --- a/DOCS.md +++ b/DOCS.md @@ -197,29 +197,30 @@ steps: The following parameters are used to configure the image: -| Name | Description | Required | Default | Environment Variables | -| --------------- | ------------------------------------------------------------------ | -------- | ----------------- | -------------------------------------------------------------- | -| `auto_tag` | enables automatic tagging of images (tag or sha, and `latest`) | `false` | `false` | `PARAMETER_AUTO_TAG`
`KANIKO_AUTO_TAG` | -| `build_args` | variables passed to image at build-time | `false` | `N/A` | `PARAMETER_BUILD_ARGS`
`KANIKO_BUILD_ARGS` | -| `cache` | enable caching of image layers | `false` | `false` | `PARAMETER_CACHE`
`KANIKO_CACHE` | -| `cache_repo` | specific repo to enable caching for | `false` | `N/A` | `PARAMETER_CACHE_REPO`
`KANIKO_CACHE_REPO` | -| `context` | path to context for building the image | `true` | `.` | `PARAMETER_CONTEXT`
`KANIKO_CONTEXT` | -| `dockerfile` | path to the file for building the image | `true` | `Dockerfile` | `PARAMETER_DOCKERFILE`
`KANIKO_DOCKERFILE` | -| `dry_run` | enable building the image without publishing | `false` | `false` | `PARAMETER_DRY_RUN`
`KANIKO_DRY_RUN` | -| `event` | event generated for build | `true` | **set by Vela** | `PARAMETER_EVENT`
`KANIKO_EVENT`
`VELA_BUILD_EVENT` | -| `labels` | unique labels to add to the image | `false` | `N/A` | `PARAMETER_LABELS`
`KANIKO_LABELS` | -| `log_level` | set the log level for the plugin | `true` | `info` | `PARAMETER_LOG_LEVEL`
`KANIKO_LOG_LEVEL` | -| `mirror` | name of the mirror registry to use | `false` | `N/A` | `PARAMETER_MIRROR`
`KANIKO_MIRROR` | -| `password` | password for communication with the registry | `true` | `N/A` | `PARAMETER_PASSWORD`
`KANIKO_PASSWORD`
`DOCKER_PASSWORD` | -| `push_retry` | number of retries for pushing an image to a remote destination | `false` | `0` | `PARAMETER_PUSH_RETRY`
`KANIKO_PUSH_RETRY` | -| `registry` | name of the registry for the repository | `true` | `index.docker.io` | `PARAMETER_REGISTRY`
`KANIKO_REGISTRY` | -| `repo` | name of the repository for the image | `true` | `N/A` | `PARAMETER_REPO`
`KANIKO_REPO` | -| `sha` | SHA-1 hash generated for commit | `true` | **set by Vela** | `PARAMETER_SHA`
`KANIKO_SHA`
`VELA_BUILD_COMMIT` | -| `snapshot_mode` | control how to snapshot the filesystem. - options (full|redo|time) | `false` | `N/A` | `PARAMETER_SNAPSHOT_MODE`
`KANIKO_SNAPSHOT_MODE` | -| `tag` | tag generated for build | `false` | **set by Vela** | `PARAMETER_TAG`
`KANIKO_TAG`
`VELA_BUILD_TAG` | -| `tags` | unique tags of the image | `true` | `latest` | `PARAMETER_TAGS`
`KANIKO_TAGS` | -| `target` | set the target build stage for the image | `false` | `N/A` | `PARAMETER_TARGET`
`KANIKO_TARGET` | -| `username` | user name for communication with the registry | `true` | `N/A` | `PARAMETER_USERNAME`
`KANIKO_USERNAME`
`DOCKER_USERNAME` | +| Name | Description | Required | Default | Environment Variables | +| ---------------------- | ------------------------------------------------------------------ | -------- | ----------------- | ----------------------------------------------------------------- | +| `auto_tag` | enables automatic tagging of images (tag or sha, and `latest`) | `false` | `false` | `PARAMETER_AUTO_TAG`
`KANIKO_AUTO_TAG` | +| `build_args` | variables passed to image at build-time | `false` | `N/A` | `PARAMETER_BUILD_ARGS`
`KANIKO_BUILD_ARGS` | +| `cache` | enable caching of image layers | `false` | `false` | `PARAMETER_CACHE`
`KANIKO_CACHE` | +| `cache_repo` | specific repo to enable caching for | `false` | `N/A` | `PARAMETER_CACHE_REPO`
`KANIKO_CACHE_REPO` | +| `context` | path to context for building the image | `true` | `.` | `PARAMETER_CONTEXT`
`KANIKO_CONTEXT` | +| `dockerfile` | path to the file for building the image | `true` | `Dockerfile` | `PARAMETER_DOCKERFILE`
`KANIKO_DOCKERFILE` | +| `dry_run` | enable building the image without publishing | `false` | `false` | `PARAMETER_DRY_RUN`
`KANIKO_DRY_RUN` | +| `event` | event generated for build | `true` | **set by Vela** | `PARAMETER_EVENT`
`KANIKO_EVENT`
`VELA_BUILD_EVENT` | +| `force_build_metadata` | enable force adding metadata layers to build image | `false` | `false` | `PARAMETER_FORCE_BUILD_METADATA`
`KANIKO_FORCE_BUILD_METADATA` | +| `labels` | unique labels to add to the image | `false` | `N/A` | `PARAMETER_LABELS`
`KANIKO_LABELS` | +| `log_level` | set the log level for the plugin | `true` | `info` | `PARAMETER_LOG_LEVEL`
`KANIKO_LOG_LEVEL` | +| `mirror` | name of the mirror registry to use | `false` | `N/A` | `PARAMETER_MIRROR`
`KANIKO_MIRROR` | +| `password` | password for communication with the registry | `true` | `N/A` | `PARAMETER_PASSWORD`
`KANIKO_PASSWORD`
`DOCKER_PASSWORD` | +| `push_retry` | number of retries for pushing an image to a remote destination | `false` | `0` | `PARAMETER_PUSH_RETRY`
`KANIKO_PUSH_RETRY` | +| `registry` | name of the registry for the repository | `true` | `index.docker.io` | `PARAMETER_REGISTRY`
`KANIKO_REGISTRY` | +| `repo` | name of the repository for the image | `true` | `N/A` | `PARAMETER_REPO`
`KANIKO_REPO` | +| `sha` | SHA-1 hash generated for commit | `true` | **set by Vela** | `PARAMETER_SHA`
`KANIKO_SHA`
`VELA_BUILD_COMMIT` | +| `snapshot_mode` | control how to snapshot the filesystem. - options (full|redo|time) | `false` | `N/A` | `PARAMETER_SNAPSHOT_MODE`
`KANIKO_SNAPSHOT_MODE` | +| `tag` | tag generated for build | `false` | **set by Vela** | `PARAMETER_TAG`
`KANIKO_TAG`
`VELA_BUILD_TAG` | +| `tags` | unique tags of the image | `true` | `latest` | `PARAMETER_TAGS`
`KANIKO_TAGS` | +| `target` | set the target build stage for the image | `false` | `N/A` | `PARAMETER_TARGET`
`KANIKO_TARGET` | +| `username` | user name for communication with the registry | `true` | `N/A` | `PARAMETER_USERNAME`
`KANIKO_USERNAME`
`DOCKER_USERNAME` | ## Template