Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:cloud66/habitus
Browse files Browse the repository at this point in the history
  • Loading branch information
lvangool committed Mar 18, 2016
2 parents 7c69de7 + 4063881 commit f133be2
Show file tree
Hide file tree
Showing 210 changed files with 141 additions and 30,496 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Folders
_obj
_test
build
artifacts

# Architecture specific extensions/prefixes
Expand Down
8 changes: 4 additions & 4 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 33 additions & 33 deletions build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ func NewBuilder(manifest *Manifest, conf *configuration.Config) *Builder {

// StartBuild runs the build process end to end
func (b *Builder) StartBuild() error {
b.Conf.Logger.Debug("Building %d steps", len(b.Build.Steps))
b.Conf.Logger.Debugf("Building %d steps", len(b.Build.Steps))
for i, s := range b.Build.Steps {
b.Conf.Logger.Debug("Step %d - %s: %s", i, s.Label, s.Name)
b.Conf.Logger.Debugf("Step %d - %s: %s", i, s.Label, s.Name)
}

for _, levels := range b.Build.buildLevels {
for _, s := range levels {
b.wg.Add(1)
go func(st Step) {
b.Conf.Logger.Debug("Parallel build for %s", st.Name)
b.Conf.Logger.Debugf("Parallel build for %s", st.Name)
defer b.wg.Done()

err := b.BuildStep(&st)
Expand All @@ -131,7 +131,7 @@ func (b *Builder) StartBuild() error {
// Clear after yourself: images, containers, etc (optional for premium users)
// except last step
for _, s := range b.Build.Steps[:len(b.Build.Steps)-1] {
b.Conf.Logger.Debug("Removing unwanted image %s", b.uniqueStepName(&s))
b.Conf.Logger.Debugf("Removing unwanted image %s", b.uniqueStepName(&s))
rmiOptions := docker.RemoveImageOptions{Force: b.Conf.FroceRmImages, NoPrune: b.Conf.NoPruneRmImages}
err := b.docker.RemoveImageExtended(b.uniqueStepName(&s), rmiOptions)
if err != nil {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (b *Builder) uniqueStepName(step *Step) string {

// BuildStep builds a single step
func (b *Builder) BuildStep(step *Step) error {
b.Conf.Logger.Notice("Building %s", step.Name)
b.Conf.Logger.Noticef("Building %s", step.Name)
// fix the Dockerfile
err := b.replaceFromField(step)
if err != nil {
Expand All @@ -174,7 +174,7 @@ func (b *Builder) BuildStep(step *Step) error {
buildArgs = append(buildArgs, docker.BuildArg{Name: s.Key, Value: s.Value})
}
// call Docker to build the Dockerfile (from the parsed file)
b.Conf.Logger.Debug("Building the image from %s", filepath.Base(b.uniqueDockerfile(step)))
b.Conf.Logger.Debugf("Building the image from %s", filepath.Base(b.uniqueDockerfile(step)))
opts := docker.BuildImageOptions{
Name: b.uniqueStepName(step),
Dockerfile: filepath.Base(b.uniqueDockerfile(step)),
Expand Down Expand Up @@ -209,15 +209,15 @@ func (b *Builder) BuildStep(step *Step) error {

if !b.Conf.NoSquash && len(step.Cleanup.Commands) > 0 {
// start the container
b.Conf.Logger.Notice("Starting container %s to run cleanup commands", container.ID)
b.Conf.Logger.Noticef("Starting container %s to run cleanup commands", container.ID)
startOpts := &docker.HostConfig{}
err := b.docker.StartContainer(container.ID, startOpts)
if err != nil {
return err
}

for _, cmd := range step.Cleanup.Commands {
b.Conf.Logger.Debug("Running cleanup command %s on %s", cmd, container.ID)
b.Conf.Logger.Debugf("Running cleanup command %s on %s", cmd, container.ID)
// create an exec for the commands
execOpts := docker.CreateExecOptions{
Container: container.ID,
Expand All @@ -242,7 +242,7 @@ func (b *Builder) BuildStep(step *Step) error {
}

if err := b.docker.StartExec(execObj.ID, startExecOpts); err != nil {
b.Conf.Logger.Error("Failed to run cleanup commands %s", err.Error())
b.Conf.Logger.Errorf("Failed to run cleanup commands %s", err.Error())
}
success <- struct{}{}
}()
Expand All @@ -254,13 +254,13 @@ func (b *Builder) BuildStep(step *Step) error {
Container: container.ID,
}

b.Conf.Logger.Debug("Commiting the container %s", container.ID)
b.Conf.Logger.Debugf("Commiting the container %s", container.ID)
img, err := b.docker.CommitContainer(cmtOpts)
if err != nil {
return err
}

b.Conf.Logger.Debug("Stopping the container %s", container.ID)
b.Conf.Logger.Debugf("Stopping the container %s", container.ID)
err = b.docker.StopContainer(container.ID, 0)
if err != nil {
return err
Expand All @@ -282,7 +282,7 @@ func (b *Builder) BuildStep(step *Step) error {
OutputStream: tarWriter,
}

b.Conf.Logger.Notice("Exporting cleaned up container %s to %s", img.ID, tmpFile.Name())
b.Conf.Logger.Noticef("Exporting cleaned up container %s to %s", img.ID, tmpFile.Name())
err = b.docker.ExportImage(expOpts)
if err != nil {
return err
Expand All @@ -294,15 +294,15 @@ func (b *Builder) BuildStep(step *Step) error {
return err
}
defer sqTmpFile.Close()
b.Conf.Logger.Notice("Squashing image %s into %s", sqTmpFile.Name(), img.ID)
b.Conf.Logger.Noticef("Squashing image %s into %s", sqTmpFile.Name(), img.ID)

squasher := squash.Squasher{Conf: b.Conf}
err = squasher.Squash(tmpFile.Name(), sqTmpFile.Name(), b.uniqueStepName(step))
if err != nil {
return err
}

b.Conf.Logger.Debug("Removing exported temp files")
b.Conf.Logger.Debugf("Removing exported temp files")
err = os.Remove(tmpFile.Name())
if err != nil {
return err
Expand All @@ -317,7 +317,7 @@ func (b *Builder) BuildStep(step *Step) error {
loadOps := docker.LoadImageOptions{
InputStream: sqashedFile,
}
b.Conf.Logger.Debug("Loading squashed image into docker")
b.Conf.Logger.Debugf("Loading squashed image into docker")
err = b.docker.LoadImage(loadOps)
if err != nil {
return err
Expand All @@ -330,7 +330,7 @@ func (b *Builder) BuildStep(step *Step) error {
}

if len(step.Artefacts) > 0 {
b.Conf.Logger.Notice("Starting container %s to fetch artefact permissions", container.ID)
b.Conf.Logger.Noticef("Starting container %s to fetch artefact permissions", container.ID)
startOpts := &docker.HostConfig{}
err := b.docker.StartContainer(container.ID, startOpts)
if err != nil {
Expand Down Expand Up @@ -362,25 +362,25 @@ func (b *Builder) BuildStep(step *Step) error {
}

if err := b.docker.StartExec(execObj.ID, startExecOpts); err != nil {
b.Conf.Logger.Error("Failed to fetch artefact permissions for %s: %s", art.Source, err.Error())
b.Conf.Logger.Errorf("Failed to fetch artefact permissions for %s: %s", art.Source, err.Error())
}

permsString := strings.Replace(strings.Replace(buf.String(), "'", "", -1), "\n", "", -1)
perms, err := strconv.Atoi(permsString)
if err != nil {
b.Conf.Logger.Error("Failed to fetch artefact permissions for %s: %s", art.Source, err.Error())
b.Conf.Logger.Errorf("Failed to fetch artefact permissions for %s: %s", art.Source, err.Error())
}
permMap[art.Source] = perms
b.Conf.Logger.Debug("Permissions for %s is %d", art.Source, perms)
b.Conf.Logger.Debugf("Permissions for %s is %d", art.Source, perms)
}

b.Conf.Logger.Debug("Stopping the container %s", container.ID)
b.Conf.Logger.Debugf("Stopping the container %s", container.ID)
err = b.docker.StopContainer(container.ID, 0)
if err != nil {
return err
}

b.Conf.Logger.Notice("Copying artefacts from %s", container.ID)
b.Conf.Logger.Noticef("Copying artefacts from %s", container.ID)

for _, art := range step.Artefacts {
err = b.copyToHost(&art, container.ID, permMap)
Expand All @@ -392,7 +392,7 @@ func (b *Builder) BuildStep(step *Step) error {

// any commands to run?
if step.Command != "" {
b.Conf.Logger.Notice("Starting container %s to run commands", container.ID)
b.Conf.Logger.Noticef("Starting container %s to run commands", container.ID)
startOpts := &docker.HostConfig{}

err := b.docker.StartContainer(container.ID, startOpts)
Expand Down Expand Up @@ -421,27 +421,27 @@ func (b *Builder) BuildStep(step *Step) error {
Detach: false,
}

b.Conf.Logger.Notice("Running command %s on container %s", execOpts.Cmd, container.ID)
b.Conf.Logger.Noticef("Running command %s on container %s", execOpts.Cmd, container.ID)

if err := b.docker.StartExec(execObj.ID, startExecOpts); err != nil {
b.Conf.Logger.Error("Failed to execute command '%s' due to %s", step.Command, err.Error())
b.Conf.Logger.Errorf("Failed to execute command '%s' due to %s", step.Command, err.Error())
}

b.Conf.Logger.Notice("\n%s", buf)
b.Conf.Logger.Noticef("\n%s", buf)

inspect, err := b.docker.InspectExec(execObj.ID)
if err != nil {
return err
}

if inspect.ExitCode != 0 {
b.Conf.Logger.Error("Running command %s on container %s exit with exit code %d", execOpts.Cmd, container.ID, inspect.ExitCode)
b.Conf.Logger.Errorf("Running command %s on container %s exit with exit code %d", execOpts.Cmd, container.ID, inspect.ExitCode)
return err
} else {
b.Conf.Logger.Notice("Running command %s on container %s exit with exit code %d", execOpts.Cmd, container.ID, inspect.ExitCode)
b.Conf.Logger.Noticef("Running command %s on container %s exit with exit code %d", execOpts.Cmd, container.ID, inspect.ExitCode)
}

b.Conf.Logger.Debug("Stopping the container %s", container.ID)
b.Conf.Logger.Debugf("Stopping the container %s", container.ID)
err = b.docker.StopContainer(container.ID, 0)
if err != nil {
return err
Expand All @@ -455,7 +455,7 @@ func (b *Builder) BuildStep(step *Step) error {
Force: true,
}

b.Conf.Logger.Debug("Removing built container %s", container.ID)
b.Conf.Logger.Debugf("Removing built container %s", container.ID)
err = b.docker.RemoveContainer(removeOpts)
if err != nil {
return err
Expand All @@ -474,7 +474,7 @@ func (b *Builder) BuildStep(step *Step) error {
// this replaces the FROM field in the Dockerfile to one with the previous step's unique name
// it stores the parsed result Dockefile in uniqueSessionName file
func (b *Builder) replaceFromField(step *Step) error {
b.Conf.Logger.Notice("Parsing and converting '%s'", step.Dockerfile)
b.Conf.Logger.Noticef("Parsing and converting '%s'", step.Dockerfile)

rwc, err := os.Open(path.Join(b.Conf.Workdir, step.Dockerfile))
if err != nil {
Expand Down Expand Up @@ -507,7 +507,7 @@ func (b *Builder) replaceFromField(step *Step) error {
}

// did it have any effect?
b.Conf.Logger.Debug("Writing the new Dockerfile into %s", step.Dockerfile+".generated")
b.Conf.Logger.Debugf("Writing the new Dockerfile into %s", step.Dockerfile+".generated")
err = ioutil.WriteFile(b.uniqueDockerfile(step), []byte(dumpDockerfile(node)), 0644)
if err != nil {
return err
Expand Down Expand Up @@ -561,7 +561,7 @@ func (b *Builder) copyToHost(a *Artefact, container string, perms map[string]int

switch hdr.Typeflag {
case tar.TypeReg:
b.Conf.Logger.Info("Copying from %s to %s", a.Source, destFile)
b.Conf.Logger.Infof("Copying from %s to %s", a.Source, destFile)

dest, err := os.Create(destFile)
if err != nil {
Expand All @@ -577,7 +577,7 @@ func (b *Builder) copyToHost(a *Artefact, container string, perms map[string]int
}
}

b.Conf.Logger.Debug("Setting file permissions for %s to %d", destFile, perms[a.Source])
b.Conf.Logger.Debugf("Setting file permissions for %s to %d", destFile, perms[a.Source])
err = os.Chmod(destFile, os.FileMode(perms[a.Source])|0700)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion build/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type namespace struct {

// LoadBuildFromFile loads Build from a yaml file
func LoadBuildFromFile(config *configuration.Config) (*Manifest, error) {
config.Logger.Notice("Using '%s' as build file", config.Buildfile)
config.Logger.Noticef("Using '%s' as build file", config.Buildfile)

n := namespace{Config: config}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var prettyFormat = logging.MustStringFormatter(
"%{color}▶ %{message} %{color:reset}",
)
var plainFormat = logging.MustStringFormatter(
"[%{level:-8s}] - %{message}",
"[%{level}] - %{message}",
)

var (
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (s *server) StartServer() error {
api.SetApp(router)

go func() {
s.builder.Conf.Logger.Info("Starting API on %d", s.builder.Conf.ApiPort)
s.builder.Conf.Logger.Infof("Starting API on %d", s.builder.Conf.ApiPort)

// 192.168.99.1
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", s.builder.Conf.ApiBinding, s.builder.Conf.ApiPort), api.MakeHandler()); err != nil {
s.builder.Conf.Logger.Error("Failed to start API %s", err.Error())
s.builder.Conf.Logger.Errorf("Failed to start API %s", err.Error())
os.Exit(2)
}

Expand Down
18 changes: 9 additions & 9 deletions squash/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func LoadExport(conf *configuration.Config, image, location string) (*Export, er
}

if image == "" {
conf.Logger.Debug("Loading export from STDIN using %s for tempdir", location)
conf.Logger.Debugf("Loading export from STDIN using %s for tempdir", location)
} else {
conf.Logger.Debug("Loading export from %s using %s for tempdir", image, location)
conf.Logger.Debugf("Loading export from %s using %s for tempdir", image, location)
}

ir := os.Stdin
Expand Down Expand Up @@ -192,9 +192,9 @@ func LoadExport(conf *configuration.Config, image, location string) (*Export, er
return nil, err
}

conf.Logger.Debug("Loaded image w/ %s layers", strconv.FormatInt(int64(len(export.Entries)), 10))
conf.Logger.Debugf("Loaded image w/ %s layers", strconv.FormatInt(int64(len(export.Entries)), 10))
for repo, tags := range export.Repositories {
conf.Logger.Debug(" - %s (%s tags)", repo, strconv.FormatInt(int64(len(*tags)), 10))
conf.Logger.Debugf(" - %s (%s tags)", repo, strconv.FormatInt(int64(len(*tags)), 10))
}
return export, err
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (e *Export) ExtractLayers() error {
e.conf.Logger.Debug("Extracting layers...")

for _, entry := range e.Entries {
e.conf.Logger.Debug(" - %s", entry.LayerTarPath)
e.conf.Logger.Debugf(" - %s", entry.LayerTarPath)
err := entry.ExtractLayerDir()
if err != nil {
return err
Expand Down Expand Up @@ -355,7 +355,7 @@ func (e *Export) PrintHistory() {
cmd = cmd[0:57] + "..."
}

e.conf.Logger.Debug(" - %s %s %s %s", order[i].LayerConfig.Id[0:12],
e.conf.Logger.Debugf(" - %s %s %s %s", order[i].LayerConfig.Id[0:12],
humanDuration(time.Now().UTC().Sub(order[i].LayerConfig.Created.UTC())),
cmd, units.HumanSize(float64(size)))
}
Expand Down Expand Up @@ -422,7 +422,7 @@ func (e *Export) ReplaceLayer(oldId string) (*ExportedImage, error) {
cmd = cmd[:47] + "..."
}

e.conf.Logger.Debug(" - Replacing %s w/ new layer %s (%s)", oldId[:12], id[:12], cmd)
e.conf.Logger.Debugf(" - Replacing %s w/ new layer %s (%s)", oldId[:12], id[:12], cmd)
if child != nil {
child.LayerConfig.Parent = id
err = child.WriteJson()
Expand Down Expand Up @@ -474,7 +474,7 @@ func (e *Export) ReplaceLayer(oldId string) (*ExportedImage, error) {

func (e *Export) SquashLayers(to, from *ExportedImage) error {

e.conf.Logger.Debug("Squashing from %s into %s", from.LayerConfig.Id[:12], to.LayerConfig.Id[:12])
e.conf.Logger.Debugf("Squashing from %s into %s", from.LayerConfig.Id[:12], to.LayerConfig.Id[:12])
layerDir := filepath.Join(to.Path, "layer")
err := os.MkdirAll(layerDir, 0755)
if err != nil {
Expand Down Expand Up @@ -601,7 +601,7 @@ func (e *Export) rewriteChildren(entry *ExportedImage) error {

entry = e.ChildOf(newEntry.LayerConfig.Id)
} else {
e.conf.Logger.Debug(" - Removing %s. Squashed. (%s)", entry.LayerConfig.Id[:12], cmd)
e.conf.Logger.Debugf(" - Removing %s. Squashed. (%s)", entry.LayerConfig.Id[:12], cmd)
err := os.RemoveAll(entry.Path)
if err != nil {
return err
Expand Down
Loading

0 comments on commit f133be2

Please sign in to comment.