Skip to content

Commit

Permalink
Local gpu (k3d) (#240)
Browse files Browse the repository at this point in the history
* Adding k3s and k3d as drivers

* k3d fixes

* bugfixes

* wip
  • Loading branch information
plparent authored Oct 31, 2024
1 parent 96bcd65 commit b8fb6df
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,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()
log.Println(pullImage.Status().Stdout)
log.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)
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ 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 {
data := strings.Fields(line)
if "docker.io/zetaforge/"+image == data[0] + ":" + data[1] {
return true, false, nil
}
}
return false, false, nil
} else {
apiClient, err := client.NewClientWithOpts(
client.WithAPIVersionNegotiation(),
)
Expand Down

0 comments on commit b8fb6df

Please sign in to comment.