|
@@ -2,6 +2,7 @@ package buildme
|
|
|
|
|
|
import (
|
|
import (
|
|
"bufio"
|
|
"bufio"
|
|
|
|
+ "buildme/utils"
|
|
"context"
|
|
"context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -16,12 +17,12 @@ import (
|
|
|
|
|
|
// Project type
|
|
// Project type
|
|
type Project struct {
|
|
type Project struct {
|
|
- tarFile string
|
|
|
|
- isTemp bool
|
|
|
|
|
|
+ tarFilename string
|
|
|
|
+ isTemp bool
|
|
//utils.Filer
|
|
//utils.Filer
|
|
//io.ReadCloser // Tar format? tar reader perhaps
|
|
//io.ReadCloser // Tar format? tar reader perhaps
|
|
- Name string
|
|
|
|
- Dockerfile string
|
|
|
|
|
|
+ //Name string
|
|
|
|
+ //Dockerfile string
|
|
|
|
|
|
conf ProjectConf
|
|
conf ProjectConf
|
|
// Meta YML data
|
|
// Meta YML data
|
|
@@ -29,26 +30,27 @@ type Project struct {
|
|
|
|
|
|
func NewProject(name string) *Project {
|
|
func NewProject(name string) *Project {
|
|
return &Project{
|
|
return &Project{
|
|
- tarFile: "",
|
|
|
|
- isTemp: false,
|
|
|
|
- Name: name,
|
|
|
|
- Dockerfile: "docker/Dockerfile.build",
|
|
|
|
- conf: ProjectConf{},
|
|
|
|
|
|
+ tarFilename: "",
|
|
|
|
+ isTemp: false,
|
|
|
|
+ // Name: name,
|
|
|
|
+ //Dockerfile: "docker/Dockerfile.build",
|
|
|
|
+ conf: ProjectConf{},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func (p *Project) SetTarFile(tarFile string, isTemp bool) *Project {
|
|
func (p *Project) SetTarFile(tarFile string, isTemp bool) *Project {
|
|
- p.tarFile = tarFile
|
|
|
|
|
|
+ p.tarFilename = tarFile
|
|
p.isTemp = isTemp
|
|
p.isTemp = isTemp
|
|
return p
|
|
return p
|
|
}
|
|
}
|
|
-func (p *Project) SetName(name string) *Project {
|
|
|
|
|
|
+
|
|
|
|
+/*func (p *Project) SetName(name string) *Project {
|
|
p.Name = name
|
|
p.Name = name
|
|
return p
|
|
return p
|
|
}
|
|
}
|
|
func (p *Project) SetDockerfile(dockerfile string) *Project {
|
|
func (p *Project) SetDockerfile(dockerfile string) *Project {
|
|
p.Dockerfile = dockerfile
|
|
p.Dockerfile = dockerfile
|
|
return p
|
|
return p
|
|
-}
|
|
|
|
|
|
+}*/
|
|
|
|
|
|
func (p *Project) SetConf(projConf ProjectConf) *Project {
|
|
func (p *Project) SetConf(projConf ProjectConf) *Project {
|
|
p.conf = projConf
|
|
p.conf = projConf
|
|
@@ -56,21 +58,21 @@ func (p *Project) SetConf(projConf ProjectConf) *Project {
|
|
}
|
|
}
|
|
|
|
|
|
func (p *Project) Reader() io.ReadCloser {
|
|
func (p *Project) Reader() io.ReadCloser {
|
|
- f, _ := os.Open(p.tarFile)
|
|
|
|
|
|
+ f, _ := os.Open(p.tarFilename)
|
|
return f
|
|
return f
|
|
}
|
|
}
|
|
|
|
|
|
func (p *Project) Close() {
|
|
func (p *Project) Close() {
|
|
if p.isTemp {
|
|
if p.isTemp {
|
|
log.Println("Closing temporary file")
|
|
log.Println("Closing temporary file")
|
|
- os.Remove(p.tarFile)
|
|
|
|
|
|
+ os.Remove(p.tarFilename)
|
|
}
|
|
}
|
|
//os.Remove(tarFile) // Should remove??
|
|
//os.Remove(tarFile) // Should remove??
|
|
}
|
|
}
|
|
|
|
|
|
func (p *Project) Task(name string) error {
|
|
func (p *Project) Task(name string) error {
|
|
|
|
|
|
- log.Printf("Proj: %s Running task: %s", p.Name, name)
|
|
|
|
|
|
+ log.Printf("Proj: %s Running task: %s", p.conf.Meta.Project, name)
|
|
|
|
|
|
taskconf, ok := p.conf.Tasks[name]
|
|
taskconf, ok := p.conf.Tasks[name]
|
|
if !ok {
|
|
if !ok {
|
|
@@ -88,7 +90,7 @@ func (p *Project) Task(name string) error {
|
|
// Task kind docker
|
|
// Task kind docker
|
|
// Stupid docker cli
|
|
// Stupid docker cli
|
|
dockerhost := os.Getenv("DOCKER_HOST")
|
|
dockerhost := os.Getenv("DOCKER_HOST")
|
|
- if !strings.Contains(dockerhost, "://") {
|
|
|
|
|
|
+ if dockerhost != "" && !strings.Contains(dockerhost, "://") {
|
|
os.Setenv("DOCKER_HOST", "http://"+dockerhost)
|
|
os.Setenv("DOCKER_HOST", "http://"+dockerhost)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -97,7 +99,7 @@ func (p *Project) Task(name string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
- dockertag := p.Name + "-" + name
|
|
|
|
|
|
+ dockertag := p.conf.Meta.Project + "-" + taskconf.Use
|
|
{
|
|
{
|
|
// Check if container exists
|
|
// Check if container exists
|
|
|
|
|
|
@@ -143,15 +145,31 @@ func (p *Project) Task(name string) error {
|
|
{
|
|
{
|
|
log.Println("Testing running the builder")
|
|
log.Println("Testing running the builder")
|
|
containerName := dockertag
|
|
containerName := dockertag
|
|
- containerCfg := &container.Config{AttachStdout: true, Cmd: []string{taskconf.Command}}
|
|
|
|
- res, err := cli.ContainerCreate(ctx, containerCfg, nil, nil, containerName)
|
|
|
|
|
|
+ containerCfg := &container.Config{AttachStdout: true, Cmd: utils.ParseField(taskconf.Command)}
|
|
|
|
+ containerRes, err := cli.ContainerCreate(ctx, containerCfg, nil, nil, containerName)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Remove container after finish
|
|
|
|
+ defer cli.ContainerRemove(ctx, containerRes.ID, types.ContainerRemoveOptions{})
|
|
|
|
+ log.Println("Created container ID:", containerRes.ID, "with image: ", dockertag)
|
|
|
|
+
|
|
|
|
+ log.Println("Starting container")
|
|
|
|
+ err = cli.ContainerStart(ctx, containerRes.ID, types.ContainerStartOptions{})
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.Println("Commit container")
|
|
|
|
+
|
|
|
|
+ _, err = cli.ContainerCommit(ctx, containerRes.ID, types.ContainerCommitOptions{Config: containerCfg})
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- log.Println("Created container ID:", res)
|
|
|
|
- log.Println("Starting container test")
|
|
|
|
|
|
|
|
- cr, _, err := cli.CopyFromContainer(ctx, res.ID, "/buildme/dist.tar.gz")
|
|
|
|
|
|
+ // Artifact??
|
|
|
|
+ /*cr, _, err := cli.CopyFromContainer(ctx, res.ID, "/buildme/dist.tar.gz")
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println("Copy error", err)
|
|
log.Println("Copy error", err)
|
|
return err
|
|
return err
|
|
@@ -167,7 +185,7 @@ func (p *Project) Task(name string) error {
|
|
defer f.Close()
|
|
defer f.Close()
|
|
|
|
|
|
io.Copy(f, cr)
|
|
io.Copy(f, cr)
|
|
- f.Sync()
|
|
|
|
|
|
+ f.Sync()*/
|
|
}
|
|
}
|
|
|
|
|
|
return nil
|
|
return nil
|