ability to disable purge

This commit is contained in:
Brad Rydzewski
2017-11-09 13:28:19 -08:00
parent 55fd78d1cc
commit 224a31a416
5 changed files with 95 additions and 92 deletions

View File

@@ -53,31 +53,14 @@ type (
// Plugin defines the Docker plugin parameters.
Plugin struct {
Login Login // Docker login configuration
Build Build // Docker build configuration
Daemon Daemon // Docker daemon configuration
Dryrun bool // Docker push is skipped
Login Login // Docker login configuration
Build Build // Docker build configuration
Daemon Daemon // Docker daemon configuration
Dryrun bool // Docker push is skipped
Cleanup bool // Docker purge is enabled
}
)
func stripHeadPrefix(ref string) string {
ref = strings.TrimPrefix(ref, "refs/heads/")
return ref
}
// UseDefaultTag for keep only default branch for latest tag
func UseDefaultTag(ref, defaultBranch string) bool {
if strings.HasPrefix(ref, "refs/tags/") {
return true
}
if stripHeadPrefix(ref) == defaultBranch {
return true
}
return false
}
// Exec executes the plugin step
func (p Plugin) Exec() error {
// start the Docker daemon server
@@ -140,8 +123,10 @@ func (p Plugin) Exec() error {
}
}
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
cmds = append(cmds, commandPrune()) // docker system prune -f
if p.Cleanup {
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
cmds = append(cmds, commandPrune()) // docker system prune -f
}
// execute all commands in batch mode.
for _, cmd := range cmds {