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:
parent
a5ea4573b0
commit
37718ded77
@ -4,7 +4,7 @@
|
|||||||
<img alt="Get it on Codeberg" src="https://codeberg.org/Codeberg/GetItOnCodeberg/media/branch/main/get-it-on-neon-blue.png" height="60">
|
<img alt="Get it on Codeberg" src="https://codeberg.org/Codeberg/GetItOnCodeberg/media/branch/main/get-it-on-neon-blue.png" height="60">
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
Woodpecker CI plugin to build multiarch Docker images with buildx. This plugin is a fork of [thegeeklab/drone-docker-buildx](https://github.com/thegeeklab/drone-docker-buildx/) which itself is a fork of [drone-plugins/drone-docker](https://github.com/drone-plugins/drone-docker). You can find the full documentation at [woodpecker-ci.org](https://woodpecker-ci.org/plugins/Docker%20Buildx).
|
Woodpecker CI plugin to build multiarch Docker images with buildx. This plugin is a fork of [thegeeklab/drone-docker-buildx](https://github.com/thegeeklab/drone-docker-buildx/) which itself is a fork of [drone-plugins/drone-docker](https://github.com/drone-plugins/drone-docker). You can find the full documentation at [woodpecker-ci.org](https://woodpecker-ci.org/plugins/Docker%20Buildx) ([docs.md](./docs.md)).
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
|
@ -121,6 +121,12 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
|||||||
FilePath: ".tags",
|
FilePath: ".tags",
|
||||||
Destination: &settings.Build.Tags,
|
Destination: &settings.Build.Tags,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "tags.file",
|
||||||
|
EnvVars: []string{"PLUGIN_TAGS_FILE", "PLUGIN_TAG_FILE"},
|
||||||
|
Usage: "overwrites tags flag with values find in set file",
|
||||||
|
Destination: &settings.Build.TagsFile,
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "tags.auto",
|
Name: "tags.auto",
|
||||||
EnvVars: []string{"PLUGIN_AUTO_TAG"},
|
EnvVars: []string{"PLUGIN_AUTO_TAG"},
|
||||||
|
13
docs.md
13
docs.md
@ -9,7 +9,7 @@ containerImageUrl: https://hub.docker.com/r/woodpeckerci/plugin-docker-buildx
|
|||||||
url: https://codeberg.org/woodpecker-plugins/docker-buildx
|
url: https://codeberg.org/woodpecker-plugins/docker-buildx
|
||||||
---
|
---
|
||||||
|
|
||||||
Woodpecker CI plugin to build multiarch Docker images with buildx. This plugin is a fork of [thegeeklab/drone-docker-buildx](https://github.com/thegeeklab/drone-docker-buildx/) which itself is a fork of [drone-plugins/drone-docker](https://github.com/drone-plugins/drone-docker). You can find the full documentation at [woodpecker-ci.org](https://woodpecker-ci.org/plugins/Docker%20Buildx).
|
Woodpecker CI plugin to build multiarch Docker images with buildx. This plugin is a fork of [thegeeklab/drone-docker-buildx](https://github.com/thegeeklab/drone-docker-buildx/) which itself is a fork of [drone-plugins/drone-docker](https://github.com/drone-plugins/drone-docker).
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ It will automatically generate buildkit configuration to use custom CA certifica
|
|||||||
| `email` | *none* | sets email address to authenticates with
|
| `email` | *none* | sets email address to authenticates with
|
||||||
| `registry` | `https://index.docker.io/v1/` | sets docker registry to authenticate with
|
| `registry` | `https://index.docker.io/v1/` | sets docker registry to authenticate with
|
||||||
| `dockerfile` | `Dockerfile` | sets dockerfile to use for the image build
|
| `dockerfile` | `Dockerfile` | sets dockerfile to use for the image build
|
||||||
| `tag`/`tags` | @".tags" | sets repository tags to use for the image
|
| `tag`/`tags` | *none* | sets repository tags to use for the image
|
||||||
| `platforms` | *none* | sets target platform for build
|
| `platforms` | *none* | sets target platform for build
|
||||||
|
|
||||||
## auto_tag
|
## auto_tag
|
||||||
@ -48,7 +48,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```yml
|
```yaml
|
||||||
publish-next-agent:
|
publish-next-agent:
|
||||||
image: woodpeckerci/plugin-docker-buildx
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [docker_username, docker_password]
|
secrets: [docker_username, docker_password]
|
||||||
@ -62,7 +62,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
|
|||||||
event: push
|
event: push
|
||||||
```
|
```
|
||||||
|
|
||||||
```yml
|
```yaml
|
||||||
publish:
|
publish:
|
||||||
image: woodpeckerci/plugin-docker-buildx
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
settings:
|
settings:
|
||||||
@ -75,7 +75,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
|
|||||||
from_secret: cb_token
|
from_secret: cb_token
|
||||||
```
|
```
|
||||||
|
|
||||||
```yml
|
```yaml
|
||||||
docker-build:
|
docker-build:
|
||||||
image: woodpeckerci/plugin-docker-buildx
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
settings:
|
settings:
|
||||||
@ -102,6 +102,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
|
|||||||
| `debug` | `false` | enables verbose debug mode for the docker daemon
|
| `debug` | `false` | enables verbose debug mode for the docker daemon
|
||||||
| `daemon_off` | `false` | disables the startup of the docker daemon
|
| `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)
|
| `buildkit_config` | *none* | sets content of the docker [buildkit TOML config](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md)
|
||||||
|
| `tags_file` | *none* | overwrites `tags` option with values find in specified file
|
||||||
| `context` | `.` | sets the path of the build context to use
|
| `context` | `.` | sets the path of the build context to use
|
||||||
| `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
|
| `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
|
| `default_suffix"`/`auto_tag_suffix`| *none* | generates tag names with the given suffix
|
||||||
@ -126,7 +127,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
|
|||||||
|
|
||||||
Only supported with `woodpecker >= 1.0.0` (next-da997fa3).
|
Only supported with `woodpecker >= 1.0.0` (next-da997fa3).
|
||||||
|
|
||||||
```yml
|
```yaml
|
||||||
settings:
|
settings:
|
||||||
repo: a6543/tmp,codeberg.org/6543/tmp
|
repo: a6543/tmp,codeberg.org/6543/tmp
|
||||||
tag: demo
|
tag: demo
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
|
"codeberg.org/woodpecker-plugins/plugin-docker-buildx/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Daemon defines Docker daemon parameters.
|
// Daemon defines Docker daemon parameters.
|
||||||
@ -52,6 +54,7 @@ type Build struct {
|
|||||||
TagsDefaultName string // Docker build auto tag name override
|
TagsDefaultName string // Docker build auto tag name override
|
||||||
TagsSuffix string // Docker build tags with suffix
|
TagsSuffix string // Docker build tags with suffix
|
||||||
Tags cli.StringSlice // Docker build tags
|
Tags cli.StringSlice // Docker build tags
|
||||||
|
TagsFile string // Docker build tags read from an file
|
||||||
LabelsAuto bool // Docker build auto labels
|
LabelsAuto bool // Docker build auto labels
|
||||||
Labels cli.StringSlice // Docker build labels
|
Labels cli.StringSlice // Docker build labels
|
||||||
Platforms cli.StringSlice // Docker build target platforms
|
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 {
|
if p.settings.Build.TagsAuto {
|
||||||
// we only generate tags on default branch or an tag event
|
// we only generate tags on default branch or an tag event
|
||||||
if UseDefaultTag(
|
if UseDefaultTag(
|
||||||
|
9
utils/lamda.go
Normal file
9
utils/lamda.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
func Map[T any](in []T, fn func(T) T) []T {
|
||||||
|
out := in
|
||||||
|
for i := range in {
|
||||||
|
out[i] = fn(out[i])
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
18
utils/lamda_test.go
Normal file
18
utils/lamda_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMap(t *testing.T) {
|
||||||
|
ints := []int{1, 2, 3, 4}
|
||||||
|
ints = Map(ints, func(i int) int { return i * 10 })
|
||||||
|
assert.EqualValues(t, []int{10, 20, 30, 40}, ints)
|
||||||
|
|
||||||
|
sl := []string{"a ", "b", " c"}
|
||||||
|
sl = Map(sl, func(s string) string { return "#" + strings.TrimSpace(s) })
|
||||||
|
assert.EqualValues(t, []string{"#a", "#b", "#c"}, sl)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user