in pkg/controller/build/build_pod.go [310:424]
func addBuildahTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, task *v1.BuildahTask, pod *corev1.Pod) error {
var bud []string
bud = []string{
"buildah",
"bud",
"--storage-driver=vfs",
}
if task.Platform != "" {
bud = append(bud, []string{
"--platform",
task.Platform,
}...)
}
bud = append(bud, []string{
"--pull-always",
"-f",
"Dockerfile",
"-t",
task.Image,
".",
}...)
push := []string{
"buildah",
"push",
"--storage-driver=vfs",
"--digestfile=/dev/termination-log",
task.Image,
"docker://" + task.Image,
}
if task.Verbose != nil && *task.Verbose {
bud = append(bud[:2], append([]string{"--log-level=debug"}, bud[2:]...)...)
push = append(push[:2], append([]string{"--log-level=debug"}, push[2:]...)...)
}
env := make([]corev1.EnvVar, 0)
volumes := make([]corev1.Volume, 0)
volumeMounts := make([]corev1.VolumeMount, 0)
if task.Registry.CA != "" {
config, err := getRegistryConfigMap(ctx, c, build.Namespace, task.Registry.CA, buildahRegistryConfigMaps)
if err != nil {
return err
}
addRegistryConfigMap(task.Registry.CA, config, &volumes, &volumeMounts)
// This is easier to use the --cert-dir option, otherwise Buildah defaults to looking up certificates
// into a directory named after the registry address
bud = append(bud[:2], append([]string{"--cert-dir=/etc/containers/certs.d"}, bud[2:]...)...)
push = append(push[:2], append([]string{"--cert-dir=/etc/containers/certs.d"}, push[2:]...)...)
}
var auth string
if task.Registry.Secret != "" {
secret, err := getRegistrySecret(ctx, c, build.Namespace, task.Registry.Secret, buildahRegistrySecrets)
if err != nil {
return err
}
if secret == plainDockerBuildahRegistrySecret {
// Handle old format and make it compatible with Buildah
auth = "(echo '{ \"auths\": ' ; cat /buildah/.docker/config.json ; echo \"}\") > /tmp/.dockercfg"
env = append(env, corev1.EnvVar{
Name: "REGISTRY_AUTH_FILE",
Value: "/tmp/.dockercfg",
})
}
addRegistrySecret(task.Registry.Secret, secret, &volumes, &volumeMounts, &env)
}
if task.Registry.Insecure {
bud = append(bud[:2], append([]string{"--tls-verify=false"}, bud[2:]...)...)
push = append(push[:2], append([]string{"--tls-verify=false"}, push[2:]...)...)
}
env = append(env, proxyFromEnvironment()...)
args := []string{
strings.Join(bud, " "),
strings.Join(push, " "),
}
if auth != "" {
args = append([]string{auth}, args...)
}
image := task.ExecutorImage
if image == "" {
image = fmt.Sprintf("%s:v%s", builder.BuildahDefaultImageName, defaults.BuildahVersion)
}
var root int64 = 0
container := corev1.Container{
Name: task.Name,
Image: image,
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{"/bin/sh", "-c"},
Args: []string{strings.Join(args, " && ")},
Env: env,
WorkingDir: filepath.Join(builderDir, build.Name, builder.ContextDir),
VolumeMounts: volumeMounts,
// Buildah requires root privileges
SecurityContext: &corev1.SecurityContext{
RunAsUser: &root,
RunAsGroup: &root,
},
}
pod.Spec.Volumes = append(pod.Spec.Volumes, volumes...)
addContainerToPod(build, container, pod)
return nil
}