mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-24 12:50:41 +00:00
chore: migrate to wp-plugin-go v3 (#181)
This commit is contained in:
parent
8761da6871
commit
51889e1102
@ -1,11 +1,10 @@
|
|||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os"
|
||||||
|
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/sys/execabs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const dockerdBin = "/usr/local/bin/dockerd"
|
const dockerdBin = "/usr/local/bin/dockerd"
|
||||||
@ -30,7 +29,7 @@ type Daemon struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker daemon command.
|
// helper function to create the docker daemon command.
|
||||||
func (d *Daemon) Start() *types.Cmd {
|
func (d *Daemon) Start() *plugin_exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"--data-root", d.StoragePath,
|
"--data-root", d.StoragePath,
|
||||||
"--host=unix:///var/run/docker.sock",
|
"--host=unix:///var/run/docker.sock",
|
||||||
@ -76,13 +75,17 @@ func (d *Daemon) Start() *types.Cmd {
|
|||||||
args = append(args, "--max-concurrent-uploads", d.MaxConcurrentUploads)
|
args = append(args, "--max-concurrent-uploads", d.MaxConcurrentUploads)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerdBin, args...)
|
||||||
Cmd: execabs.Command(dockerdBin, args...),
|
|
||||||
Private: !d.Debug,
|
if d.Debug {
|
||||||
}
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) CreateBuilder() *types.Cmd {
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Daemon) CreateBuilder() *plugin_exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"buildx",
|
"buildx",
|
||||||
"create",
|
"create",
|
||||||
@ -93,20 +96,28 @@ func (d *Daemon) CreateBuilder() *types.Cmd {
|
|||||||
args = append(args, "--config", d.BuildkitConfigFile)
|
args = append(args, "--config", d.BuildkitConfigFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerBin, args...)
|
||||||
Cmd: execabs.Command(dockerBin, args...),
|
cmd.Stdout = os.Stdout
|
||||||
}
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) ListBuilder() *types.Cmd {
|
func (d *Daemon) ListBuilder() *plugin_exec.Cmd {
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerBin, "buildx", "ls")
|
||||||
Cmd: execabs.Command(dockerBin, "buildx", "ls"),
|
cmd.Stdout = os.Stdout
|
||||||
}
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) StartCoreDNS() *types.Cmd {
|
func (d *Daemon) StartCoreDNS() *plugin_exec.Cmd {
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command("coredns", "-conf", "/etc/coredns/Corefile")
|
||||||
Cmd: exec.Command("coredns", "-conf", "/etc/coredns/Corefile"),
|
|
||||||
Private: !d.Debug,
|
if d.Debug {
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/sys/execabs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const dockerBin = "/usr/local/bin/docker"
|
const dockerBin = "/usr/local/bin/docker"
|
||||||
@ -54,7 +53,7 @@ type Build struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker login command.
|
// helper function to create the docker login command.
|
||||||
func (r *Registry) Login() *types.Cmd {
|
func (r *Registry) Login() *plugin_exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"login",
|
"login",
|
||||||
"-u", r.Username,
|
"-u", r.Username,
|
||||||
@ -67,27 +66,33 @@ func (r *Registry) Login() *types.Cmd {
|
|||||||
|
|
||||||
args = append(args, r.Address)
|
args = append(args, r.Address)
|
||||||
|
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerBin, args...)
|
||||||
Cmd: execabs.Command(dockerBin, args...),
|
cmd.Stdout = os.Stdout
|
||||||
}
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker info command.
|
// helper function to create the docker info command.
|
||||||
func Version() *types.Cmd {
|
func Version() *plugin_exec.Cmd {
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerBin, "version")
|
||||||
Cmd: execabs.Command(dockerBin, "version"),
|
cmd.Stdout = os.Stdout
|
||||||
}
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker info command.
|
// helper function to create the docker info command.
|
||||||
func Info() *types.Cmd {
|
func Info() *plugin_exec.Cmd {
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerBin, "info")
|
||||||
Cmd: execabs.Command(dockerBin, "info"),
|
cmd.Stdout = os.Stdout
|
||||||
}
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker build command.
|
// helper function to create the docker build command.
|
||||||
func (b *Build) Run() *types.Cmd {
|
func (b *Build) Run() *plugin_exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"buildx",
|
"buildx",
|
||||||
"build",
|
"build",
|
||||||
@ -180,9 +185,11 @@ func (b *Build) Run() *types.Cmd {
|
|||||||
args = append(args, "--secret", secret)
|
args = append(args, "--secret", secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Cmd{
|
cmd := plugin_exec.Command(dockerBin, args...)
|
||||||
Cmd: execabs.Command(dockerBin, args...),
|
cmd.Stdout = os.Stdout
|
||||||
}
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to add proxy values from the environment.
|
// helper function to add proxy values from the environment.
|
||||||
|
4
go.mod
4
go.mod
@ -5,9 +5,8 @@ go 1.22
|
|||||||
require (
|
require (
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0
|
github.com/cenkalti/backoff/v4 v4.3.0
|
||||||
github.com/rs/zerolog v1.32.0
|
github.com/rs/zerolog v1.32.0
|
||||||
github.com/thegeeklab/wp-plugin-go/v2 v2.3.1
|
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2
|
||||||
github.com/urfave/cli/v2 v2.27.2
|
github.com/urfave/cli/v2 v2.27.2
|
||||||
golang.org/x/sys v0.20.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -29,4 +28,5 @@ require (
|
|||||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
|
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
|
||||||
golang.org/x/crypto v0.23.0 // indirect
|
golang.org/x/crypto v0.23.0 // indirect
|
||||||
golang.org/x/net v0.25.0 // indirect
|
golang.org/x/net v0.25.0 // indirect
|
||||||
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -48,8 +48,8 @@ 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.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 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/thegeeklab/wp-plugin-go/v2 v2.3.1 h1:ARwYgTPZ5iPsmOenmqcCf8TjiEe8wBOHKO7H/Xshe48=
|
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 h1:Mv5i8S1WY+BUNjTjX6lOnB3p8S9mvM+XwfY4R98gx0g=
|
||||||
github.com/thegeeklab/wp-plugin-go/v2 v2.3.1/go.mod h1:0t8M8txtEFiaB6RqLX8vLrxkqAo5FT5Hx7dztN592D4=
|
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 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
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 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thegeeklab/wp-docker-buildx/plugin"
|
"github.com/thegeeklab/wp-docker-buildx/plugin"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/docs"
|
plugin_docs "github.com/thegeeklab/wp-plugin-go/v3/docs"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/template"
|
plugin_template "github.com/thegeeklab/wp-plugin-go/v3/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -23,7 +23,7 @@ func main() {
|
|||||||
|
|
||||||
p := plugin.New(nil)
|
p := plugin.New(nil)
|
||||||
|
|
||||||
out, err := template.Render(context.Background(), client, tmpl, docs.GetTemplateData(p.App))
|
out, err := plugin_template.Render(context.Background(), client, tmpl, plugin_docs.GetTemplateData(p.App))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,11 @@ import (
|
|||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/thegeeklab/wp-docker-buildx/docker"
|
"github.com/thegeeklab/wp-docker-buildx/docker"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/file"
|
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/tag"
|
plugin_file "github.com/thegeeklab/wp-plugin-go/v3/file"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
plugin_tag "github.com/thegeeklab/wp-plugin-go/v3/tag"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/util"
|
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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,11 +52,11 @@ func (p *Plugin) Validate() error {
|
|||||||
|
|
||||||
if p.Settings.Build.TagsAuto {
|
if p.Settings.Build.TagsAuto {
|
||||||
// return true if tag event or default branch
|
// return true if tag event or default branch
|
||||||
if tag.IsTaggable(
|
if plugin_tag.IsTaggable(
|
||||||
p.Settings.Build.Ref,
|
p.Settings.Build.Ref,
|
||||||
p.Settings.Build.Branch,
|
p.Settings.Build.Branch,
|
||||||
) {
|
) {
|
||||||
tag, err := tag.SemverTagSuffix(
|
tag, err := plugin_tag.SemverTagSuffix(
|
||||||
p.Settings.Build.Ref,
|
p.Settings.Build.Ref,
|
||||||
p.Settings.Build.TagsSuffix,
|
p.Settings.Build.TagsSuffix,
|
||||||
true,
|
true,
|
||||||
@ -81,8 +82,8 @@ func (p *Plugin) Validate() error {
|
|||||||
func (p *Plugin) Execute() error {
|
func (p *Plugin) Execute() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
homeDir := util.GetUserHomeDir()
|
homeDir := plugin_util.GetUserHomeDir()
|
||||||
batchCmd := make([]*types.Cmd, 0)
|
batchCmd := make([]*plugin_exec.Cmd, 0)
|
||||||
|
|
||||||
// start the Docker daemon server
|
// start the Docker daemon server
|
||||||
//nolint: nestif
|
//nolint: nestif
|
||||||
@ -141,7 +142,7 @@ func (p *Plugin) Execute() error {
|
|||||||
|
|
||||||
buildkitConf := p.Settings.BuildkitConfig
|
buildkitConf := p.Settings.BuildkitConfig
|
||||||
if buildkitConf != "" {
|
if buildkitConf != "" {
|
||||||
if p.Settings.Daemon.BuildkitConfigFile, err = file.WriteTmpFile("buildkit.toml", buildkitConf); err != nil {
|
if p.Settings.Daemon.BuildkitConfigFile, err = plugin_file.WriteTmpFile("buildkit.toml", buildkitConf); err != nil {
|
||||||
return fmt.Errorf("error writing buildkit config: %w", err)
|
return fmt.Errorf("error writing buildkit config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,14 +190,14 @@ func (p *Plugin) Execute() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) FlagsFromContext() 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 {
|
if !ok {
|
||||||
return fmt.Errorf("%w: failed to read cache-from input", ErrTypeAssertionFailed)
|
return fmt.Errorf("%w: failed to read cache-from input", ErrTypeAssertionFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Settings.Build.CacheFrom = cacheFrom.Get()
|
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 {
|
if !ok {
|
||||||
return fmt.Errorf("%w: failed to read secrets input", ErrTypeAssertionFailed)
|
return fmt.Errorf("%w: failed to read secrets input", ErrTypeAssertionFailed)
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/thegeeklab/wp-docker-buildx/docker"
|
"github.com/thegeeklab/wp-docker-buildx/docker"
|
||||||
wp "github.com/thegeeklab/wp-plugin-go/v2/plugin"
|
plugin_base "github.com/thegeeklab/wp-plugin-go/v3/plugin"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
plugin_types "github.com/thegeeklab/wp-plugin-go/v3/types"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
// Plugin implements provide the plugin.
|
// Plugin implements provide the plugin.
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
*wp.Plugin
|
*plugin_base.Plugin
|
||||||
Settings *Settings
|
Settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,15 +26,15 @@ type Settings struct {
|
|||||||
Build docker.Build
|
Build docker.Build
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(e wp.ExecuteFunc, build ...string) *Plugin {
|
func New(e plugin_base.ExecuteFunc, build ...string) *Plugin {
|
||||||
p := &Plugin{
|
p := &Plugin{
|
||||||
Settings: &Settings{},
|
Settings: &Settings{},
|
||||||
}
|
}
|
||||||
|
|
||||||
options := wp.Options{
|
options := plugin_base.Options{
|
||||||
Name: "wp-docker-buildx",
|
Name: "wp-docker-buildx",
|
||||||
Description: "Build multiarch OCI images with buildx",
|
Description: "Build multiarch OCI images with buildx",
|
||||||
Flags: Flags(p.Settings, wp.FlagsPluginCategory),
|
Flags: Flags(p.Settings, plugin_base.FlagsPluginCategory),
|
||||||
Execute: p.run,
|
Execute: p.run,
|
||||||
HideWoodpeckerFlags: true,
|
HideWoodpeckerFlags: true,
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func New(e wp.ExecuteFunc, build ...string) *Plugin {
|
|||||||
options.Execute = e
|
options.Execute = e
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Plugin = wp.New(options)
|
p.Plugin = plugin_base.New(options)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ func Flags(settings *Settings, category string) []cli.Flag {
|
|||||||
Name: "cache-from",
|
Name: "cache-from",
|
||||||
EnvVars: []string{"PLUGIN_CACHE_FROM"},
|
EnvVars: []string{"PLUGIN_CACHE_FROM"},
|
||||||
Usage: "images to consider as cache sources",
|
Usage: "images to consider as cache sources",
|
||||||
Value: &types.StringSliceFlag{},
|
Value: &plugin_types.StringSliceFlag{},
|
||||||
Category: category,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@ -387,7 +387,7 @@ func Flags(settings *Settings, category string) []cli.Flag {
|
|||||||
Name: "secrets",
|
Name: "secrets",
|
||||||
EnvVars: []string{"PLUGIN_SECRETS"},
|
EnvVars: []string{"PLUGIN_SECRETS"},
|
||||||
Usage: "exposes secrets to the build",
|
Usage: "exposes secrets to the build",
|
||||||
Value: &types.StringSliceFlag{},
|
Value: &plugin_types.StringSliceFlag{},
|
||||||
Category: category,
|
Category: category,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user