Change pipeline executor to build container in repo at .cursorius/Dockerfile
This commit is contained in:
@@ -5,10 +5,13 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jhoonb/archivex"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
@@ -34,6 +37,7 @@ type PipelineExecution struct {
|
||||
|
||||
func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf config.PipelineConf) {
|
||||
jobFolder := filepath.Join(pipelineConf.WorkingDir, pe.Pipeline.Id.String(), pe.Run.Id.String())
|
||||
cloneFolder := filepath.Join(jobFolder, "repo")
|
||||
|
||||
log.Debugf("Job %v configured with URL \"%v\"", pe.Pipeline.Name, pe.Pipeline.Url)
|
||||
|
||||
@@ -45,7 +49,7 @@ func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf co
|
||||
return
|
||||
}
|
||||
|
||||
err = os.MkdirAll(jobFolder, 0755)
|
||||
err = os.MkdirAll(cloneFolder, 0755)
|
||||
if err != nil {
|
||||
log.Errorf("could not create working directory for job %v: %w", pe.Pipeline.Name, err)
|
||||
return
|
||||
@@ -84,7 +88,7 @@ func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf co
|
||||
auth = nil
|
||||
}
|
||||
|
||||
_, err = git.PlainClone(jobFolder, false, &git.CloneOptions{
|
||||
_, err = git.PlainClone(cloneFolder, false, &git.CloneOptions{
|
||||
URL: pe.Pipeline.Url,
|
||||
Auth: auth,
|
||||
})
|
||||
@@ -102,6 +106,49 @@ func ExecutePipeline(pe PipelineExecution, db database.Database, pipelineConf co
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
log.Info("Building container")
|
||||
|
||||
tarFile := filepath.Join(jobFolder, "archive.tar")
|
||||
tar := new(archivex.TarFile)
|
||||
err = tar.Create(tarFile)
|
||||
if err != nil {
|
||||
log.Errorf("could not create tarfile: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = tar.AddAll(cloneFolder, false)
|
||||
if err != nil {
|
||||
log.Errorf("could not add repo to tarfile: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = tar.Close()
|
||||
if err != nil {
|
||||
log.Errorf("could not close tarfile: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
dockerBuildContext, err := os.Open(tarFile)
|
||||
defer dockerBuildContext.Close()
|
||||
|
||||
buildResponse, err := cli.ImageBuild(context.Background(), dockerBuildContext, types.ImageBuildOptions{
|
||||
Dockerfile: ".cursorius/Dockerfile",
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("could not build container: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("********* %s **********", buildResponse.OSType)
|
||||
response, err := ioutil.ReadAll(buildResponse.Body)
|
||||
if err != nil {
|
||||
log.Errorf("could no read build response: %w", err)
|
||||
return
|
||||
}
|
||||
log.Debugf("build log: %v", string(response))
|
||||
|
||||
return
|
||||
|
||||
imageName := "git.ohea.xyz/cursorius/pipeline-api/cursorius-pipeline:v2"
|
||||
|
||||
log.Infof("Pulling image %v", imageName)
|
||||
|
||||
Reference in New Issue
Block a user