diff --git a/build/builder.go b/build/builder.go index 8c1c790..192f517 100644 --- a/build/builder.go +++ b/build/builder.go @@ -112,7 +112,7 @@ func (b *Builder) StartBuild() error { b.Conf.Logger.Debugf("Building %d steps", len(b.Build.Steps)) for i, levels := range b.Build.buildLevels { for j, s := range levels { - b.Conf.Logger.Debugf("Step %d - step_name %s: name = '%s'", i + j, s.Label, s.Name) + b.Conf.Logger.Debugf("Step %d - %s, image-name = '%s'", i + j + 1, s.Label, b.uniqueStepName(&s)) } } @@ -122,7 +122,7 @@ func (b *Builder) StartBuild() error { for j, s := range levels { b.wg.Add(1) go func(st Step) { - b.Conf.Logger.Debugf("Step %d - Parallel build for %s", i + j, st.Name) + b.Conf.Logger.Debugf("Step %d - Build for %s", i + j + 1, st.Name) defer b.wg.Done() err := b.BuildStep(&st, i+j) @@ -158,7 +158,7 @@ func (b *Builder) StartBuild() error { for i, levels := range b.Build.buildLevels { for j, s := range levels { if (j == len(levels)-1) && (i != len(b.Build.buildLevels)-1) { - b.Conf.Logger.Debugf("Step %d - Removing unwanted image %s", i+j, b.uniqueStepName(&s)) + b.Conf.Logger.Debugf("Step %d - Removing unwanted image %s", i + j + 1, 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 { @@ -221,7 +221,7 @@ func (b *Builder) uniqueStepName(step *Step) string { // BuildStep builds a single step func (b *Builder) BuildStep(step *Step, step_number int) error { - b.Conf.Logger.Noticef("Step %d - Building %s from context '%s'", step_number, step.Name, b.Conf.Workdir) + b.Conf.Logger.Noticef("Step %d - Building %s from context '%s'", step_number + 1, step.Name, b.Conf.Workdir) // fix the Dockerfile err := b.replaceFromField(step, step_number) if err != nil { @@ -234,7 +234,7 @@ func (b *Builder) BuildStep(step *Step, step_number int) error { } // call Docker to build the Dockerfile (from the parsed file) - b.Conf.Logger.Infof("Step %d - Building the %s image from %s", step_number, b.uniqueStepName(step), b.uniqueDockerfile(step)) + b.Conf.Logger.Infof("Step %d - Building the %s image from %s", step_number + 1, b.uniqueStepName(step), b.uniqueDockerfile(step)) opts := docker.BuildImageOptions{ Name: b.uniqueStepName(step), Dockerfile: b.uniqueDockerfileName(step), @@ -549,7 +549,7 @@ func (b *Builder) BuildStep(step *Step, step_number int) 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, step_number int) error { - b.Conf.Logger.Noticef("Step %d - Parsing and converting '%s'", step_number, step.Dockerfile) + b.Conf.Logger.Noticef("Step %d - Parsing and converting '%s'", step_number + 1, step.Dockerfile) rwc, err := os.Open(path.Join(b.Conf.Workdir, step.Dockerfile)) if err != nil { @@ -580,7 +580,7 @@ func (b *Builder) replaceFromField(step *Step, step_number int) error { buffer = fromTag.ReplaceAll(buffer, []byte("FROM " + uniqueStepName)) } - b.Conf.Logger.Debugf("Step %d - Writing the new Dockerfile into '%s'", step_number, b.uniqueDockerfile(step)) + b.Conf.Logger.Debugf("Step %d - Writing the new Dockerfile into '%s'", step_number + 1, b.uniqueDockerfile(step)) err = ioutil.WriteFile(b.uniqueDockerfile(step), buffer, 0644) if err != nil { return err diff --git a/build/manifest.go b/build/manifest.go index 3c37c03..50674e2 100644 --- a/build/manifest.go +++ b/build/manifest.go @@ -44,7 +44,7 @@ type Step struct { Label string Dockerfile string Artifacts []Artifact - Manifest Manifest + Manifest *Manifest Cleanup *Cleanup DependsOn []*Step Command string @@ -121,20 +121,20 @@ func LoadBuildFromFile(config *configuration.Config) (*Manifest, error) { } func (n *namespace) convertToBuild(version string) (*Manifest, error) { - r := Manifest{ + manifest := Manifest{ SecretProviders: make(map[string]secrets.SecretProvider), } - r.SecretProviders["file"] = &secrets.FileProvider{} - r.SecretProviders["env"] = &secrets.EnvProvider{} + manifest.SecretProviders["file"] = &secrets.FileProvider{} + manifest.SecretProviders["env"] = &secrets.EnvProvider{} - r.IsPrivileged = false - r.Steps = []Step{} + manifest.IsPrivileged = false + manifest.Steps = []Step{} for name, s := range n.BuildConfig.Steps { convertedStep := Step{} - convertedStep.Manifest = r + convertedStep.Manifest = &manifest convertedStep.Dockerfile = s.Dockerfile convertedStep.Name = s.Name convertedStep.Label = name @@ -142,7 +142,7 @@ func (n *namespace) convertToBuild(version string) (*Manifest, error) { convertedStep.Command = s.Command if s.Cleanup != nil && !n.Config.NoSquash { convertedStep.Cleanup = &Cleanup{Commands: s.Cleanup.Commands} - r.IsPrivileged = true + manifest.IsPrivileged = true } else { convertedStep.Cleanup = &Cleanup{} } @@ -162,7 +162,7 @@ func (n *namespace) convertToBuild(version string) (*Manifest, error) { return nil, fmt.Errorf("Unsupported type '%s'", s.Type) } - r.SecretProviders[s.Type].RegisterSecret(name, s.Value) + manifest.SecretProviders[s.Type].RegisterSecret(name, s.Value) convertedStep.Secrets = append(convertedStep.Secrets, convertedSecret) } @@ -185,21 +185,21 @@ func (n *namespace) convertToBuild(version string) (*Manifest, error) { } // is it unique? - for _, s := range r.Steps { + for _, s := range manifest.Steps { if s.Name == convertedStep.Name { return nil, fmt.Errorf("Step name '%s' is not unique", convertedStep.Name) } } - r.Steps = append(r.Steps, convertedStep) + manifest.Steps = append(manifest.Steps, convertedStep) } // now that we have the Manifest built from the file, we can resolve dependencies - for idx, step := range r.Steps { + for idx, step := range manifest.Steps { bStep := n.BuildConfig.Steps[step.Label] for _, d := range bStep.DependsOn { - convertedStep, err := r.FindStepByLabel(d) + convertedStep, err := manifest.FindStepByLabel(d) if err != nil { return nil, err } @@ -207,18 +207,18 @@ func (n *namespace) convertToBuild(version string) (*Manifest, error) { return nil, fmt.Errorf("can't find step %s", d) } - r.Steps[idx].DependsOn = append(r.Steps[idx].DependsOn, convertedStep) + manifest.Steps[idx].DependsOn = append(manifest.Steps[idx].DependsOn, convertedStep) } } // build the dependency tree - bl, err := r.serviceOrder(r.Steps) + bl, err := manifest.serviceOrder(manifest.Steps) if err != nil { return nil, err } - r.buildLevels = bl + manifest.buildLevels = bl - return &r, nil + return &manifest, nil } func (m *Manifest) getStepsByLevel(level int) ([]Step, error) { diff --git a/examples/uid_nested/Dockerfile.base b/examples/uid_nested/Dockerfile.base new file mode 100644 index 0000000..19b6dbb --- /dev/null +++ b/examples/uid_nested/Dockerfile.base @@ -0,0 +1,2 @@ +FROM alpine:3.5 +RUN echo 'the base' \ No newline at end of file diff --git a/examples/uid_nested/Dockerfile.compile b/examples/uid_nested/Dockerfile.compile new file mode 100644 index 0000000..2f5f78b --- /dev/null +++ b/examples/uid_nested/Dockerfile.compile @@ -0,0 +1,2 @@ +FROM base +RUN echo 'compiling' \ No newline at end of file diff --git a/examples/uid_nested/Dockerfile.runtime b/examples/uid_nested/Dockerfile.runtime new file mode 100644 index 0000000..d8b1b0e --- /dev/null +++ b/examples/uid_nested/Dockerfile.runtime @@ -0,0 +1,2 @@ +FROM base +RUN echo 'runtime' \ No newline at end of file diff --git a/examples/uid_nested/build.yml b/examples/uid_nested/build.yml new file mode 100644 index 0000000..334e2ba --- /dev/null +++ b/examples/uid_nested/build.yml @@ -0,0 +1,16 @@ +build: + version: 2016-03-14 + steps: + base: + name: base + dockerfile: Dockerfile.base + compilation: + name: compilation + dockerfile: Dockerfile.compile + depends_on: + - base + runtime: + name: runtime + dockerfile: Dockerfile.runtime + depends_on: + - compilation