0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-06-02 18:29:42 +02:00

Compare commits

...

38 Commits
v4.0.0 ... main

Author SHA1 Message Date
renovate[bot]
7bf14e3635 chore(docker): update docker:26.1-dind docker digest to 76ba10a 2024-05-31 03:17:59 +00:00
renovate[bot]
02bf2bc68d chore(deps): update dependency golangci/golangci-lint to v1.59.0 2024-05-27 03:09:30 +00:00
renovate[bot]
36018940e1
chore(deps): update dependency docker/buildx to v0.14.1 (#185)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-24 09:41:45 +02:00
renovate[bot]
258dbbe73f
fix(deps): update module github.com/rs/zerolog to v1.33.0 (#186)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-24 09:36:43 +02:00
renovate[bot]
311240e69d chore(docker): update docker:26.1-dind docker digest to a811114 2024-05-24 03:43:21 +00:00
renovate[bot]
03feac0b30 chore(deps): update dependency golangci/golangci-lint to v1.58.2 2024-05-20 09:31:10 +00:00
renovate[bot]
527d6b8428 chore(docker): update docker digests 2024-05-18 06:11:29 +00:00
51889e1102
chore: migrate to wp-plugin-go v3 (#181) 2024-05-17 21:55:16 +02:00
renovate[bot]
8761da6871 chore(docker): update docker.io/library/golang:1.22 docker digest to ab48cd7 2024-05-15 23:08:21 +00:00
renovate[bot]
053ab0fb69 chore(deps): update dependency golangci/golangci-lint to v1.58.1 2024-05-13 03:20:29 +00:00
37147a6a90
ci: fix golangci-lint deprecations 2024-05-12 11:08:24 +02:00
renovate[bot]
26460f0c9f chore(docker): update docker:26.1-dind docker digest to c890c32 2024-05-10 10:27:29 +00:00
renovate[bot]
d5f2c72a18 chore(docker): update docker.io/library/golang:1.22 docker digest to b1e05e2 2024-05-08 03:12:39 +00:00
6964a133e8
fix: check is cmd is nil before execution (#176) 2024-05-07 11:57:26 +02:00
6087e0e1e4
cleanup import 2024-05-06 21:26:56 +02:00
757d2804ea
refactor: switch to plugin Cmd and add tests (#175) 2024-05-06 20:29:51 +02:00
renovate[bot]
3e74ff0c22 chore(deps): update dependency golangci/golangci-lint to v1.58.0 2024-05-06 04:23:30 +00:00
renovate[bot]
6c91855a4d
fix(deps): update module golang.org/x/sys to v0.20.0 (#171)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-05 13:03:59 +02:00
77beefbc24
docs: hide system flags and refactor generator (#169) 2024-05-05 13:03:50 +02:00
renovate[bot]
43c2e2074c chore(docker): update docker:26.1-dind docker digest to 56e2c52 2024-05-03 03:51:41 +00:00
renovate[bot]
0e549d8232
fix(deps): update module github.com/urfave/cli/v2 to v2.27.2 (#166)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-29 10:27:28 +02:00
renovate[bot]
2e429e38e4 chore(docker): update docker:26.1-dind docker digest to 66183ea 2024-04-27 04:45:16 +00:00
renovate[bot]
bee53eb3bb chore(docker): update docker:26.1-dind docker digest to 308c63f 2024-04-26 04:32:39 +00:00
renovate[bot]
6b9393a6e9
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v4.0.2 (#163)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-25 13:17:48 +02:00
renovate[bot]
37476ba4cc chore(docker): update docker.io/library/golang:1.22 docker digest to d5302d4 2024-04-25 03:50:53 +00:00
renovate[bot]
46cfd69d5f
chore(deps): update docker docker tag to v26.1 (#161)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-24 09:23:50 +02:00
renovate[bot]
b8749c1199
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v4.0.1 (#160)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 20:46:26 +02:00
renovate[bot]
9ed4065964
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.7.1 (#159)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 12:38:35 +02:00
renovate[bot]
fe25250ffb chore(docker): update docker:26.0-dind docker digest to c8d3a4b 2024-04-21 03:42:04 +00:00
renovate[bot]
c2804f8b28
chore(deps): update dependency docker/buildx to v0.14.0 (#156)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-20 14:21:42 +02:00
renovate[bot]
9d102b7cfd chore(docker): update docker:26.0-dind docker digest to 12b3a58 2024-04-19 03:36:01 +00:00
renovate[bot]
c033c7f497 chore(docker): update docker:26.0-dind docker digest to a2d55c6 2024-04-13 03:13:32 +00:00
renovate[bot]
6f2836570d chore(docker): update docker.io/library/golang:1.22 docker digest to 450e382 2024-04-11 08:52:29 +00:00
renovate[bot]
227a4275de
fix(deps): update module golang.org/x/sys to v0.19.0 (#153)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-05 08:55:17 +02:00
renovate[bot]
93fd442469 chore(docker): update docker.io/library/golang:1.22 docker digest to c4fb952 2024-04-04 03:12:40 +00:00
renovate[bot]
c55260ce5f chore(docker): update docker:26.0-dind docker digest to 7ff986c 2024-04-03 03:42:44 +00:00
renovate[bot]
013cd7453f chore(deps): update dependency golangci/golangci-lint to v1.57.2 2024-04-01 04:02:36 +00:00
renovate[bot]
d4de895786
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v4 (#149)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-27 08:43:04 +01:00
23 changed files with 918 additions and 952 deletions

View File

@ -23,7 +23,6 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forcetypeassert
@ -37,12 +36,12 @@ linters:
- gocyclo
- godot
- godox
- goerr113
- err113
- gofmt
- gofumpt
- goheader
- goimports
- gomnd
- mnd
- gomoddirectives
- gomodguard
- goprintffuncname

View File

@ -7,7 +7,7 @@ when:
steps:
- name: dryrun
image: quay.io/thegeeklab/wp-docker-buildx:3.0.1
image: quay.io/thegeeklab/wp-docker-buildx:4.0.2
settings:
containerfile: Containerfile.multiarch
dry_run: true
@ -20,7 +20,7 @@ steps:
- event: [pull_request]
- name: publish-dockerhub
image: quay.io/thegeeklab/wp-docker-buildx:3.0.1
image: quay.io/thegeeklab/wp-docker-buildx:4.0.2
group: container
settings:
auto_tag: true
@ -41,7 +41,7 @@ steps:
- ${CI_REPO_DEFAULT_BRANCH}
- name: publish-quay
image: quay.io/thegeeklab/wp-docker-buildx:3.0.1
image: quay.io/thegeeklab/wp-docker-buildx:4.0.2
group: container
settings:
auto_tag: true

View File

@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.22@sha256:0b55ab82ac2a54a6f8f85ec8b943b9e470c39e32c109b766bbc1b801f3fa8d3b as build
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.22@sha256:f43c6f049f04cbbaeb28f0aad3eea15274a7d0a7899a617d0037aec48d7ab010 as build
ARG TARGETOS
ARG TARGETARCH
@ -8,7 +8,7 @@ WORKDIR /src
RUN make build
FROM docker:26.0-dind@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
FROM docker:26.1-dind@sha256:76ba10a4aed708c7b2db09d45740d711edf707f7368f6808bd32a53eaed33404
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
@ -22,7 +22,7 @@ ARG TARGETARCH
ARG BUILDX_VERSION
# renovate: datasource=github-releases depName=docker/buildx
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.13.1}"
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.14.1}"
ENV DOCKER_HOST=unix:///var/run/docker.sock

View File

@ -1,7 +1,7 @@
# renovate: datasource=github-releases depName=mvdan/gofumpt
GOFUMPT_PACKAGE_VERSION := v0.6.0
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_PACKAGE_VERSION := v1.57.1
GOLANGCI_LINT_PACKAGE_VERSION := v1.59.0
EXECUTABLE := wp-docker-buildx
@ -19,7 +19,6 @@ GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(G
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
GENERATE ?=
XGO_VERSION := go-1.22.x
XGO_TARGETS ?= linux/amd64,linux/arm64
@ -28,7 +27,7 @@ TARGETARCH ?= amd64
ifneq ("$(TARGETVARIANT)","")
GOARM ?= $(subst v,,$(TARGETVARIANT))
endif
TAGS ?= netgo
TAGS ?= netgo,osusergo
ifndef VERSION
ifneq ($(CI_COMMIT_TAG),)
@ -65,11 +64,7 @@ lint: golangci-lint
.PHONY: generate
generate:
$(GO) generate $(GENERATE)
.PHONY: generate-docs
generate-docs:
$(GO) generate ./cmd/$(EXECUTABLE)/flags.go
$(GO) generate $(PACKAGES)
.PHONY: test
test:

View File

@ -1,58 +0,0 @@
//go:build generate
// +build generate
package main
import (
"bytes"
"embed"
"fmt"
"os"
"text/template"
"github.com/thegeeklab/wp-docker-buildx/plugin"
"github.com/thegeeklab/wp-plugin-go/docs"
wp "github.com/thegeeklab/wp-plugin-go/plugin"
wp_template "github.com/thegeeklab/wp-plugin-go/template"
"github.com/urfave/cli/v2"
)
//go:embed templates/docs-data.yaml.tmpl
var yamlTemplate embed.FS
func main() {
settings := &plugin.Settings{}
app := &cli.App{
Flags: settingsFlags(settings, wp.FlagsPluginCategory),
}
out, err := toYAML(app)
if err != nil {
panic(err)
}
fi, err := os.Create("../../docs/data/data-raw.yaml")
if err != nil {
panic(err)
}
defer fi.Close()
if _, err := fi.WriteString(out); err != nil {
panic(err)
}
}
func toYAML(app *cli.App) (string, error) {
var w bytes.Buffer
yamlTmpl, err := template.New("docs").Funcs(wp_template.LoadFuncMap()).ParseFS(yamlTemplate, "templates/docs-data.yaml.tmpl")
if err != nil {
fmt.Println(yamlTmpl)
return "", err
}
if err := yamlTmpl.ExecuteTemplate(&w, "docs-data.yaml.tmpl", docs.GetTemplateData(app)); err != nil {
return "", err
}
return w.String(), nil
}

View File

@ -1,345 +0,0 @@
package main
import (
"github.com/thegeeklab/wp-docker-buildx/plugin"
"github.com/thegeeklab/wp-plugin-go/types"
"github.com/urfave/cli/v2"
)
// settingsFlags has the cli.Flags for the plugin.Settings.
//
//nolint:maintidx
//go:generate go run docs.go flags.go
func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "dry-run",
EnvVars: []string{"PLUGIN_DRY_RUN"},
Usage: "disable docker push",
Destination: &settings.Dryrun,
Category: category,
},
&cli.StringFlag{
Name: "daemon.mirror",
EnvVars: []string{"PLUGIN_MIRROR", "DOCKER_PLUGIN_MIRROR"},
Usage: "registry mirror to pull images",
Destination: &settings.Daemon.Mirror,
DefaultText: "$DOCKER_PLUGIN_MIRROR",
Category: category,
},
&cli.StringFlag{
Name: "daemon.storage-driver",
EnvVars: []string{"PLUGIN_STORAGE_DRIVER"},
Usage: "docker daemon storage driver",
Destination: &settings.Daemon.StorageDriver,
Category: category,
},
&cli.StringFlag{
Name: "daemon.storage-path",
EnvVars: []string{"PLUGIN_STORAGE_PATH"},
Usage: "docker daemon storage path",
Value: "/var/lib/docker",
Destination: &settings.Daemon.StoragePath,
Category: category,
},
&cli.StringFlag{
Name: "daemon.bip",
EnvVars: []string{"PLUGIN_BIP"},
Usage: "allow the docker daemon to bride IP address",
Destination: &settings.Daemon.Bip,
Category: category,
},
&cli.StringFlag{
Name: "daemon.mtu",
EnvVars: []string{"PLUGIN_MTU"},
Usage: "docker daemon custom MTU setting",
Destination: &settings.Daemon.MTU,
Category: category,
},
&cli.StringSliceFlag{
Name: "daemon.dns",
EnvVars: []string{"PLUGIN_CUSTOM_DNS"},
Usage: "custom docker daemon DNS server",
Destination: &settings.Daemon.DNS,
Category: category,
},
&cli.StringSliceFlag{
Name: "daemon.dns-search",
EnvVars: []string{"PLUGIN_CUSTOM_DNS_SEARCH"},
Usage: "custom docker daemon DNS search domain",
Destination: &settings.Daemon.DNSSearch,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.insecure",
EnvVars: []string{"PLUGIN_INSECURE"},
Usage: "allow the docker daemon to use insecure registries",
Value: false,
Destination: &settings.Daemon.Insecure,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.ipv6",
EnvVars: []string{"PLUGIN_IPV6"},
Usage: "enable docker daemon IPv6 support",
Value: false,
Destination: &settings.Daemon.IPv6,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.experimental",
EnvVars: []string{"PLUGIN_EXPERIMENTAL"},
Usage: "enable docker daemon experimental mode",
Value: false,
Destination: &settings.Daemon.Experimental,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.debug",
EnvVars: []string{"PLUGIN_DEBUG"},
Usage: "enable verbose debug mode for the docker daemon",
Value: false,
Destination: &settings.Daemon.Debug,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.off",
EnvVars: []string{"PLUGIN_DAEMON_OFF"},
Usage: "disable the startup of the docker daemon",
Value: false,
Destination: &settings.Daemon.Disabled,
Category: category,
},
&cli.StringFlag{
Name: "daemon.buildkit-config",
EnvVars: []string{"PLUGIN_BUILDKIT_CONFIG"},
Usage: "content of the docker buildkit toml config",
Destination: &settings.Daemon.BuildkitConfig,
Category: category,
},
&cli.StringFlag{
Name: "daemon.max-concurrent-uploads",
EnvVars: []string{"PLUGIN_MAX_CONCURRENT_UPLOADS"},
Usage: "max concurrent uploads for each push",
Destination: &settings.Daemon.MaxConcurrentUploads,
Category: category,
},
&cli.StringFlag{
Name: "containerfile",
EnvVars: []string{"PLUGIN_CONTAINERFILE"},
Usage: "containerfile to use for the image build",
Value: "Containerfile",
Destination: &settings.Build.Containerfile,
Category: category,
},
&cli.StringFlag{
Name: "context",
EnvVars: []string{"PLUGIN_CONTEXT"},
Usage: "path of the build context",
Value: ".",
Destination: &settings.Build.Context,
Category: category,
},
&cli.StringSliceFlag{
Name: "named-context",
EnvVars: []string{"PLUGIN_NAMED_CONTEXT"},
Usage: "additional named build context",
Destination: &settings.Build.NamedContext,
Category: category,
},
&cli.StringSliceFlag{
Name: "tags",
EnvVars: []string{"PLUGIN_TAGS", "PLUGIN_TAG"},
Usage: "repository tags to use for the image",
FilePath: ".tags",
Destination: &settings.Build.Tags,
Category: category,
},
&cli.BoolFlag{
Name: "tags.auto",
EnvVars: []string{"PLUGIN_AUTO_TAG", "PLUGIN_DEFAULT_TAGS"},
Usage: "generate tag names automatically based on git branch and git tag",
Value: false,
Destination: &settings.Build.TagsAuto,
Category: category,
},
&cli.StringFlag{
Name: "tags.suffix",
EnvVars: []string{"PLUGIN_AUTO_TAG_SUFFIX", "PLUGIN_DEFAULT_SUFFIX"},
Usage: "generate tag names with the given suffix",
Destination: &settings.Build.TagsSuffix,
Category: category,
},
&cli.StringSliceFlag{
Name: "extra.tags",
EnvVars: []string{"PLUGIN_EXTRA_TAGS"},
Usage: "additional tags to use for the image including registry",
FilePath: ".extratags",
Destination: &settings.Build.ExtraTags,
Category: category,
},
&cli.StringSliceFlag{
Name: "args",
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
Usage: "custom build arguments for the build",
Destination: &settings.Build.Args,
Category: category,
},
&cli.StringSliceFlag{
Name: "args-from-env",
EnvVars: []string{"PLUGIN_BUILD_ARGS_FROM_ENV"},
Usage: "forward environment variables as custom arguments to the build",
Destination: &settings.Build.ArgsEnv,
Category: category,
},
&cli.BoolFlag{
Name: "quiet",
EnvVars: []string{"PLUGIN_QUIET"},
Usage: "enable suppression of the build output",
Value: false,
Destination: &settings.Build.Quiet,
Category: category,
},
&cli.StringFlag{
Name: "output",
EnvVars: []string{"PLUGIN_OUTPUT"},
Usage: "export action for the build result",
Destination: &settings.Build.Output,
Category: category,
},
&cli.StringFlag{
Name: "target",
EnvVars: []string{"PLUGIN_TARGET"},
Usage: "build target to use",
Destination: &settings.Build.Target,
Category: category,
},
&cli.GenericFlag{
Name: "cache-from",
EnvVars: []string{"PLUGIN_CACHE_FROM"},
Usage: "images to consider as cache sources",
Value: &types.StringSliceFlag{},
Category: category,
},
&cli.StringFlag{
Name: "cache-to",
EnvVars: []string{"PLUGIN_CACHE_TO"},
Usage: "cache destination for the build cache",
Destination: &settings.Build.CacheTo,
Category: category,
},
&cli.BoolFlag{
Name: "pull-image",
EnvVars: []string{"PLUGIN_PULL_IMAGE"},
Usage: "enforce to pull base image at build time",
Value: true,
Destination: &settings.Build.Pull,
Category: category,
},
&cli.BoolFlag{
Name: "compress",
EnvVars: []string{"PLUGIN_COMPRESS"},
Usage: "enable compression of the build context using gzip",
Value: false,
Destination: &settings.Build.Compress,
Category: category,
},
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"PLUGIN_REPO"},
Usage: "repository name for the image",
Destination: &settings.Build.Repo,
Category: category,
},
&cli.StringFlag{
Name: "docker.registry",
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
Usage: "docker registry to authenticate with",
Value: "https://index.docker.io/v1/",
Destination: &settings.Login.Registry,
Category: category,
},
&cli.StringFlag{
Name: "docker.username",
EnvVars: []string{"PLUGIN_USERNAME", "DOCKER_USERNAME"},
Usage: "username for registry authentication",
Destination: &settings.Login.Username,
DefaultText: "$DOCKER_USERNAME",
Category: category,
},
&cli.StringFlag{
Name: "docker.password",
EnvVars: []string{"PLUGIN_PASSWORD", "DOCKER_PASSWORD"},
Usage: "password for registry authentication",
Destination: &settings.Login.Password,
DefaultText: "$DOCKER_PASSWORD",
Category: category,
},
&cli.StringFlag{
Name: "docker.email",
EnvVars: []string{"PLUGIN_EMAIL", "DOCKER_EMAIL"},
Usage: "email address for registry authentication",
Destination: &settings.Login.Email,
DefaultText: "$DOCKER_EMAIL",
Category: category,
},
&cli.StringFlag{
Name: "docker.config",
EnvVars: []string{"PLUGIN_CONFIG", "DOCKER_PLUGIN_CONFIG"},
Usage: "content of the docker daemon json config",
Destination: &settings.Login.Config,
DefaultText: "$DOCKER_PLUGIN_CONFIG",
Category: category,
},
&cli.BoolFlag{
Name: "no-cache",
EnvVars: []string{"PLUGIN_NO_CACHE"},
Usage: "disable the usage of cached intermediate containers",
Value: false,
Destination: &settings.Build.NoCache,
Category: category,
},
&cli.StringSliceFlag{
Name: "add-host",
EnvVars: []string{"PLUGIN_ADD_HOST"},
Usage: "additional `host:ip` mapping",
Destination: &settings.Build.AddHost,
Category: category,
},
&cli.StringSliceFlag{
Name: "platforms",
EnvVars: []string{"PLUGIN_PLATFORMS"},
Usage: "target platform for build",
Destination: &settings.Build.Platforms,
Category: category,
},
&cli.StringSliceFlag{
Name: "labels",
EnvVars: []string{"PLUGIN_LABELS"},
Usage: "labels to add to image",
Destination: &settings.Build.Labels,
Category: category,
},
&cli.StringFlag{
Name: "provenance",
EnvVars: []string{"PLUGIN_PROVENANCE"},
Usage: "generates provenance attestation for the build",
Destination: &settings.Build.Provenance,
Category: category,
},
&cli.StringFlag{
Name: "sbom",
EnvVars: []string{"PLUGIN_SBOM"},
Usage: "generates SBOM attestation for the build",
Destination: &settings.Build.SBOM,
Category: category,
},
&cli.GenericFlag{
Name: "secrets",
EnvVars: []string{"PLUGIN_SECRETS"},
Usage: "exposes secrets to the build",
Value: &types.StringSliceFlag{},
Category: category,
},
}
}

View File

@ -1,11 +1,7 @@
package main
import (
"fmt"
"github.com/thegeeklab/wp-docker-buildx/plugin"
wp "github.com/thegeeklab/wp-plugin-go/plugin"
)
//nolint:gochecknoglobals
@ -15,14 +11,5 @@ var (
)
func main() {
settings := &plugin.Settings{}
options := wp.Options{
Name: "wp-docker-buildx",
Description: "Build multiarch OCI images with buildx",
Version: BuildVersion,
VersionMetadata: fmt.Sprintf("date=%s", BuildDate),
Flags: settingsFlags(settings, wp.FlagsPluginCategory),
}
plugin.New(options, settings).Run()
plugin.New(nil, BuildVersion, BuildDate).Run()
}

View File

@ -1,18 +0,0 @@
---
{{- if .GlobalArgs }}
properties:
{{- range $v := .GlobalArgs }}
- name: {{ $v.Name }}
{{- with $v.Description }}
description: |
{{ . | ToSentence }}
{{- end }}
{{- with $v.Type }}
type: {{ . }}
{{- end }}
{{- with $v.Default }}
defaultValue: {{ . }}
{{- end }}
required: {{ default false $v.Required }}
{{ end -}}
{{ end -}}

123
docker/daemon.go Normal file
View File

@ -0,0 +1,123 @@
package docker
import (
"os"
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
"github.com/urfave/cli/v2"
)
const dockerdBin = "/usr/local/bin/dockerd"
// Daemon defines Docker daemon parameters.
type Daemon struct {
Registry string // Docker registry
Mirror string // Docker registry mirror
Insecure bool // Docker daemon enable insecure registries
StorageDriver string // Docker daemon storage driver
StoragePath string // Docker daemon storage path
Disabled bool // DOcker daemon is disabled (already running)
Debug bool // Docker daemon started in debug mode
Bip string // Docker daemon network bridge IP address
DNS cli.StringSlice // Docker daemon dns server
DNSSearch cli.StringSlice // Docker daemon dns search domain
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
BuildkitConfigFile string // Docker buildkit config file
MaxConcurrentUploads string // Docker daemon max concurrent uploads
}
// helper function to create the docker daemon command.
func (d *Daemon) Start() *plugin_exec.Cmd {
args := []string{
"--data-root", d.StoragePath,
"--host=unix:///var/run/docker.sock",
}
if d.StorageDriver != "" {
args = append(args, "-s", d.StorageDriver)
}
if d.Insecure && d.Registry != "" {
args = append(args, "--insecure-registry", d.Registry)
}
if d.IPv6 {
args = append(args, "--ipv6")
}
if d.Mirror != "" {
args = append(args, "--registry-mirror", d.Mirror)
}
if d.Bip != "" {
args = append(args, "--bip", d.Bip)
}
for _, dns := range d.DNS.Value() {
args = append(args, "--dns", dns)
}
for _, dnsSearch := range d.DNSSearch.Value() {
args = append(args, "--dns-search", dnsSearch)
}
if d.MTU != "" {
args = append(args, "--mtu", d.MTU)
}
if d.Experimental {
args = append(args, "--experimental")
}
if d.MaxConcurrentUploads != "" {
args = append(args, "--max-concurrent-uploads", d.MaxConcurrentUploads)
}
cmd := plugin_exec.Command(dockerdBin, args...)
if d.Debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
return cmd
}
func (d *Daemon) CreateBuilder() *plugin_exec.Cmd {
args := []string{
"buildx",
"create",
"--use",
}
if d.BuildkitConfigFile != "" {
args = append(args, "--config", d.BuildkitConfigFile)
}
cmd := plugin_exec.Command(dockerBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
func (d *Daemon) ListBuilder() *plugin_exec.Cmd {
cmd := plugin_exec.Command(dockerBin, "buildx", "ls")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
func (d *Daemon) StartCoreDNS() *plugin_exec.Cmd {
cmd := plugin_exec.Command("coredns", "-conf", "/etc/coredns/Corefile")
if d.Debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
return cmd
}

236
docker/docker.go Normal file
View File

@ -0,0 +1,236 @@
package docker
import (
"fmt"
"os"
"strings"
"time"
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
"github.com/urfave/cli/v2"
)
const dockerBin = "/usr/local/bin/docker"
// Login defines Docker login parameters.
type Registry struct {
Address string // Docker registry address
Username string // Docker registry username
Password string // Docker registry password
Email string // Docker registry email
Config string // Docker Auth Config
}
// Build defines Docker build parameters.
type Build struct {
Ref string // Git commit ref
Branch string // Git repository branch
Containerfile string // Docker build Containerfile
Context string // Docker build context
TagsAuto bool // Docker build auto tag
TagsSuffix string // Docker build tags with suffix
Tags cli.StringSlice // Docker build tags
ExtraTags cli.StringSlice // Docker build tags including registry
Platforms cli.StringSlice // Docker build target platforms
Args cli.StringSlice // Docker build args
ArgsEnv cli.StringSlice // Docker build args from env
Target string // Docker build target
Pull bool // Docker build pull
CacheFrom []string // Docker build cache-from
CacheTo string // Docker build cache-to
Compress bool // Docker build compress
Repo string // Docker build repository
NoCache bool // Docker build no-cache
AddHost cli.StringSlice // Docker build add-host
Quiet bool // Docker build quiet
Output string // Docker build output folder
NamedContext cli.StringSlice // Docker build named context
Labels cli.StringSlice // Docker build labels
Provenance string // Docker build provenance attestation
SBOM string // Docker build sbom attestation
Secrets []string // Docker build secrets
Dryrun bool // Docker build dryrun
}
// helper function to create the docker login command.
func (r *Registry) Login() *plugin_exec.Cmd {
args := []string{
"login",
"-u", r.Username,
"-p", r.Password,
}
if r.Email != "" {
args = append(args, "-e", r.Email)
}
args = append(args, r.Address)
cmd := plugin_exec.Command(dockerBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
// helper function to create the docker info command.
func Version() *plugin_exec.Cmd {
cmd := plugin_exec.Command(dockerBin, "version")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
// helper function to create the docker info command.
func Info() *plugin_exec.Cmd {
cmd := plugin_exec.Command(dockerBin, "info")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
// helper function to create the docker build command.
func (b *Build) Run() *plugin_exec.Cmd {
args := []string{
"buildx",
"build",
"--rm=true",
"-f", b.Containerfile,
}
defaultBuildArgs := []string{
fmt.Sprintf("DOCKER_IMAGE_CREATED=%s", time.Now().Format(time.RFC3339)),
}
args = append(args, b.Context)
if !b.Dryrun && b.Output == "" && len(b.Tags.Value()) > 0 {
args = append(args, "--push")
}
if b.Compress {
args = append(args, "--compress")
}
if b.Pull {
args = append(args, "--pull=true")
}
if b.NoCache {
args = append(args, "--no-cache")
}
for _, arg := range b.CacheFrom {
args = append(args, "--cache-from", arg)
}
if b.CacheTo != "" {
args = append(args, "--cache-to", b.CacheTo)
}
for _, arg := range b.ArgsEnv.Value() {
b.addProxyValue(arg)
}
for _, arg := range append(defaultBuildArgs, b.Args.Value()...) {
args = append(args, "--build-arg", arg)
}
for _, host := range b.AddHost.Value() {
args = append(args, "--add-host", host)
}
if b.Target != "" {
args = append(args, "--target", b.Target)
}
if b.Quiet {
args = append(args, "--quiet")
}
if b.Output != "" {
args = append(args, "--output", b.Output)
}
for _, arg := range b.NamedContext.Value() {
args = append(args, "--build-context", arg)
}
if len(b.Platforms.Value()) > 0 {
args = append(args, "--platform", strings.Join(b.Platforms.Value(), ","))
}
for _, arg := range b.Tags.Value() {
args = append(args, "-t", fmt.Sprintf("%s:%s", b.Repo, arg))
}
for _, arg := range b.ExtraTags.Value() {
args = append(args, "-t", arg)
}
for _, arg := range b.Labels.Value() {
args = append(args, "--label", arg)
}
if b.Provenance != "" {
args = append(args, "--provenance", b.Provenance)
}
if b.SBOM != "" {
args = append(args, "--sbom", b.SBOM)
}
for _, secret := range b.Secrets {
args = append(args, "--secret", secret)
}
cmd := plugin_exec.Command(dockerBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}
// helper function to add proxy values from the environment.
func (b *Build) AddProxyBuildArgs() {
b.addProxyValue("http_proxy")
b.addProxyValue("https_proxy")
b.addProxyValue("no_proxy")
}
// helper function to add the upper and lower case version of a proxy value.
func (b *Build) addProxyValue(key string) {
value := b.getProxyValue(key)
if len(value) > 0 && !b.hasProxyBuildArg(key) {
b.Args = *cli.NewStringSlice(append(b.Args.Value(), fmt.Sprintf("%s=%s", key, value))...)
b.Args = *cli.NewStringSlice(append(b.Args.Value(), fmt.Sprintf("%s=%s", strings.ToUpper(key), value))...)
}
}
// helper function to get a proxy value from the environment.
//
// assumes that the upper and lower case versions of are the same.
func (b *Build) getProxyValue(key string) string {
value := os.Getenv(key)
if len(value) > 0 {
return value
}
return os.Getenv(strings.ToUpper(key))
}
// helper function that looks to see if a proxy value was set in the build args.
func (b *Build) hasProxyBuildArg(key string) bool {
keyUpper := strings.ToUpper(key)
for _, s := range b.Args.Value() {
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) {
return true
}
}
return false
}

View File

@ -104,7 +104,7 @@ docker run --rm \
-e PLUGIN_TAG=latest \
-e PLUGIN_REPO=octocat/hello-world \
-e CI_COMMIT_SHA=00000000 \
-v $(pwd):/build:z \
-v $(pwd)/testdata:/build:z \
-w /build \
--privileged \
thegeeklab/wp-docker-buildx --dry-run

View File

@ -179,6 +179,13 @@ properties:
defaultValue: false
required: false
- name: insecure_skip_verify
description: |
Skip SSL verification.
type: bool
defaultValue: false
required: false
- name: ipv6
description: |
Enable docker daemon IPv6 support.
@ -192,6 +199,13 @@ properties:
type: list
required: false
- name: log_level
description: |
Plugin log level.
type: string
defaultValue: "info"
required: false
- name: max_concurrent_uploads
description: |
Max concurrent uploads for each push.

16
go.mod
View File

@ -4,17 +4,16 @@ go 1.22
require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/rs/zerolog v1.32.0
github.com/thegeeklab/wp-plugin-go v1.7.0
github.com/urfave/cli/v2 v2.27.1
golang.org/x/sys v0.18.0
github.com/rs/zerolog v1.33.0
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2
github.com/urfave/cli/v2 v2.27.2
)
require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect
@ -26,7 +25,8 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
)

32
go.sum
View File

@ -8,8 +8,8 @@ github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBa
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -35,8 +35,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
@ -48,25 +48,25 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/thegeeklab/wp-plugin-go v1.7.0 h1:YXE8WkFeoSqMhBR4WYMetlEzCp5cYwP6lZfrHH6rpIc=
github.com/thegeeklab/wp-plugin-go v1.7.0/go.mod h1:5ZCnuq/bOryxCfi9nsTPW6V+hw6L5uILVoU6OFy8E4U=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 h1:Mv5i8S1WY+BUNjTjX6lOnB3p8S9mvM+XwfY4R98gx0g=
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2/go.mod h1:ij1iJcAVgzerBTqXnmq0bu1VA+hhVVwzXKqiqfoGjjg=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -78,8 +78,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=

42
internal/docs/main.go Normal file
View File

@ -0,0 +1,42 @@
//go:build generate
// +build generate
package main
import (
"context"
"flag"
"net/http"
"os"
"time"
"github.com/thegeeklab/wp-docker-buildx/plugin"
plugin_docs "github.com/thegeeklab/wp-plugin-go/v3/docs"
plugin_template "github.com/thegeeklab/wp-plugin-go/v3/template"
)
func main() {
tmpl := "https://raw.githubusercontent.com/thegeeklab/woodpecker-plugins/main/templates/docs-data.yaml.tmpl"
client := http.Client{
Timeout: 30 * time.Second,
}
p := plugin.New(nil)
out, err := plugin_template.Render(context.Background(), client, tmpl, plugin_docs.GetTemplateData(p.App))
if err != nil {
panic(err)
}
outputFile := flag.String("output", "", "Output file path")
flag.Parse()
if *outputFile == "" {
panic("no output file specified")
}
err = os.WriteFile(*outputFile, []byte(out), 0o644)
if err != nil {
panic(err)
}
}

View File

@ -1,42 +0,0 @@
package plugin
import (
"io"
"net"
"os"
"os/exec"
"github.com/thegeeklab/wp-plugin-go/trace"
)
func (p Plugin) startCoredns() {
cmd := exec.Command("coredns", "-conf", "/etc/coredns/Corefile")
if p.Settings.Daemon.Debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
}
go func() {
trace.Cmd(cmd)
_ = cmd.Run()
}()
}
func getContainerIP() (string, error) {
netInterfaceAddrList, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, netInterfaceAddr := range netInterfaceAddrList {
netIP, ok := netInterfaceAddr.(*net.IPNet)
if ok && !netIP.IP.IsLoopback() && netIP.IP.To4() != nil {
return netIP.IP.String(), nil
}
}
return "", nil
}

View File

@ -1,31 +0,0 @@
package plugin
import (
"io"
"os"
"github.com/thegeeklab/wp-plugin-go/trace"
)
const (
dockerBin = "/usr/local/bin/docker"
dockerdBin = "/usr/local/bin/dockerd"
dockerHome = "/root/.docker/"
buildkitConfig = "/tmp/buildkit.toml"
)
func (p Plugin) startDaemon() {
cmd := commandDaemon(p.Settings.Daemon)
if p.Settings.Daemon.Debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdout = io.Discard
cmd.Stderr = io.Discard
}
go func() {
trace.Cmd(cmd)
_ = cmd.Run()
}()
}

View File

@ -1,261 +0,0 @@
package plugin
import (
"fmt"
"os"
"strings"
"time"
"github.com/urfave/cli/v2"
"golang.org/x/sys/execabs"
)
// helper function to create the docker login command.
func commandLogin(login Login) *execabs.Cmd {
if login.Email != "" {
return commandLoginEmail(login)
}
args := []string{
"login",
"-u", login.Username,
"-p", login.Password,
login.Registry,
}
return execabs.Command(
dockerBin, args...,
)
}
func commandLoginEmail(login Login) *execabs.Cmd {
args := []string{
"login",
"-u", login.Username,
"-p", login.Password,
"-e", login.Email,
login.Registry,
}
return execabs.Command(
dockerBin, args...,
)
}
// helper function to create the docker info command.
func commandVersion() *execabs.Cmd {
return execabs.Command(dockerBin, "version")
}
// helper function to create the docker info command.
func commandInfo() *execabs.Cmd {
return execabs.Command(dockerBin, "info")
}
func commandBuilder(daemon Daemon) *execabs.Cmd {
args := []string{
"buildx",
"create",
"--use",
}
if daemon.BuildkitConfig != "" {
args = append(args, "--config", buildkitConfig)
}
return execabs.Command(dockerBin, args...)
}
func commandBuildx() *execabs.Cmd {
return execabs.Command(dockerBin, "buildx", "ls")
}
// helper function to create the docker build command.
func commandBuild(build Build, dryrun bool) *execabs.Cmd {
args := []string{
"buildx",
"build",
"--rm=true",
"-f", build.Containerfile,
}
defaultBuildArgs := []string{
fmt.Sprintf("DOCKER_IMAGE_CREATED=%s", time.Now().Format(time.RFC3339)),
}
args = append(args, build.Context)
if !dryrun && build.Output == "" && len(build.Tags.Value()) > 0 {
args = append(args, "--push")
}
if build.Compress {
args = append(args, "--compress")
}
if build.Pull {
args = append(args, "--pull=true")
}
if build.NoCache {
args = append(args, "--no-cache")
}
for _, arg := range build.CacheFrom {
args = append(args, "--cache-from", arg)
}
if build.CacheTo != "" {
args = append(args, "--cache-to", build.CacheTo)
}
for _, arg := range build.ArgsEnv.Value() {
addProxyValue(&build, arg)
}
for _, arg := range append(defaultBuildArgs, build.Args.Value()...) {
args = append(args, "--build-arg", arg)
}
for _, host := range build.AddHost.Value() {
args = append(args, "--add-host", host)
}
if build.Target != "" {
args = append(args, "--target", build.Target)
}
if build.Quiet {
args = append(args, "--quiet")
}
if build.Output != "" {
args = append(args, "--output", build.Output)
}
for _, arg := range build.NamedContext.Value() {
args = append(args, "--build-context", arg)
}
if len(build.Platforms.Value()) > 0 {
args = append(args, "--platform", strings.Join(build.Platforms.Value(), ","))
}
for _, arg := range build.Tags.Value() {
args = append(args, "-t", fmt.Sprintf("%s:%s", build.Repo, arg))
}
for _, arg := range build.ExtraTags.Value() {
args = append(args, "-t", arg)
}
for _, arg := range build.Labels.Value() {
args = append(args, "--label", arg)
}
if build.Provenance != "" {
args = append(args, "--provenance", build.Provenance)
}
if build.SBOM != "" {
args = append(args, "--sbom", build.SBOM)
}
for _, secret := range build.Secrets {
args = append(args, "--secret", secret)
}
return execabs.Command(dockerBin, args...)
}
// helper function to add proxy values from the environment.
func addProxyBuildArgs(build *Build) {
addProxyValue(build, "http_proxy")
addProxyValue(build, "https_proxy")
addProxyValue(build, "no_proxy")
}
// helper function to add the upper and lower case version of a proxy value.
func addProxyValue(build *Build, key string) {
value := getProxyValue(key)
if len(value) > 0 && !hasProxyBuildArg(build, key) {
build.Args = *cli.NewStringSlice(append(build.Args.Value(), fmt.Sprintf("%s=%s", key, value))...)
build.Args = *cli.NewStringSlice(append(build.Args.Value(), fmt.Sprintf("%s=%s", strings.ToUpper(key), value))...)
}
}
// helper function to get a proxy value from the environment.
//
// assumes that the upper and lower case versions of are the same.
func getProxyValue(key string) string {
value := os.Getenv(key)
if len(value) > 0 {
return value
}
return os.Getenv(strings.ToUpper(key))
}
// helper function that looks to see if a proxy value was set in the build args.
func hasProxyBuildArg(build *Build, key string) bool {
keyUpper := strings.ToUpper(key)
for _, s := range build.Args.Value() {
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) {
return true
}
}
return false
}
// helper function to create the docker daemon command.
func commandDaemon(daemon Daemon) *execabs.Cmd {
args := []string{
"--data-root", daemon.StoragePath,
"--host=unix:///var/run/docker.sock",
}
if daemon.StorageDriver != "" {
args = append(args, "-s", daemon.StorageDriver)
}
if daemon.Insecure && daemon.Registry != "" {
args = append(args, "--insecure-registry", daemon.Registry)
}
if daemon.IPv6 {
args = append(args, "--ipv6")
}
if daemon.Mirror != "" {
args = append(args, "--registry-mirror", daemon.Mirror)
}
if daemon.Bip != "" {
args = append(args, "--bip", daemon.Bip)
}
for _, dns := range daemon.DNS.Value() {
args = append(args, "--dns", dns)
}
for _, dnsSearch := range daemon.DNSSearch.Value() {
args = append(args, "--dns-search", dnsSearch)
}
if daemon.MTU != "" {
args = append(args, "--mtu", daemon.MTU)
}
if daemon.Experimental {
args = append(args, "--experimental")
}
if daemon.MaxConcurrentUploads != "" {
args = append(args, "--max-concurrent-uploads", daemon.MaxConcurrentUploads)
}
return execabs.Command(dockerdBin, args...)
}

View File

@ -5,16 +5,17 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/rs/zerolog/log"
"github.com/thegeeklab/wp-plugin-go/tag"
"github.com/thegeeklab/wp-plugin-go/trace"
"github.com/thegeeklab/wp-plugin-go/types"
"github.com/thegeeklab/wp-docker-buildx/docker"
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
plugin_file "github.com/thegeeklab/wp-plugin-go/v3/file"
plugin_tag "github.com/thegeeklab/wp-plugin-go/v3/tag"
plugin_types "github.com/thegeeklab/wp-plugin-go/v3/types"
plugin_util "github.com/thegeeklab/wp-plugin-go/v3/util"
"github.com/urfave/cli/v2"
"golang.org/x/sys/execabs"
)
var ErrTypeAssertionFailed = errors.New("type assertion failed")
@ -47,15 +48,15 @@ func (p *Plugin) run(ctx context.Context) error {
func (p *Plugin) Validate() error {
p.Settings.Build.Branch = p.Metadata.Repository.Branch
p.Settings.Build.Ref = p.Metadata.Curr.Ref
p.Settings.Daemon.Registry = p.Settings.Login.Registry
p.Settings.Daemon.Registry = p.Settings.Registry.Address
if p.Settings.Build.TagsAuto {
// return true if tag event or default branch
if tag.IsTaggable(
if plugin_tag.IsTaggable(
p.Settings.Build.Ref,
p.Settings.Build.Branch,
) {
tag, err := tag.SemverTagSuffix(
tag, err := plugin_tag.SemverTagSuffix(
p.Settings.Build.Ref,
p.Settings.Build.TagsSuffix,
true,
@ -79,19 +80,28 @@ func (p *Plugin) Validate() error {
//
//nolint:gocognit
func (p *Plugin) Execute() error {
var err error
homeDir := plugin_util.GetUserHomeDir()
batchCmd := make([]*plugin_exec.Cmd, 0)
// start the Docker daemon server
//nolint: nestif
if !p.Settings.Daemon.Disabled {
// If no custom DNS value set start internal DNS server
if len(p.Settings.Daemon.DNS.Value()) == 0 {
ip, err := getContainerIP()
ip, err := GetContainerIP()
if err != nil {
log.Warn().Msgf("error detecting IP address: %v", err)
}
if ip != "" {
log.Debug().Msgf("discovered IP address: %v", ip)
p.startCoredns()
cmd := p.Settings.Daemon.StartCoreDNS()
go func() {
_ = cmd.Run()
}()
if err := p.Settings.Daemon.DNS.Set(ip); err != nil {
return fmt.Errorf("error setting daemon dns: %w", err)
@ -99,13 +109,16 @@ func (p *Plugin) Execute() error {
}
}
p.startDaemon()
cmd := p.Settings.Daemon.Start()
go func() {
_ = cmd.Run()
}()
}
// poll the docker daemon until it is started. This ensures the daemon is
// ready to accept connections before we proceed.
for i := 0; i < 15; i++ {
cmd := commandInfo()
cmd := docker.Info()
err := cmd.Run()
if err == nil {
@ -115,57 +128,40 @@ func (p *Plugin) Execute() error {
time.Sleep(time.Second * 1)
}
// Create Auth Config File
if p.Settings.Login.Config != "" {
if err := os.MkdirAll(dockerHome, strictFilePerm); err != nil {
return fmt.Errorf("failed to create docker home: %w", err)
}
path := filepath.Join(dockerHome, "config.json")
err := os.WriteFile(path, []byte(p.Settings.Login.Config), strictFilePerm)
if err != nil {
return fmt.Errorf("error writing config.json: %w", err)
if p.Settings.Registry.Config != "" {
if err := WriteDockerConf(homeDir, p.Settings.Registry.Config); err != nil {
return fmt.Errorf("error writing docker config: %w", err)
}
}
// login to the Docker registry
if p.Settings.Login.Password != "" {
cmd := commandLogin(p.Settings.Login)
err := cmd.Run()
if err != nil {
if p.Settings.Registry.Password != "" {
if err := p.Settings.Registry.Login().Run(); err != nil {
return fmt.Errorf("error authenticating: %w", err)
}
}
if p.Settings.Daemon.BuildkitConfig != "" {
err := os.WriteFile(buildkitConfig, []byte(p.Settings.Daemon.BuildkitConfig), strictFilePerm)
if err != nil {
return fmt.Errorf("error writing buildkit.toml: %w", err)
buildkitConf := p.Settings.BuildkitConfig
if buildkitConf != "" {
if p.Settings.Daemon.BuildkitConfigFile, err = plugin_file.WriteTmpFile("buildkit.toml", buildkitConf); err != nil {
return fmt.Errorf("error writing buildkit config: %w", err)
}
defer os.Remove(p.Settings.Daemon.BuildkitConfigFile)
}
switch {
case p.Settings.Login.Password != "":
case p.Settings.Registry.Password != "":
log.Info().Msgf("Detected registry credentials")
case p.Settings.Login.Config != "":
case p.Settings.Registry.Config != "":
log.Info().Msgf("Detected registry credentials file")
default:
log.Info().Msgf("Registry credentials or Docker config not provided. Guest mode enabled.")
}
// add proxy build args
addProxyBuildArgs(&p.Settings.Build)
p.Settings.Build.AddProxyBuildArgs()
backoffOps := func() error {
versionCmd := commandVersion() // docker version
versionCmd.Stdout = os.Stdout
versionCmd.Stderr = os.Stderr
trace.Cmd(versionCmd)
return versionCmd.Run()
return docker.Version().Run()
}
backoffLog := func(err error, delay time.Duration) {
log.Error().Msgf("failed to run docker version command: %v: retry in %s", err, delay.Truncate(time.Second))
@ -175,20 +171,17 @@ func (p *Plugin) Execute() error {
return err
}
var batchCmd []*execabs.Cmd
batchCmd = append(batchCmd, commandInfo()) // docker info
batchCmd = append(batchCmd, commandBuilder(p.Settings.Daemon))
batchCmd = append(batchCmd, commandBuildx())
batchCmd = append(batchCmd, commandBuild(p.Settings.Build, p.Settings.Dryrun)) // docker build
batchCmd = append(batchCmd, docker.Info())
batchCmd = append(batchCmd, p.Settings.Daemon.CreateBuilder())
batchCmd = append(batchCmd, p.Settings.Daemon.ListBuilder())
batchCmd = append(batchCmd, p.Settings.Build.Run())
// execute all commands in batch mode.
for _, cmd := range batchCmd {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace.Cmd(cmd)
if cmd == nil {
continue
}
err := cmd.Run()
if err != nil {
if err := cmd.Run(); err != nil {
return err
}
}
@ -197,14 +190,14 @@ func (p *Plugin) Execute() error {
}
func (p *Plugin) FlagsFromContext() error {
cacheFrom, ok := p.Context.Generic("cache-from").(*types.StringSliceFlag)
cacheFrom, ok := p.Context.Generic("cache-from").(*plugin_types.StringSliceFlag)
if !ok {
return fmt.Errorf("%w: failed to read cache-from input", ErrTypeAssertionFailed)
}
p.Settings.Build.CacheFrom = cacheFrom.Get()
secrets, ok := p.Context.Generic("secrets").(*types.StringSliceFlag)
secrets, ok := p.Context.Generic("secrets").(*plugin_types.StringSliceFlag)
if !ok {
return fmt.Errorf("%w: failed to read secrets input", ErrTypeAssertionFailed)
}

View File

@ -1,91 +1,394 @@
package plugin
import (
wp "github.com/thegeeklab/wp-plugin-go/plugin"
"fmt"
"github.com/thegeeklab/wp-docker-buildx/docker"
plugin_base "github.com/thegeeklab/wp-plugin-go/v3/plugin"
plugin_types "github.com/thegeeklab/wp-plugin-go/v3/types"
"github.com/urfave/cli/v2"
)
//go:generate go run ../internal/docs/main.go -output=../docs/data/data-raw.yaml
// Plugin implements provide the plugin.
type Plugin struct {
*wp.Plugin
*plugin_base.Plugin
Settings *Settings
}
// Settings for the Plugin.
type Settings struct {
Daemon Daemon
Login Login
Build Build
Dryrun bool
BuildkitConfig string
Daemon docker.Daemon
Registry docker.Registry
Build docker.Build
}
// Daemon defines Docker daemon parameters.
type Daemon struct {
Registry string // Docker registry
Mirror string // Docker registry mirror
Insecure bool // Docker daemon enable insecure registries
StorageDriver string // Docker daemon storage driver
StoragePath string // Docker daemon storage path
Disabled bool // DOcker daemon is disabled (already running)
Debug bool // Docker daemon started in debug mode
Bip string // Docker daemon network bridge IP address
DNS cli.StringSlice // Docker daemon dns server
DNSSearch cli.StringSlice // Docker daemon dns search domain
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
BuildkitConfig string // Docker buildkit config
MaxConcurrentUploads string
}
// Login defines Docker login parameters.
type Login struct {
Registry string // Docker registry address
Username string // Docker registry username
Password string // Docker registry password
Email string // Docker registry email
Config string // Docker Auth Config
}
// Build defines Docker build parameters.
type Build struct {
Ref string // Git commit ref
Branch string // Git repository branch
Containerfile string // Docker build Containerfile
Context string // Docker build context
TagsAuto bool // Docker build auto tag
TagsSuffix string // Docker build tags with suffix
Tags cli.StringSlice // Docker build tags
ExtraTags cli.StringSlice // Docker build tags including registry
Platforms cli.StringSlice // Docker build target platforms
Args cli.StringSlice // Docker build args
ArgsEnv cli.StringSlice // Docker build args from env
Target string // Docker build target
Pull bool // Docker build pull
CacheFrom []string // Docker build cache-from
CacheTo string // Docker build cache-to
Compress bool // Docker build compress
Repo string // Docker build repository
NoCache bool // Docker build no-cache
AddHost cli.StringSlice // Docker build add-host
Quiet bool // Docker build quiet
Output string // Docker build output folder
NamedContext cli.StringSlice // Docker build named context
Labels cli.StringSlice // Docker build labels
Provenance string // Docker build provenance attestation
SBOM string // Docker build sbom attestation
Secrets []string // Docker build secrets
}
func New(options wp.Options, settings *Settings) *Plugin {
p := &Plugin{}
if options.Execute == nil {
options.Execute = p.run
func New(e plugin_base.ExecuteFunc, build ...string) *Plugin {
p := &Plugin{
Settings: &Settings{},
}
p.Plugin = wp.New(options)
p.Settings = settings
options := plugin_base.Options{
Name: "wp-docker-buildx",
Description: "Build multiarch OCI images with buildx",
Flags: Flags(p.Settings, plugin_base.FlagsPluginCategory),
Execute: p.run,
HideWoodpeckerFlags: true,
}
if len(build) > 0 {
options.Version = build[0]
}
if len(build) > 1 {
options.VersionMetadata = fmt.Sprintf("date=%s", build[1])
}
if e != nil {
options.Execute = e
}
p.Plugin = plugin_base.New(options)
return p
}
// Flags returns a slice of CLI flags for the plugin.
//
//nolint:maintidx
func Flags(settings *Settings, category string) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "dry-run",
EnvVars: []string{"PLUGIN_DRY_RUN"},
Usage: "disable docker push",
Destination: &settings.Build.Dryrun,
Category: category,
},
&cli.StringFlag{
Name: "daemon.mirror",
EnvVars: []string{"PLUGIN_MIRROR", "DOCKER_PLUGIN_MIRROR"},
Usage: "registry mirror to pull images",
Destination: &settings.Daemon.Mirror,
DefaultText: "$DOCKER_PLUGIN_MIRROR",
Category: category,
},
&cli.StringFlag{
Name: "daemon.storage-driver",
EnvVars: []string{"PLUGIN_STORAGE_DRIVER"},
Usage: "docker daemon storage driver",
Destination: &settings.Daemon.StorageDriver,
Category: category,
},
&cli.StringFlag{
Name: "daemon.storage-path",
EnvVars: []string{"PLUGIN_STORAGE_PATH"},
Usage: "docker daemon storage path",
Value: "/var/lib/docker",
Destination: &settings.Daemon.StoragePath,
Category: category,
},
&cli.StringFlag{
Name: "daemon.bip",
EnvVars: []string{"PLUGIN_BIP"},
Usage: "allow the docker daemon to bride IP address",
Destination: &settings.Daemon.Bip,
Category: category,
},
&cli.StringFlag{
Name: "daemon.mtu",
EnvVars: []string{"PLUGIN_MTU"},
Usage: "docker daemon custom MTU setting",
Destination: &settings.Daemon.MTU,
Category: category,
},
&cli.StringSliceFlag{
Name: "daemon.dns",
EnvVars: []string{"PLUGIN_CUSTOM_DNS"},
Usage: "custom docker daemon DNS server",
Destination: &settings.Daemon.DNS,
Category: category,
},
&cli.StringSliceFlag{
Name: "daemon.dns-search",
EnvVars: []string{"PLUGIN_CUSTOM_DNS_SEARCH"},
Usage: "custom docker daemon DNS search domain",
Destination: &settings.Daemon.DNSSearch,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.insecure",
EnvVars: []string{"PLUGIN_INSECURE"},
Usage: "allow the docker daemon to use insecure registries",
Value: false,
Destination: &settings.Daemon.Insecure,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.ipv6",
EnvVars: []string{"PLUGIN_IPV6"},
Usage: "enable docker daemon IPv6 support",
Value: false,
Destination: &settings.Daemon.IPv6,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.experimental",
EnvVars: []string{"PLUGIN_EXPERIMENTAL"},
Usage: "enable docker daemon experimental mode",
Value: false,
Destination: &settings.Daemon.Experimental,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.debug",
EnvVars: []string{"PLUGIN_DEBUG"},
Usage: "enable verbose debug mode for the docker daemon",
Value: false,
Destination: &settings.Daemon.Debug,
Category: category,
},
&cli.BoolFlag{
Name: "daemon.off",
EnvVars: []string{"PLUGIN_DAEMON_OFF"},
Usage: "disable the startup of the docker daemon",
Value: false,
Destination: &settings.Daemon.Disabled,
Category: category,
},
&cli.StringFlag{
Name: "daemon.buildkit-config",
EnvVars: []string{"PLUGIN_BUILDKIT_CONFIG"},
Usage: "content of the docker buildkit toml config",
Destination: &settings.BuildkitConfig,
Category: category,
},
&cli.StringFlag{
Name: "daemon.max-concurrent-uploads",
EnvVars: []string{"PLUGIN_MAX_CONCURRENT_UPLOADS"},
Usage: "max concurrent uploads for each push",
Destination: &settings.Daemon.MaxConcurrentUploads,
Category: category,
},
&cli.StringFlag{
Name: "containerfile",
EnvVars: []string{"PLUGIN_CONTAINERFILE"},
Usage: "containerfile to use for the image build",
Value: "Containerfile",
Destination: &settings.Build.Containerfile,
Category: category,
},
&cli.StringFlag{
Name: "context",
EnvVars: []string{"PLUGIN_CONTEXT"},
Usage: "path of the build context",
Value: ".",
Destination: &settings.Build.Context,
Category: category,
},
&cli.StringSliceFlag{
Name: "named-context",
EnvVars: []string{"PLUGIN_NAMED_CONTEXT"},
Usage: "additional named build context",
Destination: &settings.Build.NamedContext,
Category: category,
},
&cli.StringSliceFlag{
Name: "tags",
EnvVars: []string{"PLUGIN_TAGS", "PLUGIN_TAG"},
Usage: "repository tags to use for the image",
FilePath: ".tags",
Destination: &settings.Build.Tags,
Category: category,
},
&cli.BoolFlag{
Name: "tags.auto",
EnvVars: []string{"PLUGIN_AUTO_TAG", "PLUGIN_DEFAULT_TAGS"},
Usage: "generate tag names automatically based on git branch and git tag",
Value: false,
Destination: &settings.Build.TagsAuto,
Category: category,
},
&cli.StringFlag{
Name: "tags.suffix",
EnvVars: []string{"PLUGIN_AUTO_TAG_SUFFIX", "PLUGIN_DEFAULT_SUFFIX"},
Usage: "generate tag names with the given suffix",
Destination: &settings.Build.TagsSuffix,
Category: category,
},
&cli.StringSliceFlag{
Name: "extra.tags",
EnvVars: []string{"PLUGIN_EXTRA_TAGS"},
Usage: "additional tags to use for the image including registry",
FilePath: ".extratags",
Destination: &settings.Build.ExtraTags,
Category: category,
},
&cli.StringSliceFlag{
Name: "args",
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
Usage: "custom build arguments for the build",
Destination: &settings.Build.Args,
Category: category,
},
&cli.StringSliceFlag{
Name: "args-from-env",
EnvVars: []string{"PLUGIN_BUILD_ARGS_FROM_ENV"},
Usage: "forward environment variables as custom arguments to the build",
Destination: &settings.Build.ArgsEnv,
Category: category,
},
&cli.BoolFlag{
Name: "quiet",
EnvVars: []string{"PLUGIN_QUIET"},
Usage: "enable suppression of the build output",
Value: false,
Destination: &settings.Build.Quiet,
Category: category,
},
&cli.StringFlag{
Name: "output",
EnvVars: []string{"PLUGIN_OUTPUT"},
Usage: "export action for the build result",
Destination: &settings.Build.Output,
Category: category,
},
&cli.StringFlag{
Name: "target",
EnvVars: []string{"PLUGIN_TARGET"},
Usage: "build target to use",
Destination: &settings.Build.Target,
Category: category,
},
&cli.GenericFlag{
Name: "cache-from",
EnvVars: []string{"PLUGIN_CACHE_FROM"},
Usage: "images to consider as cache sources",
Value: &plugin_types.StringSliceFlag{},
Category: category,
},
&cli.StringFlag{
Name: "cache-to",
EnvVars: []string{"PLUGIN_CACHE_TO"},
Usage: "cache destination for the build cache",
Destination: &settings.Build.CacheTo,
Category: category,
},
&cli.BoolFlag{
Name: "pull-image",
EnvVars: []string{"PLUGIN_PULL_IMAGE"},
Usage: "enforce to pull base image at build time",
Value: true,
Destination: &settings.Build.Pull,
Category: category,
},
&cli.BoolFlag{
Name: "compress",
EnvVars: []string{"PLUGIN_COMPRESS"},
Usage: "enable compression of the build context using gzip",
Value: false,
Destination: &settings.Build.Compress,
Category: category,
},
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"PLUGIN_REPO"},
Usage: "repository name for the image",
Destination: &settings.Build.Repo,
Category: category,
},
&cli.StringFlag{
Name: "docker.registry",
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
Usage: "docker registry to authenticate with",
Value: "https://index.docker.io/v1/",
Destination: &settings.Registry.Address,
Category: category,
},
&cli.StringFlag{
Name: "docker.username",
EnvVars: []string{"PLUGIN_USERNAME", "DOCKER_USERNAME"},
Usage: "username for registry authentication",
Destination: &settings.Registry.Username,
DefaultText: "$DOCKER_USERNAME",
Category: category,
},
&cli.StringFlag{
Name: "docker.password",
EnvVars: []string{"PLUGIN_PASSWORD", "DOCKER_PASSWORD"},
Usage: "password for registry authentication",
Destination: &settings.Registry.Password,
DefaultText: "$DOCKER_PASSWORD",
Category: category,
},
&cli.StringFlag{
Name: "docker.email",
EnvVars: []string{"PLUGIN_EMAIL", "DOCKER_EMAIL"},
Usage: "email address for registry authentication",
Destination: &settings.Registry.Email,
DefaultText: "$DOCKER_EMAIL",
Category: category,
},
&cli.StringFlag{
Name: "docker.config",
EnvVars: []string{"PLUGIN_CONFIG", "DOCKER_PLUGIN_CONFIG"},
Usage: "content of the docker daemon json config",
Destination: &settings.Registry.Config,
DefaultText: "$DOCKER_PLUGIN_CONFIG",
Category: category,
},
&cli.BoolFlag{
Name: "no-cache",
EnvVars: []string{"PLUGIN_NO_CACHE"},
Usage: "disable the usage of cached intermediate containers",
Value: false,
Destination: &settings.Build.NoCache,
Category: category,
},
&cli.StringSliceFlag{
Name: "add-host",
EnvVars: []string{"PLUGIN_ADD_HOST"},
Usage: "additional `host:ip` mapping",
Destination: &settings.Build.AddHost,
Category: category,
},
&cli.StringSliceFlag{
Name: "platforms",
EnvVars: []string{"PLUGIN_PLATFORMS"},
Usage: "target platform for build",
Destination: &settings.Build.Platforms,
Category: category,
},
&cli.StringSliceFlag{
Name: "labels",
EnvVars: []string{"PLUGIN_LABELS"},
Usage: "labels to add to image",
Destination: &settings.Build.Labels,
Category: category,
},
&cli.StringFlag{
Name: "provenance",
EnvVars: []string{"PLUGIN_PROVENANCE"},
Usage: "generates provenance attestation for the build",
Destination: &settings.Build.Provenance,
Category: category,
},
&cli.StringFlag{
Name: "sbom",
EnvVars: []string{"PLUGIN_SBOM"},
Usage: "generates SBOM attestation for the build",
Destination: &settings.Build.SBOM,
Category: category,
},
&cli.GenericFlag{
Name: "secrets",
EnvVars: []string{"PLUGIN_SECRETS"},
Usage: "exposes secrets to the build",
Value: &plugin_types.StringSliceFlag{},
Category: category,
},
}
}

View File

@ -1,15 +1,12 @@
package main
package plugin
import (
"context"
"reflect"
"testing"
"github.com/thegeeklab/wp-docker-buildx/plugin"
wp "github.com/thegeeklab/wp-plugin-go/plugin"
)
func Test_pluginOptions(t *testing.T) {
func TestFlags(t *testing.T) {
tests := []struct {
name string
envs map[string]string
@ -32,14 +29,7 @@ func Test_pluginOptions(t *testing.T) {
t.Setenv(key, value)
}
settings := &plugin.Settings{}
options := wp.Options{
Name: "wp-docker-buildx",
Flags: settingsFlags(settings, wp.FlagsPluginCategory),
Execute: func(_ context.Context) error { return nil },
}
got := plugin.New(options, settings)
got := New(func(_ context.Context) error { return nil })
_ = got.App.Run([]string{"wp-docker-buildx"})
_ = got.FlagsFromContext()

38
plugin/util.go Normal file
View File

@ -0,0 +1,38 @@
package plugin
import (
"net"
"os"
"path/filepath"
)
func GetContainerIP() (string, error) {
netInterfaceAddrList, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, netInterfaceAddr := range netInterfaceAddrList {
netIP, ok := netInterfaceAddr.(*net.IPNet)
if ok && !netIP.IP.IsLoopback() && netIP.IP.To4() != nil {
return netIP.IP.String(), nil
}
}
return "", nil
}
func WriteDockerConf(path, conf string) error {
confPath := filepath.Join(path, ".docker", "config.json")
if err := os.MkdirAll(confPath, strictFilePerm); err != nil {
return err
}
err := os.WriteFile(path, []byte(conf), strictFilePerm)
if err != nil {
return err
}
return nil
}

1
testdata/Containerfile vendored Normal file
View File

@ -0,0 +1 @@
FROM alpine:latest