adds driver-opt arg as plugin parameter (#93)
#### 📖 Summary Adds `--driver-opt` buildx arg as plugin parameter. This should make it possible to pass through proxy settings. #### 📑 Test Plan > 💡 Select your test plan for the code changes. - [x] CI pipeline tests - Custom test - No test plan ##### Details / Justification Manually tested on own instance behind corporate proxy:  Unfortunately the `--build-arg` passthru seems not working #### 📚 Additional Notes - fixes #82 - still to do: - [x] update docs - [x] add usage example > 💡NOTE: This is my first contribution in this codebase. Feedback and help is probably needed 😸 Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/93 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: OCram85 <marco.blessing@googlemail.com> Co-committed-by: OCram85 <marco.blessing@googlemail.com>
This commit is contained in:
@@ -41,6 +41,10 @@ func commandBuilder(daemon Daemon) *exec.Cmd {
|
||||
args = append(args, "--config", buildkitConfig)
|
||||
}
|
||||
|
||||
for _, driveropt := range daemon.BuildkitDriverOpt.Value() {
|
||||
args = append(args, "--driver-opt", driveropt)
|
||||
}
|
||||
|
||||
return exec.Command(dockerExe, args...)
|
||||
}
|
||||
|
||||
|
||||
72
plugin/docker_test.go
Normal file
72
plugin/docker_test.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func TestCommandBuilder(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
Name string
|
||||
Daemon Daemon
|
||||
Input string
|
||||
WantedLen int
|
||||
Skip bool
|
||||
Excuse string
|
||||
}{
|
||||
{
|
||||
Name: "Single driver-opt value",
|
||||
Daemon: Daemon{},
|
||||
Input: "no_proxy=*.mydomain",
|
||||
WantedLen: 1,
|
||||
},
|
||||
{
|
||||
Name: "Single driver-opt value with comma",
|
||||
Input: "no_proxy=.mydomain,.sub.domain.com",
|
||||
WantedLen: 1,
|
||||
Skip: true,
|
||||
Excuse: "Can be enabled whenever #94 is fixed.",
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
if (test.Skip) {
|
||||
t.Skip(fmt.Printf("%v skipped. %v", test.Name, test.Excuse))
|
||||
}
|
||||
// prepare test values to mock plugin call with settings
|
||||
os.Setenv("PLUGIN_BUILDKIT_DRIVEROPT", test.Input)
|
||||
|
||||
// create dummy cli app to reproduce the issue
|
||||
app := &cli.App{
|
||||
Name: "dummy App",
|
||||
Usage: "testing inputs",
|
||||
Version: "0.0.1",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "daemon.buildkit-driveropt",
|
||||
EnvVars: []string{"PLUGIN_BUILDKIT_DRIVEROPT"},
|
||||
Usage: "adds optional driver-ops args like 'env.http_proxy'",
|
||||
Destination: &test.Daemon.BuildkitDriverOpt,
|
||||
},
|
||||
},
|
||||
Action: nil,
|
||||
}
|
||||
|
||||
// need to run the app to resolve the flags
|
||||
_ = app.Run(nil)
|
||||
|
||||
// call the commandBuilder to prepare the cmd with its args
|
||||
_ = commandBuilder(test.Daemon)
|
||||
|
||||
assert.Len(t, test.Daemon.BuildkitDriverOpt.Value(), test.WantedLen)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,20 +18,21 @@ import (
|
||||
|
||||
// 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
|
||||
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
|
||||
BuildkitDriverOpt cli.StringSlice // Docker buildkit driveropt args
|
||||
}
|
||||
|
||||
// Login defines Docker login parameters.
|
||||
|
||||
Reference in New Issue
Block a user