Luis Figueiredo 8 vuotta sitten
vanhempi
commit
f9ac150f4a

+ 1 - 1
Makefile

@@ -22,4 +22,4 @@ distclean: clean
 	rm -rf pkg
 
 
-.PHONY: all clean distclean
+.PHONY: all deps clean distclean

+ 2 - 3
buildme.yml

@@ -1,6 +1,5 @@
-meta:
-  project: buildme
-  default: build
+project: buildme
+default: build
 
 images:
   builder:

+ 1 - 3
src/buildme/cmd/builder/main.go

@@ -3,11 +3,9 @@ package main
 import (
 	"buildme"
 	"flag"
-	"strings"
 
 	_ "buildme/fetcher/git"
 	_ "buildme/fetcher/path"
-	"buildme/utils"
 
 	"dev.hexasoftware.com/hxs/prettylog"
 )
@@ -17,8 +15,8 @@ var (
 )
 
 func main() {
+	prettylog.Global()
 
-	log.Println("Test:", strings.Join(utils.ParseField("make \"myself and I \""), "\n"))
 	var fetchType string
 	var fetchPath string
 	var fetchName string

+ 1 - 0
src/buildme/fetcher.go

@@ -4,6 +4,7 @@ var (
 	fetchers = map[string]Fetcher{}
 )
 
+//RegisterFetcher global fetcher driver
 func RegisterFetcher(ftype string, fetcher Fetcher) {
 	fetchers[ftype] = fetcher
 }

+ 1 - 2
src/buildme/fetcher/git/git.go

@@ -48,7 +48,6 @@ func (g *Git) Fetch(fpath string) (*buildme.Project, error) {
 		log.Println("Err:", err)
 		return nil, err
 	}
-	projName := filepath.Base(fpath)
 	//git.
 
 	log.Println("Taring content")
@@ -62,7 +61,7 @@ func (g *Git) Fetch(fpath string) (*buildme.Project, error) {
 	log.Println("Removing dir", tmpdirname)
 	os.RemoveAll(tmpdirname)
 
-	proj := buildme.NewProject(projName)
+	proj := buildme.NewProject()
 	proj.SetTarFile(tarFile.Name(), true) // Set as temporary will delete as soon as project closes
 
 	return proj, nil

+ 1 - 2
src/buildme/fetcher/path/path.go

@@ -35,7 +35,6 @@ func (p *Path) Fetch(fpath string) (*buildme.Project, error) {
 		return nil, errors.New("Path should be a directory")
 	}
 	log.Println("Building path:", fpath)
-	projName := filepath.Base(fpath)
 
 	//tmpTarReader, err := utils.Tar(fpath, nil) // in memory
 	tarFile, err := utils.TempTar(fpath, buildme.TempDir(), "tarbuildme.")
@@ -44,7 +43,7 @@ func (p *Path) Fetch(fpath string) (*buildme.Project, error) {
 	}
 	tarFile.Close()
 	log.Println("Tar file:", tarFile.Name())
-	proj := buildme.NewProject(projName)
+	proj := buildme.NewProject()
 	proj.SetTarFile(tarFile.Name(), true)
 
 	return proj, nil

+ 14 - 20
src/buildme/project.go

@@ -28,7 +28,8 @@ type Project struct {
 	// Meta YML data
 }
 
-func NewProject(name string) *Project {
+//NewProject Creates a project
+func NewProject() *Project {
 	return &Project{
 		tarFilename: "",
 		isTemp:      false,
@@ -37,6 +38,8 @@ func NewProject(name string) *Project {
 		conf: ProjectConf{},
 	}
 }
+
+//SetTarFile sets the source project tar
 func (p *Project) SetTarFile(tarFile string, isTemp bool) *Project {
 	p.tarFilename = tarFile
 	p.isTemp = isTemp
@@ -72,7 +75,7 @@ func (p *Project) Close() {
 
 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]
 	if !ok {
@@ -99,7 +102,7 @@ func (p *Project) Task(name string) error {
 		return err
 	}
 	ctx := context.Background()
-	dockertag := p.conf.Meta.Project + "-" + taskconf.Use
+	dockerTag := p.conf.Project + "-" + taskconf.Use
 	{
 		// Check if container exists
 
@@ -111,12 +114,13 @@ func (p *Project) Task(name string) error {
 		}*/
 		// 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 {
 			return err
 		}
 		defer res.Body.Close()
 
+		// Just a reader and output
 		br := bufio.NewReader(res.Body)
 		for {
 			jdata, _, err := br.ReadLine()
@@ -132,37 +136,27 @@ func (p *Project) Task(name string) error {
 			}
 			log.Println(msg)
 		}
-
-		/*out := prettylog.NewWriter("logger")
-		_, err = io.Copy(out, res.Body)
-		if err != nil {
-			return err
-		}*/
-
 		// Just output
-
 	}
 	{
 		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 {
 			return err
 		}
-
 		// 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{})
 		if err != nil {
 			return err
 		}
 
 		log.Println("Commit container")
-
+		log.Println("============= Commiting container")
 		_, err = cli.ContainerCommit(ctx, containerRes.ID, types.ContainerCommitOptions{Config: containerCfg})
 		if err != nil {
 			return err

+ 4 - 7
src/buildme/project_conf.go

@@ -1,15 +1,12 @@
 package buildme
 
 type ProjectConf struct {
-	Meta   MetaConf             `yaml:"meta"`
-	Images map[string]ImageConf `yaml:"images"`
-	Tasks  map[string]TaskConf  `yaml:"tasks"`
+	Project string               `yaml:"project"`
+	Default string               `yaml:"default"`
+	Images  map[string]ImageConf `yaml:"images"`
+	Tasks   map[string]TaskConf  `yaml:"tasks"`
 }
 
-type MetaConf struct {
-	Project string `yaml:"project"`
-	Default string `yaml:"default"`
-}
 type ImageConf struct {
 	Dockerfile string `yaml:"dockerfile"`
 }