Finish jobrunner impl

This commit is contained in:
2022-10-23 19:57:30 -06:00
parent a8e2d70b6b
commit 451797400d
+41 -9
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
@@ -52,25 +53,56 @@ func RunJob(job Job, workingDir string) error {
if err != nil {
return fmt.Errorf("Could not create docker client: %v", err)
}
log.Info("Source cloned successfully")
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,
&container.Config{
Image: "cursorius:latest",
Image: imageName,
Cmd: []string{"/launcher.sh"},
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)
&container.HostConfig{
Mounts: []mount.Mount{{
Type: mount.TypeVolume,
Source: jobFolder,
Target: "/job",
ReadOnly: false,
Consistency: mount.ConsistencyDefault,
}},
Mounts: []mount.Mount{
{
Type: mount.TypeBind,
Source: jobFolder,
Target: "/cursorius/src",
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, "",
)