Add option to overwrites tags option with values specified in an file (#62)

Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/62
Reviewed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
6543
2023-05-02 19:25:49 +00:00
parent a5ea4573b0
commit 37718ded77
6 changed files with 60 additions and 7 deletions

View File

@@ -12,6 +12,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"codeberg.org/woodpecker-plugins/plugin-docker-buildx/utils"
)
// Daemon defines Docker daemon parameters.
@@ -52,6 +54,7 @@ type Build struct {
TagsDefaultName string // Docker build auto tag name override
TagsSuffix string // Docker build tags with suffix
Tags cli.StringSlice // Docker build tags
TagsFile string // Docker build tags read from an file
LabelsAuto bool // Docker build auto labels
Labels cli.StringSlice // Docker build labels
Platforms cli.StringSlice // Docker build target platforms
@@ -123,6 +126,22 @@ func (p *Plugin) Validate() error {
}
}
// overload tags flag with tags.file if set
if p.settings.Build.TagsFile != "" {
tagsFile, err := os.ReadFile(p.settings.Build.TagsFile)
if err != nil {
return fmt.Errorf("could not read tags file: %w", err)
}
// split file content into slice of tags
tagsFileList := strings.Split(strings.TrimSpace(string(tagsFile)), "\n")
// trim space of each tag
tagsFileList = utils.Map(tagsFileList, func(s string) string { return strings.TrimSpace(s) })
// finally overwrite
p.settings.Build.Tags = *cli.NewStringSlice(tagsFileList...)
}
if p.settings.Build.TagsAuto {
// we only generate tags on default branch or an tag event
if UseDefaultTag(