Skip to content

Commit

Permalink
fix: use kaniko to build image configuration parameters (#1558)
Browse files Browse the repository at this point in the history
Co-authored-by: 曲源成 <[email protected]>
  • Loading branch information
quyuancheng and 曲源成 authored Feb 17, 2023
1 parent 4668fb2 commit 2529478
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion builder/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type Response struct {
//Request build input
type Request struct {
KanikoImage string
InsecureBuild bool
KanikoArgs []string
RbdNamespace string
GRDataPVCName string
CachePVCName string
Expand Down
2 changes: 1 addition & 1 deletion builder/build/code_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *slugBuild) buildRunnerImage(slugPackage string) (string, error) {
return "", fmt.Errorf("pull image %s: %v", builder.RUNNERIMAGENAME, err)
}
logrus.Infof("pull image %s successfully.", builder.RUNNERIMAGENAME)
err := sources.ImageBuild(cacheDir, s.re.RbdNamespace, s.re.ServiceID, s.re.DeployVersion, s.re.Logger, "run-build", "", s.re.KanikoImage, s.re.InsecureBuild)
err := sources.ImageBuild(cacheDir, s.re.RbdNamespace, s.re.ServiceID, s.re.DeployVersion, s.re.Logger, "run-build", "", s.re.KanikoImage, s.re.KanikoArgs)
if err != nil {
s.re.Logger.Error(fmt.Sprintf("build image %s of new version failure", imageName), map[string]string{"step": "builder-exector", "status": "failure"})
logrus.Errorf("build image error: %s", err.Error())
Expand Down
5 changes: 4 additions & 1 deletion builder/build/dockerfile_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func (d *dockerfileBuild) runBuildJob(re *Request, buildImageName string) error
Image: re.KanikoImage,
Stdin: true,
StdinOnce: true,
Args: []string{fmt.Sprintf("--context=%v", re.SourceDir), fmt.Sprintf("--destination=%s", buildImageName), "--skip-tls-verify", fmt.Sprintf("--insecure-pull=%v", re.InsecureBuild), fmt.Sprintf("--insecure=%v", re.InsecureBuild)},
Args: []string{fmt.Sprintf("--context=%v", re.SourceDir), fmt.Sprintf("--destination=%s", buildImageName), "--skip-tls-verify"},
}
if len(re.KanikoArgs) > 0 {
container.Args = append(container.Args, re.KanikoArgs...)
}
container.VolumeMounts = mounts
podSpec.Containers = append(podSpec.Containers, container)
Expand Down
2 changes: 1 addition & 1 deletion builder/build/netcore_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (d *netcoreBuild) Build(re *Request) (*Response, error) {
return nil, fmt.Errorf("write default dockerfile error:%s", err.Error())
}
// build image
err := sources.ImageBuild(d.sourceDir, re.RbdNamespace, re.ServiceID, re.DeployVersion, re.Logger, "nc-build", "", re.KanikoImage, re.InsecureBuild)
err := sources.ImageBuild(d.sourceDir, re.RbdNamespace, re.ServiceID, re.DeployVersion, re.Logger, "nc-build", "", re.KanikoImage, re.KanikoArgs)
if err != nil {
re.Logger.Error(fmt.Sprintf("build image %s failure, find log in rbd-chaos", d.buildImageName), map[string]string{"step": "builder-exector", "status": "failure"})
logrus.Errorf("build image error: %s", err.Error())
Expand Down
4 changes: 2 additions & 2 deletions builder/exector/build_from_sourcecode_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type SourceCodeBuildItem struct {
TGZDir string `json:"tgz_dir"`
ImageClient sources.ImageClient
KanikoImage string
InsecureBuild bool
KanikoArgs []string
KubeClient kubernetes.Interface
RbdNamespace string
RbdRepoName string
Expand Down Expand Up @@ -304,7 +304,7 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
return nil, err
}
buildReq := &build.Request{
InsecureBuild: i.InsecureBuild,
KanikoArgs: i.KanikoArgs,
KanikoImage: i.KanikoImage,
RbdNamespace: i.RbdNamespace,
SourceDir: i.RepoInfo.GetCodeBuildAbsPath(),
Expand Down
6 changes: 3 additions & 3 deletions builder/exector/exector.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func NewManager(conf option.Config, mqc mqclient.MQClient) (Manager, error) {
logrus.Infof("The maximum number of concurrent build tasks supported by the current node is %d", maxConcurrentTask)
return &exectorManager{
KanikoImage: conf.KanikoImage,
InsecureBuild: conf.InsecureBuild,
KanikoArgs: conf.KanikoArgs,
KubeClient: kubeClient,
EtcdCli: etcdCli,
mqClient: mqc,
Expand All @@ -133,7 +133,7 @@ func NewManager(conf option.Config, mqc mqclient.MQClient) (Manager, error) {

type exectorManager struct {
KanikoImage string
InsecureBuild bool
KanikoArgs []string
KubeClient kubernetes.Interface
EtcdCli *clientv3.Client
tasks chan *pb.TaskMessage
Expand Down Expand Up @@ -336,7 +336,7 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) {
i := NewSouceCodeBuildItem(task.TaskBody)
i.ImageClient = e.imageClient
i.KanikoImage = e.KanikoImage
i.InsecureBuild = e.InsecureBuild
i.KanikoArgs = e.KanikoArgs
i.KubeClient = e.KubeClient
i.RbdNamespace = e.cfg.RbdNamespace
i.RbdRepoName = e.cfg.RbdRepoName
Expand Down
2 changes: 1 addition & 1 deletion builder/exector/plugin_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (e *exectorManager) runD(t *model.BuildPluginTaskBody, logger event.Logger)
n1 := strings.Split(mm[len(mm)-1], ".")[0]
buildImageName := fmt.Sprintf(builder.REGISTRYDOMAIN+"/plugin_%s_%s:%s", n1, t.PluginID, t.DeployVersion)
logger.Info("start build image", map[string]string{"step": "builder-exector"})
err := sources.ImageBuild(sourceDir, "rbd-system", t.PluginID, t.DeployVersion, logger, "plug-build", buildImageName, e.KanikoImage, e.InsecureBuild)
err := sources.ImageBuild(sourceDir, "rbd-system", t.PluginID, t.DeployVersion, logger, "plug-build", buildImageName, e.KanikoImage, e.KanikoArgs)
if err != nil {
logger.Error(fmt.Sprintf("build image %s failure,find log in rbd-chaos", buildImageName), map[string]string{"step": "builder-exector", "status": "failure"})
logrus.Errorf("[plugin]build image error: %s", err.Error())
Expand Down
7 changes: 5 additions & 2 deletions builder/sources/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
}

//ImageBuild use kaniko build image
func ImageBuild(contextDir, RbdNamespace, ServiceID, DeployVersion string, logger event.Logger, buildType, plugImageName, KanikoImage string, InsecureBuild bool) error {
func ImageBuild(contextDir, RbdNamespace, ServiceID, DeployVersion string, logger event.Logger, buildType, plugImageName, KanikoImage string, KanikoArgs []string) error {
// create image name
var buildImageName string
if buildType == "plug-build" {
Expand Down Expand Up @@ -430,7 +430,10 @@ func ImageBuild(contextDir, RbdNamespace, ServiceID, DeployVersion string, logge
Image: KanikoImage,
Stdin: true,
StdinOnce: true,
Args: []string{"--context=dir:///workspace", fmt.Sprintf("--destination=%s", buildImageName), "--skip-tls-verify", fmt.Sprintf("--insecure-pull=%v", InsecureBuild), fmt.Sprintf("--insecure=%v", InsecureBuild)},
Args: []string{"--context=dir:///workspace", fmt.Sprintf("--destination=%s", buildImageName), "--skip-tls-verify"},
}
if len(KanikoArgs) > 0 {
container.Args = append(container.Args, KanikoArgs...)
}
container.VolumeMounts = volumeMounts
podSpec.Containers = append(podSpec.Containers, container)
Expand Down
4 changes: 2 additions & 2 deletions cmd/builder/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Config struct {
ClusterName string
MysqlConnectionInfo string
KanikoImage string
InsecureBuild bool
KanikoArgs []string
DBType string
PrometheusMetricPath string
EventLogServers []string
Expand Down Expand Up @@ -106,7 +106,7 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.CachePath, "cache-path", "/cache", "volume cache mount path, when cache-mode using hostpath, default path is /cache")
fs.StringVar(&a.ContainerRuntime, "container-runtime", sources.ContainerRuntimeContainerd, "container runtime, support docker and containerd")
fs.StringVar(&a.RuntimeEndpoint, "runtime-endpoint", sources.RuntimeEndpointContainerd, "container runtime endpoint")
fs.BoolVar(&a.InsecureBuild, "insecure-build", false, "kaniko build image policy http or https, true is http")
fs.StringSliceVar(&a.KanikoArgs, "kaniko-args", []string{}, "kaniko build image container args config")
}

//SetLog 设置log
Expand Down

0 comments on commit 2529478

Please sign in to comment.