|
@@ -28,7 +28,8 @@ type Project struct {
|
|
// Meta YML data
|
|
// Meta YML data
|
|
}
|
|
}
|
|
|
|
|
|
-func NewProject(name string) *Project {
|
|
|
|
|
|
+//NewProject Creates a project
|
|
|
|
+func NewProject() *Project {
|
|
return &Project{
|
|
return &Project{
|
|
tarFilename: "",
|
|
tarFilename: "",
|
|
isTemp: false,
|
|
isTemp: false,
|
|
@@ -37,6 +38,8 @@ func NewProject(name string) *Project {
|
|
conf: ProjectConf{},
|
|
conf: ProjectConf{},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//SetTarFile sets the source project tar
|
|
func (p *Project) SetTarFile(tarFile string, isTemp bool) *Project {
|
|
func (p *Project) SetTarFile(tarFile string, isTemp bool) *Project {
|
|
p.tarFilename = tarFile
|
|
p.tarFilename = tarFile
|
|
p.isTemp = isTemp
|
|
p.isTemp = isTemp
|
|
@@ -72,7 +75,7 @@ func (p *Project) Close() {
|
|
|
|
|
|
func (p *Project) Task(name string) error {
|
|
func (p *Project) Task(name string) error {
|
|
|
|
|
|
- log.Printf("Proj: %s Running task: %s", p.conf.Meta.Project, name)
|
|
|
|
|
|
+ log.Printf("Proj: %s Running task: %s", p.conf.Project, name)
|
|
|
|
|
|
taskconf, ok := p.conf.Tasks[name]
|
|
taskconf, ok := p.conf.Tasks[name]
|
|
if !ok {
|
|
if !ok {
|
|
@@ -99,7 +102,7 @@ func (p *Project) Task(name string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
- dockertag := p.conf.Meta.Project + "-" + taskconf.Use
|
|
|
|
|
|
+ dockerTag := p.conf.Project + "-" + taskconf.Use
|
|
{
|
|
{
|
|
// Check if container exists
|
|
// Check if container exists
|
|
|
|
|
|
@@ -111,12 +114,13 @@ func (p *Project) Task(name string) error {
|
|
}*/
|
|
}*/
|
|
// Execute inside container
|
|
// Execute inside container
|
|
|
|
|
|
- res, err := cli.ImageBuild(ctx, p.Reader(), types.ImageBuildOptions{Tags: []string{dockertag}, Dockerfile: imgconf.Dockerfile})
|
|
|
|
|
|
+ res, err := cli.ImageBuild(ctx, p.Reader(), types.ImageBuildOptions{Tags: []string{dockerTag}, Dockerfile: imgconf.Dockerfile})
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
+ // Just a reader and output
|
|
br := bufio.NewReader(res.Body)
|
|
br := bufio.NewReader(res.Body)
|
|
for {
|
|
for {
|
|
jdata, _, err := br.ReadLine()
|
|
jdata, _, err := br.ReadLine()
|
|
@@ -132,37 +136,27 @@ func (p *Project) Task(name string) error {
|
|
}
|
|
}
|
|
log.Println(msg)
|
|
log.Println(msg)
|
|
}
|
|
}
|
|
-
|
|
|
|
- /*out := prettylog.NewWriter("logger")
|
|
|
|
- _, err = io.Copy(out, res.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
// Just output
|
|
// Just output
|
|
-
|
|
|
|
}
|
|
}
|
|
{
|
|
{
|
|
log.Println("Testing running the builder")
|
|
log.Println("Testing running the builder")
|
|
- containerName := dockertag
|
|
|
|
- containerCfg := &container.Config{AttachStdout: true, Cmd: utils.ParseField(taskconf.Command)}
|
|
|
|
- containerRes, err := cli.ContainerCreate(ctx, containerCfg, nil, nil, containerName)
|
|
|
|
|
|
+ containerCfg := &container.Config{Image: dockerTag, AttachStdout: true, Cmd: utils.ParseField(taskconf.Command)}
|
|
|
|
+ containerRes, err := cli.ContainerCreate(ctx, containerCfg, nil, nil, dockerTag)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
-
|
|
|
|
// Remove container after finish
|
|
// Remove container after finish
|
|
- defer cli.ContainerRemove(ctx, containerRes.ID, types.ContainerRemoveOptions{})
|
|
|
|
- log.Println("Created container ID:", containerRes.ID, "with image: ", dockertag)
|
|
|
|
|
|
+ ////defer cli.ContainerRemove(ctx, containerRes.ID, types.ContainerRemoveOptions{})
|
|
|
|
|
|
- log.Println("Starting container")
|
|
|
|
|
|
+ log.Println("Created container ID:", containerRes.ID, "with image: ", dockerTag)
|
|
|
|
+ log.Println(" ============= Starting container")
|
|
err = cli.ContainerStart(ctx, containerRes.ID, types.ContainerStartOptions{})
|
|
err = cli.ContainerStart(ctx, containerRes.ID, types.ContainerStartOptions{})
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
log.Println("Commit container")
|
|
log.Println("Commit container")
|
|
-
|
|
|
|
|
|
+ log.Println("============= Commiting container")
|
|
_, err = cli.ContainerCommit(ctx, containerRes.ID, types.ContainerCommitOptions{Config: containerCfg})
|
|
_, err = cli.ContainerCommit(ctx, containerRes.ID, types.ContainerCommitOptions{Config: containerCfg})
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|