|
|
@ -1,6 +1,8 @@
|
|
|
|
package manifest
|
|
|
|
package manifest
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/docker/buildx/util/platformutil"
|
|
|
|
"github.com/docker/buildx/util/platformutil"
|
|
|
@ -25,9 +27,8 @@ type DeploymentOpt struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BuildkitFlags []string
|
|
|
|
BuildkitFlags []string
|
|
|
|
// BuildkitConfig
|
|
|
|
// files mounted at /etc/buildkitd
|
|
|
|
// when not empty, will create configmap with buildkit.toml and mounted
|
|
|
|
ConfigFiles map[string][]byte
|
|
|
|
BuildkitConfig []byte
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rootless bool
|
|
|
|
Rootless bool
|
|
|
|
NodeSelector map[string]string
|
|
|
|
NodeSelector map[string]string
|
|
|
@ -43,7 +44,7 @@ const (
|
|
|
|
AnnotationPlatform = "buildx.docker.com/platform"
|
|
|
|
AnnotationPlatform = "buildx.docker.com/platform"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c *corev1.ConfigMap, err error) {
|
|
|
|
func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c []*corev1.ConfigMap, err error) {
|
|
|
|
labels := map[string]string{
|
|
|
|
labels := map[string]string{
|
|
|
|
"app": opt.Name,
|
|
|
|
"app": opt.Name,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,26 +104,23 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c *corev1.ConfigMa
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cfg := range splitConfigFiles(opt.ConfigFiles) {
|
|
|
|
if len(opt.BuildkitConfig) > 0 {
|
|
|
|
cc := &corev1.ConfigMap{
|
|
|
|
c = &corev1.ConfigMap{
|
|
|
|
|
|
|
|
TypeMeta: metav1.TypeMeta{
|
|
|
|
TypeMeta: metav1.TypeMeta{
|
|
|
|
APIVersion: corev1.SchemeGroupVersion.String(),
|
|
|
|
APIVersion: corev1.SchemeGroupVersion.String(),
|
|
|
|
Kind: "ConfigMap",
|
|
|
|
Kind: "ConfigMap",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Namespace: opt.Namespace,
|
|
|
|
Namespace: opt.Namespace,
|
|
|
|
Name: opt.Name + "-config",
|
|
|
|
Name: opt.Name + "-" + cfg.name,
|
|
|
|
Annotations: annotations,
|
|
|
|
Annotations: annotations,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Data: map[string]string{
|
|
|
|
Data: cfg.files,
|
|
|
|
"buildkitd.toml": string(opt.BuildkitConfig),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
d.Spec.Template.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{{
|
|
|
|
d.Spec.Template.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{{
|
|
|
|
Name: "config",
|
|
|
|
Name: cfg.name,
|
|
|
|
MountPath: "/etc/buildkit",
|
|
|
|
MountPath: path.Join("/etc/buildkit", cfg.path),
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
|
|
d.Spec.Template.Spec.Volumes = []corev1.Volume{{
|
|
|
|
d.Spec.Template.Spec.Volumes = []corev1.Volume{{
|
|
|
@ -130,11 +128,12 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c *corev1.ConfigMa
|
|
|
|
VolumeSource: corev1.VolumeSource{
|
|
|
|
VolumeSource: corev1.VolumeSource{
|
|
|
|
ConfigMap: &corev1.ConfigMapVolumeSource{
|
|
|
|
ConfigMap: &corev1.ConfigMapVolumeSource{
|
|
|
|
LocalObjectReference: corev1.LocalObjectReference{
|
|
|
|
LocalObjectReference: corev1.LocalObjectReference{
|
|
|
|
Name: c.Name,
|
|
|
|
Name: cc.Name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
|
|
|
|
c = append(c, cc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if opt.Qemu.Install {
|
|
|
|
if opt.Qemu.Install {
|
|
|
@ -208,3 +207,35 @@ func toRootless(d *appsv1.Deployment) error {
|
|
|
|
d.Spec.Template.ObjectMeta.Annotations["container.seccomp.security.alpha.kubernetes.io/"+containerName] = "unconfined"
|
|
|
|
d.Spec.Template.ObjectMeta.Annotations["container.seccomp.security.alpha.kubernetes.io/"+containerName] = "unconfined"
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type config struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
path string
|
|
|
|
|
|
|
|
files map[string]string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func splitConfigFiles(m map[string][]byte) []config {
|
|
|
|
|
|
|
|
var c []config
|
|
|
|
|
|
|
|
idx := map[string]int{}
|
|
|
|
|
|
|
|
nameIdx := 0
|
|
|
|
|
|
|
|
for k, v := range m {
|
|
|
|
|
|
|
|
dir := path.Dir(k)
|
|
|
|
|
|
|
|
i, ok := idx[dir]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
idx[dir] = len(c)
|
|
|
|
|
|
|
|
i = len(c)
|
|
|
|
|
|
|
|
name := "config"
|
|
|
|
|
|
|
|
if dir != "." {
|
|
|
|
|
|
|
|
nameIdx++
|
|
|
|
|
|
|
|
name = fmt.Sprintf("%s-%d", name, nameIdx)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c = append(c, config{
|
|
|
|
|
|
|
|
path: dir,
|
|
|
|
|
|
|
|
name: name,
|
|
|
|
|
|
|
|
files: map[string]string{},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c[i].files[path.Base(k)] = string(v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
}
|
|
|
|