Skip to content

Commit

Permalink
0.2.4 new flag "singlelayer"
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed May 6, 2023
1 parent cb67750 commit 1c64b17
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
51 changes: 41 additions & 10 deletions core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions core/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 2 additions & 1 deletion example/example.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
base: debian:sid-slim
name: Vib Example
id: vib-example
singlelayer: true
labels:
maintainer: Vanilla OS Contributors
args:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

var (
Version = "0.2.3"
Version = "0.2.4"
)

func main() {
Expand Down

0 comments on commit 1c64b17

Please sign in to comment.