0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-10 03:30:40 +00:00

feat: add option to specify buildkit config file path (#32)

This commit is contained in:
Albie 2021-07-08 08:00:51 +01:00 committed by GitHub
parent 380e304e7a
commit 904641bf10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 16 deletions

View File

@ -93,6 +93,12 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
EnvVars: []string{"PLUGIN_DAEMON_OFF"}, EnvVars: []string{"PLUGIN_DAEMON_OFF"},
Destination: &settings.Daemon.Disabled, Destination: &settings.Daemon.Disabled,
}, },
&cli.StringFlag{
Name: "daemon.buildkit-config",
Usage: "location of buildkit config file",
EnvVars: []string{"PLUGIN_BUILDKIT_CONFIG"},
Destination: &settings.Daemon.BuildkitConfig,
},
&cli.StringFlag{ &cli.StringFlag{
Name: "dockerfile", Name: "dockerfile",
Usage: "build dockerfile", Usage: "build dockerfile",

View File

@ -52,8 +52,18 @@ func commandInfo() *exec.Cmd {
return exec.Command(dockerExe, "info") return exec.Command(dockerExe, "info")
} }
func commandBuilder() *exec.Cmd { func commandBuilder(daemon Daemon) *exec.Cmd {
return exec.Command(dockerExe, "buildx", "create", "--use") args := []string{
"buildx",
"create",
"--use",
}
if daemon.BuildkitConfig != "" {
args = append(args, "--config", daemon.BuildkitConfig)
}
return exec.Command(dockerExe, args...)
} }
func commandBuildx() *exec.Cmd { func commandBuildx() *exec.Cmd {

View File

@ -27,6 +27,7 @@ type Daemon struct {
MTU string // Docker daemon mtu setting MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode Experimental bool // Docker daemon enable experimental mode
BuildkitConfig string // Docker buildkit config file
} }
// Login defines Docker login parameters. // Login defines Docker login parameters.
@ -77,6 +78,12 @@ func (p *Plugin) Validate() error {
p.settings.Build.Ref = p.pipeline.Commit.Ref p.settings.Build.Ref = p.pipeline.Commit.Ref
p.settings.Daemon.Registry = p.settings.Login.Registry p.settings.Daemon.Registry = p.settings.Login.Registry
if p.settings.Daemon.BuildkitConfig != "" {
if _, err := os.Stat(p.settings.Daemon.BuildkitConfig); err != nil && os.IsNotExist(err) {
return fmt.Errorf("given buildkit config file not found")
}
}
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 UseDefaultTag( if UseDefaultTag(
@ -159,7 +166,7 @@ func (p *Plugin) Execute() error {
var cmds []*exec.Cmd var cmds []*exec.Cmd
cmds = append(cmds, commandVersion()) // docker version cmds = append(cmds, commandVersion()) // docker version
cmds = append(cmds, commandInfo()) // docker info cmds = append(cmds, commandInfo()) // docker info
cmds = append(cmds, commandBuilder()) cmds = append(cmds, commandBuilder(p.settings.Daemon))
cmds = append(cmds, commandBuildx()) cmds = append(cmds, commandBuildx())
// pre-pull cache images // pre-pull cache images