Update executor to run built user provided container

This commit is contained in:
2023-02-24 22:37:17 -07:00
parent 708fbca91a
commit 4069e1b0e1
+6 -20
View File
@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@@ -131,8 +130,10 @@ func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf co
dockerBuildContext, err := os.Open(tarFile) dockerBuildContext, err := os.Open(tarFile)
defer dockerBuildContext.Close() defer dockerBuildContext.Close()
imageName := fmt.Sprintf("%v-%v:latest", pe.Pipeline.Id.String(), pe.Run.Id.String())
buildResponse, err := cli.ImageBuild(context.Background(), dockerBuildContext, types.ImageBuildOptions{ buildResponse, err := cli.ImageBuild(context.Background(), dockerBuildContext, types.ImageBuildOptions{
Tags: []string{fmt.Sprintf("%v-%v:latest", pe.Pipeline.Id.String(), pe.Run.Id.String())}, Tags: []string{imageName},
Dockerfile: ".cursorius/Dockerfile", Dockerfile: ".cursorius/Dockerfile",
}) })
if err != nil { if err != nil {
@@ -147,28 +148,13 @@ func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf co
} }
log.Debugf("build log: %v", string(response)) log.Debugf("build log: %v", string(response))
imageName := "git.ohea.xyz/cursorius/pipeline-api/cursorius-pipeline:v2" err = buildResponse.Body.Close()
log.Infof("Pulling image %v", imageName)
pullOutput, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
if err != nil { if err != nil {
log.Errorf("could not pull image %v: %w", imageName, err) log.Errorf("Could not close build response body: %w", err)
return return
} }
buf, err := io.ReadAll(pullOutput) log.Info("Image built sucessfully sucessfully")
if err != nil {
log.Errorf("could not read from io.ReadCloser:, %w", err)
return
}
log.Infof("%s", buf)
err = pullOutput.Close()
if err != nil {
log.Errorf("could not close io.ReadCloser: %w", err)
return
}
log.Info("Image pulled sucessfully")
hostConfig := container.HostConfig{} hostConfig := container.HostConfig{}