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"},
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{
Name: "dockerfile",
Usage: "build dockerfile",

View File

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

View File

@ -27,6 +27,7 @@ type Daemon struct {
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
BuildkitConfig string // Docker buildkit config file
}
// Login defines Docker login parameters.
@ -77,6 +78,12 @@ func (p *Plugin) Validate() error {
p.settings.Build.Ref = p.pipeline.Commit.Ref
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 {
// return true if tag event or default branch
if UseDefaultTag(
@ -159,7 +166,7 @@ func (p *Plugin) Execute() error {
var cmds []*exec.Cmd
cmds = append(cmds, commandVersion()) // docker version
cmds = append(cmds, commandInfo()) // docker info
cmds = append(cmds, commandBuilder())
cmds = append(cmds, commandBuilder(p.settings.Daemon))
cmds = append(cmds, commandBuildx())
// pre-pull cache images