Compare commits
10 Commits
38b9f475bb
...
8d04efc34a
Author | SHA1 | Date | |
---|---|---|---|
8d04efc34a | |||
b34ee789bc | |||
|
0f0aba7f82 | ||
|
c35b2e1ae9 | ||
|
051ea11a5c | ||
|
37718ded77 | ||
|
a5ea4573b0 | ||
|
2a8de61424 | ||
|
33b6eb4faa | ||
|
ee3adee4d4 |
@ -1,9 +1,13 @@
|
|||||||
variables:
|
variables:
|
||||||
- &platforms 'linux/amd64,linux/arm64'
|
- &golang 'golang:1.20'
|
||||||
- &golang 'golang:1.18'
|
|
||||||
- &build_plugin 'woodpeckerci/plugin-docker-buildx:2'
|
- &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:
|
vendor:
|
||||||
image: *golang
|
image: *golang
|
||||||
commands: go mod vendor
|
commands: go mod vendor
|
||||||
@ -16,9 +20,8 @@ pipeline:
|
|||||||
image: *build_plugin
|
image: *build_plugin
|
||||||
pull: true
|
pull: true
|
||||||
settings:
|
settings:
|
||||||
platforms: *platforms
|
<<: *base_buildx_settings
|
||||||
repo: woodpeckerci/plugin-docker-buildx
|
repo: test
|
||||||
dockerfile: Dockerfile.multiarch
|
|
||||||
dry_run: true
|
dry_run: true
|
||||||
when:
|
when:
|
||||||
event: pull_request
|
event: pull_request
|
||||||
@ -27,19 +30,10 @@ pipeline:
|
|||||||
publish:
|
publish:
|
||||||
image: *build_plugin
|
image: *build_plugin
|
||||||
settings:
|
settings:
|
||||||
platforms: *platforms
|
<<: *base_buildx_settings
|
||||||
repo: woodpeckerci/plugin-docker-buildx,codeberg.org/woodpecker-plugins/docker-buildx
|
|
||||||
auto_tag: true
|
|
||||||
dockerfile: Dockerfile.multiarch
|
|
||||||
logins:
|
logins:
|
||||||
# Default DockerHub login
|
|
||||||
- registry: https://index.docker.io/v1/
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
# Additional Codeberg login
|
# Additional Codeberg login
|
||||||
- registry: https://codeberg.org
|
- registry: https://git.polynom.me
|
||||||
username:
|
username:
|
||||||
from_secret: cb_username
|
from_secret: cb_username
|
||||||
password:
|
password:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
ARG BUILDX_VERSION=0.9.1
|
ARG BUILDX_VERSION=0.11.0
|
||||||
ARG DOCKER_VERSION=20.10-dind
|
ARG DOCKER_VERSION=20.10-dind
|
||||||
ARG GOLANG_VERSION=1.18
|
ARG GOLANG_VERSION=1.20
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION} as build
|
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION} as build
|
||||||
|
|
||||||
|
@ -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">
|
<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
|
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)).
|
||||||
|
|
||||||
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).
|
|
||||||
|
|
||||||
## 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"},
|
||||||
@ -153,11 +159,11 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
|||||||
Value: true,
|
Value: true,
|
||||||
Destination: &settings.Build.LabelsAuto,
|
Destination: &settings.Build.LabelsAuto,
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringFlag{
|
||||||
Name: "args",
|
Name: "args",
|
||||||
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
||||||
Usage: "sets custom build arguments for the build",
|
Usage: "sets custom build arguments for the build. Must be a JSON string",
|
||||||
Destination: &settings.Build.Args,
|
Destination: &settings.Build.ArgsRaw,
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "args-from-env",
|
Name: "args-from-env",
|
||||||
|
@ -20,6 +20,10 @@ func main() {
|
|||||||
godotenv.Overload("/run/drone/env")
|
godotenv.Overload("/run/drone/env")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
|
||||||
|
godotenv.Overload(envFile)
|
||||||
|
}
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "docker-buildx",
|
Name: "docker-buildx",
|
||||||
Usage: "build docker container with DinD and buildx",
|
Usage: "build docker container with DinD and buildx",
|
||||||
|
14
docs.md
14
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 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
|
## 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
|
||||||
@ -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
|
| `add_host` | *none* | sets additional host:ip mapping
|
||||||
| `output` | *none* | sets build output in format `type=<type>[,<key>=<value>]`
|
| `output` | *none* | sets build output in format `type=<type>[,<key>=<value>]`
|
||||||
| `logins` | *none* | option to log into multiple registries
|
| `logins` | *none* | option to log into multiple registries
|
||||||
|
| `env_file` | *none* | load env vars from specified file
|
||||||
|
|
||||||
## Multi registry push example
|
## Multi registry push example
|
||||||
|
|
||||||
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
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module codeberg.org/woodpecker-plugins/plugin-docker-buildx
|
module codeberg.org/woodpecker-plugins/plugin-docker-buildx
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
codeberg.org/6543/go-yaml2json v0.3.0
|
codeberg.org/6543/go-yaml2json v0.3.0
|
||||||
|
@ -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,9 +54,11 @@ 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
|
||||||
|
ArgsRaw string // Docker build args (as JSON)
|
||||||
Args cli.StringSlice // Docker build args
|
Args cli.StringSlice // Docker build args
|
||||||
ArgsEnv cli.StringSlice // Docker build args from env
|
ArgsEnv cli.StringSlice // Docker build args from env
|
||||||
Target string // Docker build target
|
Target string // Docker build target
|
||||||
@ -84,6 +88,26 @@ func (l Login) anonymous() bool {
|
|||||||
return l.Username == "" || l.Password == ""
|
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
|
// Init initialise plugin settings
|
||||||
func (p *Plugin) InitSettings() error {
|
func (p *Plugin) InitSettings() error {
|
||||||
if p.settings.LoginsRaw != "" {
|
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 {
|
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(
|
||||||
@ -208,6 +248,8 @@ func (p *Plugin) writeBuildkitConfig() error {
|
|||||||
|
|
||||||
// Execute provides the implementation of the plugin.
|
// Execute provides the implementation of the plugin.
|
||||||
func (p *Plugin) Execute() error {
|
func (p *Plugin) Execute() error {
|
||||||
|
p.settings.Build.BuildArgs()
|
||||||
|
|
||||||
// start the Docker daemon server
|
// start the Docker daemon server
|
||||||
if !p.settings.Daemon.Disabled {
|
if !p.settings.Daemon.Disabled {
|
||||||
// If no custom DNS value set start internal DNS server
|
// If no custom DNS value set start internal DNS server
|
||||||
|
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