diff --git a/core/build.go b/core/build.go index 85c7e8e..a8bf726 100644 --- a/core/build.go +++ b/core/build.go @@ -84,12 +84,14 @@ func BuildContainerfile(recipe *Recipe, cmds []ModuleCommand) error { } // RUN(S) - for _, cmd := range recipe.Runs { - _, err = containerfile.WriteString( - fmt.Sprintf("RUN %s\n", cmd), - ) - if err != nil { - return err + if !recipe.SingleLayer { + for _, cmd := range recipe.Runs { + _, err = containerfile.WriteString( + fmt.Sprintf("RUN %s\n", cmd), + ) + if err != nil { + return err + } } } @@ -106,10 +108,39 @@ func BuildContainerfile(recipe *Recipe, cmds []ModuleCommand) error { } // MODULES RUN(S) - for _, cmd := range cmds { - _, err = containerfile.WriteString( - fmt.Sprintf("RUN %s\n", cmd.Command), - ) + if !recipe.SingleLayer { + for _, cmd := range cmds { + _, err = containerfile.WriteString( + fmt.Sprintf("RUN %s\n", cmd.Command), + ) + if err != nil { + return err + } + } + } + + // SINGLE LAYER + if recipe.SingleLayer { + unifiedCmd := "RUN " + for i, cmd := range recipe.Runs { + unifiedCmd += cmd + if i != len(recipe.Runs)-1 { + unifiedCmd += " && " + } + } + + if len(cmds) > 0 { + unifiedCmd += " && " + } + + for i, cmd := range cmds { + unifiedCmd += cmd.Command + if i != len(cmds)-1 { + unifiedCmd += " && " + } + } + + _, err = containerfile.WriteString(unifiedCmd) if err != nil { return err } diff --git a/core/structs.go b/core/structs.go index e338120..e72fa42 100644 --- a/core/structs.go +++ b/core/structs.go @@ -4,6 +4,7 @@ type Recipe struct { Base string `json:"base"` Name string Id string + SingleLayer bool `json:"singlelayer"` Labels map[string]string `json:"labels"` Args map[string]string `json:"args"` Runs []string `json:"runs"` diff --git a/example/example.yml b/example/example.yml index 9f5a428..e89202b 100644 --- a/example/example.yml +++ b/example/example.yml @@ -1,6 +1,7 @@ base: debian:sid-slim name: Vib Example id: vib-example +singlelayer: true labels: maintainer: Vanilla OS Contributors args: @@ -11,7 +12,7 @@ runs: modules: - name: abroot-git type: go - buildVars: + buildvars: GO_OUTPUT_BIN: "/usr/local/bin/abroot" source: url: https://github.com/vanilla-os/abroot.git diff --git a/main.go b/main.go index 0164cc3..cd3d460 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( ) var ( - Version = "0.2.3" + Version = "0.2.4" ) func main() {