Allow using auto_tag while supplying additional tags via tags (#35)

This implements #32, allowing to append tags supplied via `tags` along side auto generated tags.

Tags supplied via `tags` are *not* suffixed by the `auto_tag_suffix`

Co-authored-by: Gapodo <gapodo@datenclown.at>
Reviewed-on: https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/pulls/35
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: gapodo <gapodo@geekvoid.net>
Co-committed-by: gapodo <gapodo@geekvoid.net>
This commit is contained in:
gapodo 2022-11-04 23:47:43 +01:00 committed by 6543
parent 466dfce406
commit f10f7b4c7f
2 changed files with 19 additions and 11 deletions

View File

@ -97,7 +97,7 @@ It will automatically generate buildkit configuration to use custom CA certifica
| `daemon_off` | `false` | disables the startup of the docker daemon
| `buildkit_config` | *none* | sets content of the docker [buildkit TOML config](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md)
| `context` | `.` | sets the path of the build context to use
| `default_tags`/`auto_tag` | `false` | generates tag names automatically based on git branch and git tag
| `default_tags`/`auto_tag` | `false` | generates tag names automatically based on git branch and git tag, tags supplied via `tags` are additionally added to the auto_tags without suffix
| `default_suffix"`/`auto_tag_suffix`| *none* | generates tag names with the given suffix
| `label`/`labels` | *none* | sets labels to use for the image in format `<name>=<value>`
| `default_labels`/`auto_labels` | `true` | sets docker image labels based on git information

View File

@ -86,7 +86,7 @@ func (l Login) anonymous() bool {
func (p *Plugin) InitSettings() error {
if p.settings.LoginsRaw != "" {
if err := json.Unmarshal([]byte(p.settings.LoginsRaw), &p.settings.Logins); err != nil {
return fmt.Errorf("Could not unmarshal logins: %v", err)
return fmt.Errorf("could not unmarshal logins: %v", err)
}
}
@ -131,12 +131,27 @@ func (p *Plugin) Validate() error {
logrus.Printf("cannot build docker image for %s, invalid semantic version", p.settings.Build.Ref)
return err
}
// include user supplied tags
tag = append(tag, p.sanitizedUserTags()...)
p.settings.Build.Tags = *cli.NewStringSlice(tag...)
} else {
logrus.Printf("skipping automated docker build for %s", p.settings.Build.Ref)
return nil
}
} else {
p.settings.Build.Tags = *cli.NewStringSlice(p.sanitizedUserTags()...)
}
if p.settings.Build.LabelsAuto {
p.settings.Build.Labels = *cli.NewStringSlice(p.Labels()...)
}
return nil
}
func (p *Plugin) sanitizedUserTags() []string {
// ignore empty tags
var tags []string
for _, t := range p.settings.Build.Tags.Value() {
@ -145,14 +160,7 @@ func (p *Plugin) Validate() error {
tags = append(tags, t)
}
}
p.settings.Build.Tags = *cli.NewStringSlice(tags...)
}
if p.settings.Build.LabelsAuto {
p.settings.Build.Labels = *cli.NewStringSlice(p.Labels()...)
}
return nil
return tags
}
func (p *Plugin) writeBuildkitConfig() error {