From 35650d46a7b17ed838666302e26e8a573b474384 Mon Sep 17 00:00:00 2001 From: plparent Date: Fri, 25 Oct 2024 13:20:23 -0400 Subject: [PATCH 1/4] Adding k3s and k3d as drivers --- executor.go | 9 +++++++++ setup.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index bffcc714..6841da86 100644 --- a/executor.go +++ b/executor.go @@ -624,6 +624,15 @@ func buildImage(ctx context.Context, source string, tag string, logger *log.Logg logger.Printf("Docker build error: %v", errorDetail["message"]) } } + if cfg.Local.Driver == "k3s" { + pullImage := cmd.NewCmd("docker", "save", tag, "|", "k3s", "ctr", "images", "import", "-") + <-pullImage.Start() + log.Printf(pullImage.Status().Stdout) + else if cfg.Local.Driver == "k3d" { + pullImage := cmd.NewCmd("k3d", "image", "import", tag) + <-pullImage.Start() + log.Printf(pullImage.Status().Stdout) + } } return nil diff --git a/setup.go b/setup.go index 6f1d73e7..269840dc 100644 --- a/setup.go +++ b/setup.go @@ -308,7 +308,7 @@ func setup(ctx context.Context, config Config, db *sql.DB) { signals := make(chan os.Signal, 1) signal.Notify(signals, os.Interrupt) - if config.Local.Driver == "minikube" { + if config.Local.Driver == "minikube" || config.Local.Driver == "k3d" { stopBucketCh := make(chan struct{}, 1) go func() { for { From bb10ff99cc5face8e1042960edab5cd685d1adbe Mon Sep 17 00:00:00 2001 From: plparent Date: Wed, 30 Oct 2024 11:24:38 -0400 Subject: [PATCH 2/4] k3d fixes --- executor.go | 9 +++------ main.go | 2 ++ translator.go | 11 ++++++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/executor.go b/executor.go index 6841da86..8a82f63b 100644 --- a/executor.go +++ b/executor.go @@ -624,14 +624,11 @@ func buildImage(ctx context.Context, source string, tag string, logger *log.Logg logger.Printf("Docker build error: %v", errorDetail["message"]) } } - if cfg.Local.Driver == "k3s" { - pullImage := cmd.NewCmd("docker", "save", tag, "|", "k3s", "ctr", "images", "import", "-") - <-pullImage.Start() - log.Printf(pullImage.Status().Stdout) - else if cfg.Local.Driver == "k3d" { + + if cfg.Local.Driver == "k3d" { pullImage := cmd.NewCmd("k3d", "image", "import", tag) <-pullImage.Start() - log.Printf(pullImage.Status().Stdout) + logger.Println(pullImage.Status().Stdout) } } diff --git a/main.go b/main.go index 0226a222..d6ad25d4 100644 --- a/main.go +++ b/main.go @@ -52,9 +52,11 @@ type Config struct { Cloud Cloud `json:"Cloud,omitempty"` } + type Local struct { BucketPort int Driver string + K3DCluster string `json:"K3DCluster,omitempty"` } type Cloud struct { diff --git a/translator.go b/translator.go index feac5f99..49f29545 100644 --- a/translator.go +++ b/translator.go @@ -52,7 +52,16 @@ func checkImage(ctx context.Context, image string, cfg Config) (bool, bool, erro } } return false, false, nil - } else { + } else if cfg.Local.Driver == "k3d" { + dockerImage := cmd.NewCmd("docker", "exec", "k3d-" + cfg.Local.K3DCluster + "-server-0", "crictl", "images") + <-dockerImage.Start() + for _, line := range dockerImage.Status().Stdout { + if "docker.io/zetaforge/"+image == line { + return true, false, nil + } + } + return false, false, nil + } else { apiClient, err := client.NewClientWithOpts( client.WithAPIVersionNegotiation(), ) From 159b60d88c930f314135da7d38585c6cef796267 Mon Sep 17 00:00:00 2001 From: plparent Date: Thu, 31 Oct 2024 11:50:56 -0400 Subject: [PATCH 3/4] bugfixes --- executor.go | 19 +++++++++++++------ translator.go | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/executor.go b/executor.go index 8a82f63b..c6554320 100644 --- a/executor.go +++ b/executor.go @@ -624,12 +624,6 @@ func buildImage(ctx context.Context, source string, tag string, logger *log.Logg logger.Printf("Docker build error: %v", errorDetail["message"]) } } - - if cfg.Local.Driver == "k3d" { - pullImage := cmd.NewCmd("k3d", "image", "import", tag) - <-pullImage.Start() - logger.Println(pullImage.Status().Stdout) - } } return nil @@ -711,6 +705,19 @@ func localExecute(pipeline *zjson.Pipeline, pipelineMerkleTree *zjson.PipelineMe } } + if cfg.Local.Driver == "k3d" { + imageImport := []string{"image", "import"} + for _, image := range blocks { + imageImport = append(imageImport, image) + } + imageImport = append(imageImport, "-c") + imageImport = append(imageImport, cfg.Local.K3DCluster) + pullImage := cmd.NewCmd("k3d", imageImport...) + <-pullImage.Start() + logger.Println(pullImage.Status().Stdout) + logger.Println(pullImage.Status().Stderr) + } + if err := eg.Wait(); err != nil { pipelineLogger.Printf("error during pipeline build execution; err=%v", err) log.Printf("error during pipeline build execution; err=%v", err) diff --git a/translator.go b/translator.go index 49f29545..bb14d3d5 100644 --- a/translator.go +++ b/translator.go @@ -56,7 +56,8 @@ func checkImage(ctx context.Context, image string, cfg Config) (bool, bool, erro dockerImage := cmd.NewCmd("docker", "exec", "k3d-" + cfg.Local.K3DCluster + "-server-0", "crictl", "images") <-dockerImage.Start() for _, line := range dockerImage.Status().Stdout { - if "docker.io/zetaforge/"+image == line { + data := strings.Fields(line) + if "docker.io/zetaforge/"+image == data[0] + ":" + data[1] { return true, false, nil } } From 07c386c03083f792d931edef7f3acc7f1382f527 Mon Sep 17 00:00:00 2001 From: plparent Date: Thu, 31 Oct 2024 11:54:44 -0400 Subject: [PATCH 4/4] wip --- executor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index c6554320..dbf11315 100644 --- a/executor.go +++ b/executor.go @@ -714,8 +714,8 @@ func localExecute(pipeline *zjson.Pipeline, pipelineMerkleTree *zjson.PipelineMe imageImport = append(imageImport, cfg.Local.K3DCluster) pullImage := cmd.NewCmd("k3d", imageImport...) <-pullImage.Start() - logger.Println(pullImage.Status().Stdout) - logger.Println(pullImage.Status().Stderr) + log.Println(pullImage.Status().Stdout) + log.Println(pullImage.Status().Stderr) } if err := eg.Wait(); err != nil {