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:
parent
cba1abc7f4
commit
a7ecc354a9
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user