Finish jobrunner impl
This commit is contained in:
+41
-9
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -52,25 +53,56 @@ func RunJob(job Job, workingDir string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not create docker client: %v", err)
|
return fmt.Errorf("Could not create docker client: %v", err)
|
||||||
}
|
}
|
||||||
|
log.Info("Source cloned successfully")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
imageName := "git.ohea.xyz/cursorius/cursorius:latest"
|
||||||
|
|
||||||
|
log.Infof("Pulling image %v", imageName)
|
||||||
|
pullOutput, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not pull image %v: %v", imageName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
buf, err := io.ReadAll(pullOutput)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read from io.ReadCloser:, %v", err)
|
||||||
|
}
|
||||||
|
log.Infof("%s", buf)
|
||||||
|
|
||||||
|
err = pullOutput.Close()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not close io.ReadCloser: %v", err)
|
||||||
|
}
|
||||||
|
log.Info("Image pulled sucessfully")
|
||||||
|
|
||||||
resp, err := cli.ContainerCreate(ctx,
|
resp, err := cli.ContainerCreate(ctx,
|
||||||
&container.Config{
|
&container.Config{
|
||||||
Image: "cursorius:latest",
|
Image: imageName,
|
||||||
Cmd: []string{"/launcher.sh"},
|
Cmd: []string{"/launcher.sh"},
|
||||||
Tty: false,
|
Tty: false,
|
||||||
Env: []string{fmt.Sprintf("CURSORIUS_SRC_DIR=/job")},
|
//Env: []string{fmt.Sprintf("CURSORIUS_SRC_DIR=%s", jobFolder)},
|
||||||
|
Env: []string{fmt.Sprintf("CURSORIUS_SRC_DIR=/cursorius/src")},
|
||||||
},
|
},
|
||||||
// TODO: fix running the runner in docker (add VolumesFrom to HostConfig)
|
// TODO: fix running the runner in docker (add VolumesFrom to HostConfig)
|
||||||
&container.HostConfig{
|
&container.HostConfig{
|
||||||
Mounts: []mount.Mount{{
|
Mounts: []mount.Mount{
|
||||||
Type: mount.TypeVolume,
|
{
|
||||||
Source: jobFolder,
|
Type: mount.TypeBind,
|
||||||
Target: "/job",
|
Source: jobFolder,
|
||||||
ReadOnly: false,
|
Target: "/cursorius/src",
|
||||||
Consistency: mount.ConsistencyDefault,
|
ReadOnly: false,
|
||||||
}},
|
Consistency: mount.ConsistencyDefault,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: mount.TypeBind,
|
||||||
|
Source: "/var/run/docker.sock",
|
||||||
|
Target: "/var/run/docker.sock",
|
||||||
|
ReadOnly: false,
|
||||||
|
Consistency: mount.ConsistencyDefault,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
nil, nil, "",
|
nil, nil, "",
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user