Kaniko
Integrates Kaniko into your builds.
Kaniko allows building Docker containers without needing root rights on the machine, allowing it to be used within other containers. Since CI jobs usually are already containerized, Kaniko is a much simpler way of building containers than using Docker in Docker.
Usage
This examples:
Builds an image
"app"
from the Dockerfile in folderdocker
, with a temporary version,Publishes it to the GitLab registry,
Runs tests on it,
If we're in the main branch and the tests are successful, retags the image as
"latest"
.
gitLabCi {
val build by stage()
val test by stage()
val deploy by stage()
val imageName = "${Variable.Registry.image}/app"
val buildApp by kanikoBuild(
imageName = imageName,
context = "docker",
stage = build,
)
val testApp by job(stage = test) {
image(imageName, version = Docker.defaultVersion)
script {
// …
}
}
if (Value.isDefaultBranch) {
val publishApp by kanikoRename(
imageName = imageName,
stage = deploy,
)
}
}
Extensions
Pipeline extensions:
kanikoBuild: Builds an image and pushes it to a registry.
kanikoRename: Renames an image to pushes it to a registry.
Functions
Builds an image called imageName of version imageVersion based on the context directory and the specified dockerfile.
Logs into the GitLab container registry for Kaniko.