1
0

feat!: prepend/append commands to dockerfile

BREAKING CHANGE: Command definition in the configuration has been changed

from

[[docker.commands]]
distro = { id = "Ubuntu" }
command = "echo runs before the base layer"

to

[[docker.commands.prepend]]
distro = { id = "Ubuntu" }
command = "echo runs before the base layer"
This commit is contained in:
dump_stack() 2024-10-06 16:11:29 +00:00
parent cba1abc7f4
commit a7ecc354a9
Signed by: dump_stack
GPG Key ID: C9905BA72B5E02BB
2 changed files with 32 additions and 7 deletions

View File

@ -35,9 +35,12 @@ type OutOfTree struct {
Timeout artifact.Duration
Registry string
// Commands that will be executed before
// the base layer of Dockerfile
Commands []distro.Command
// Commands that are executed before (prepend) and after (append) the
// base layer of the Dockerfile.
Commands struct {
Prepend []distro.Command
Append []distro.Command
}
}
}

View File

@ -32,7 +32,12 @@ var Registry = ""
var Timeout time.Duration
var Commands []distro.Command
// Commands that are executed before (prepend) and after (append) the
// base layer of the Dockerfile.
var Commands struct {
Prepend []distro.Command
Append []distro.Command
}
var UseCache = true
@ -296,9 +301,15 @@ func (c Container) Build(image string, envs, runs []string) (err error) {
}
cf += image + "\n"
for _, c := range Commands {
// TODO check for distro type
cf += "RUN " + c.Command + "\n"
for _, cmd := range Commands.Prepend {
if cmd.Distro.ID != distro.None && cmd.Distro.ID != c.dist.ID {
continue
}
if cmd.Distro.Release != "" && cmd.Distro.Release != c.dist.Release {
continue
}
cf += "RUN " + cmd.Command + "\n"
}
for _, e := range envs {
@ -309,6 +320,17 @@ func (c Container) Build(image string, envs, runs []string) (err error) {
cf += "RUN " + c + "\n"
}
for _, cmd := range Commands.Append {
if cmd.Distro.ID != distro.None && cmd.Distro.ID != c.dist.ID {
continue
}
if cmd.Distro.Release != "" && cmd.Distro.Release != c.dist.Release {
continue
}
cf += "RUN " + cmd.Command + "\n"
}
buf, err := os.ReadFile(cfile)
if err != nil {
err = os.WriteFile(cfile, []byte(cf), os.ModePerm)