Compare commits

...

10 Commits

Author SHA1 Message Date
8d04efc34a Push to my registry
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
2023-10-08 16:02:56 +02:00
b34ee789bc Allow using key-value data 2023-10-08 16:01:53 +02:00
qwerty287
0f0aba7f82 Allow to load env file (#80)
closes https://codeberg.org/woodpecker-plugins/docker-buildx/issues/34

Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/80
Reviewed-by: anbraten <anbraten@noreply.codeberg.org>
Co-authored-by: qwerty287 <ndev@web.de>
Co-committed-by: qwerty287 <ndev@web.de>
2023-10-08 08:49:51 +00:00
6543
c35b2e1ae9
update pipeline to meet v1.0.0 standard 2023-07-31 04:36:36 +02:00
Lauris BH
051ea11a5c bump buildx to v0.11.0 (#66)
- use buildx [v0.11.0](https://github.com/docker/buildx/releases/tag/v0.11.0)

Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/66
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lafriks@noreply.codeberg.org>
Co-committed-by: Lauris BH <lafriks@noreply.codeberg.org>
2023-06-27 13:57:45 +00:00
6543
37718ded77 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>
2023-05-02 19:25:49 +00:00
6543
a5ea4573b0 CI: use new yaml syntax (#61)
Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/61
2023-04-30 13:21:32 +00:00
6543
2a8de61424 Fix link to "full documentation" 2023-04-29 14:40:01 +00:00
6543
33b6eb4faa bump buildx and golang (#58)
- use golang v1.20
- use buildx v0.10.4
  (to have buildkit v0.11.2)

Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/58
Reviewed-by: Lauris BH <lafriks@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Co-committed-by: 6543 <6543@obermui.de>
2023-03-22 15:26:29 +00:00
jolheiser
ee3adee4d4 Fix README wording (#57)
Removes a redundant sentence and some duplicated text.

Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/57
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: jolheiser <jolheiser@noreply.codeberg.org>
Co-committed-by: jolheiser <jolheiser@noreply.codeberg.org>
2023-03-19 01:27:00 +00:00
10 changed files with 105 additions and 32 deletions

View File

@ -1,9 +1,13 @@
variables:
- &platforms 'linux/amd64,linux/arm64'
- &golang 'golang:1.18'
- &golang 'golang:1.20'
- &build_plugin 'woodpeckerci/plugin-docker-buildx:2'
- base_settings: &base_buildx_settings
platforms: 'linux/amd64,linux/arm64'
dockerfile: Dockerfile.multiarch
auto_tag: true
repo: git.polynom.me/papatutuwawa/docker-buildx
pipeline:
steps:
vendor:
image: *golang
commands: go mod vendor
@ -16,9 +20,8 @@ pipeline:
image: *build_plugin
pull: true
settings:
platforms: *platforms
repo: woodpeckerci/plugin-docker-buildx
dockerfile: Dockerfile.multiarch
<<: *base_buildx_settings
repo: test
dry_run: true
when:
event: pull_request
@ -27,19 +30,10 @@ pipeline:
publish:
image: *build_plugin
settings:
platforms: *platforms
repo: woodpeckerci/plugin-docker-buildx,codeberg.org/woodpecker-plugins/docker-buildx
auto_tag: true
dockerfile: Dockerfile.multiarch
<<: *base_buildx_settings
logins:
# Default DockerHub login
- registry: https://index.docker.io/v1/
username:
from_secret: docker_username
password:
from_secret: docker_password
# Additional Codeberg login
- registry: https://codeberg.org
- registry: https://git.polynom.me
username:
from_secret: cb_username
password:

View File

@ -1,6 +1,6 @@
ARG BUILDX_VERSION=0.9.1
ARG BUILDX_VERSION=0.11.0
ARG DOCKER_VERSION=20.10-dind
ARG GOLANG_VERSION=1.18
ARG GOLANG_VERSION=1.20
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION} as build

View File

@ -4,9 +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">
</a>
Woodpecker CI plugin to build multiarch Docker images with 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 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

View File

@ -121,6 +121,12 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
FilePath: ".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{
Name: "tags.auto",
EnvVars: []string{"PLUGIN_AUTO_TAG"},
@ -153,11 +159,11 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
Value: true,
Destination: &settings.Build.LabelsAuto,
},
&cli.StringSliceFlag{
&cli.StringFlag{
Name: "args",
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
Usage: "sets custom build arguments for the build",
Destination: &settings.Build.Args,
Usage: "sets custom build arguments for the build. Must be a JSON string",
Destination: &settings.Build.ArgsRaw,
},
&cli.StringSliceFlag{
Name: "args-from-env",

View File

@ -20,6 +20,10 @@ func main() {
godotenv.Overload("/run/drone/env")
}
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
godotenv.Overload(envFile)
}
app := &cli.App{
Name: "docker-buildx",
Usage: "build docker container with DinD and buildx",

14
docs.md
View File

@ -9,7 +9,7 @@ containerImageUrl: https://hub.docker.com/r/woodpeckerci/plugin-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 You can find the full documentation at [woodpecker-plugins.codeberg.page](https://woodpecker-plugins.codeberg.page/plugins/drone-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).
## Features
@ -37,7 +37,7 @@ It will automatically generate buildkit configuration to use custom CA certifica
| `email` | *none* | sets email address to authenticates with
| `registry` | `https://index.docker.io/v1/` | sets docker registry to authenticate with
| `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
## auto_tag
@ -48,7 +48,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
## Examples
```yml
```yaml
publish-next-agent:
image: woodpeckerci/plugin-docker-buildx
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
```
```yml
```yaml
publish:
image: woodpeckerci/plugin-docker-buildx
settings:
@ -75,7 +75,7 @@ If it's not a tag event, and no default branch, automated tags are skipped.
from_secret: cb_token
```
```yml
```yaml
docker-build:
image: woodpeckerci/plugin-docker-buildx
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
| `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)
| `tags_file` | *none* | overwrites `tags` option with values find in specified file
| `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
| `default_suffix"`/`auto_tag_suffix`| *none* | generates tag names with the given suffix
@ -121,12 +122,13 @@ If it's not a tag event, and no default branch, automated tags are skipped.
| `add_host` | *none* | sets additional host:ip mapping
| `output` | *none* | sets build output in format `type=<type>[,<key>=<value>]`
| `logins` | *none* | option to log into multiple registries
| `env_file` | *none* | load env vars from specified file
## Multi registry push example
Only supported with `woodpecker >= 1.0.0` (next-da997fa3).
```yml
```yaml
settings:
repo: a6543/tmp,codeberg.org/6543/tmp
tag: demo

2
go.mod
View File

@ -1,6 +1,6 @@
module codeberg.org/woodpecker-plugins/plugin-docker-buildx
go 1.18
go 1.20
require (
codeberg.org/6543/go-yaml2json v0.3.0

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,9 +54,11 @@ 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
ArgsRaw string // Docker build args (as JSON)
Args cli.StringSlice // Docker build args
ArgsEnv cli.StringSlice // Docker build args from env
Target string // Docker build target
@ -84,6 +88,26 @@ func (l Login) anonymous() bool {
return l.Username == "" || l.Password == ""
}
// Parse the provided build args into b.Args
func (b Build) BuildArgs() {
if len(b.ArgsRaw) > 0 {
buildArgsRaw := map[string]string{}
err := json.Unmarshal([]byte(b.ArgsRaw), &buildArgsRaw)
if err != nil {
fmt.Printf("Failed to parse build args: %s", err)
}
for key, value := range buildArgsRaw {
b.Args = *cli.NewStringSlice(
append(
b.Args.Value(),
fmt.Sprintf("%s=%s", key, value),
)...,
)
}
}
}
// Init initialise plugin settings
func (p *Plugin) InitSettings() error {
if p.settings.LoginsRaw != "" {
@ -123,6 +147,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(
@ -208,6 +248,8 @@ func (p *Plugin) writeBuildkitConfig() error {
// Execute provides the implementation of the plugin.
func (p *Plugin) Execute() error {
p.settings.Build.BuildArgs()
// start the Docker daemon server
if !p.settings.Daemon.Disabled {
// If no custom DNS value set start internal DNS server

9
utils/lamda.go Normal file
View 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
View 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)
}