feat: load buildkit config from string instead of file (#37)
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const dockerExe = "/usr/local/bin/docker"
|
||||
const dockerdExe = "/usr/local/bin/dockerd"
|
||||
const dockerHome = "/root/.docker/"
|
||||
const buildkitConfig = "/tmp/buildkit.json"
|
||||
|
||||
func (p Plugin) startDaemon() {
|
||||
cmd := commandDaemon(p.settings.Daemon)
|
||||
@@ -15,8 +16,8 @@ func (p Plugin) startDaemon() {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
} else {
|
||||
cmd.Stdout = ioutil.Discard
|
||||
cmd.Stderr = ioutil.Discard
|
||||
cmd.Stdout = io.Discard
|
||||
cmd.Stderr = io.Discard
|
||||
}
|
||||
go func() {
|
||||
trace(cmd)
|
||||
|
||||
@@ -54,13 +54,13 @@ func commandInfo() *exec.Cmd {
|
||||
|
||||
func commandBuilder(daemon Daemon) *exec.Cmd {
|
||||
args := []string{
|
||||
"buildx",
|
||||
"create",
|
||||
"buildx",
|
||||
"create",
|
||||
"--use",
|
||||
}
|
||||
|
||||
if daemon.BuildkitConfig != "" {
|
||||
args = append(args, "--config", daemon.BuildkitConfig)
|
||||
args = append(args, "--config", buildkitConfig)
|
||||
}
|
||||
|
||||
return exec.Command(dockerExe, args...)
|
||||
@@ -84,7 +84,7 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd {
|
||||
}
|
||||
|
||||
args = append(args, build.Context)
|
||||
if ! dryrun {
|
||||
if !dryrun {
|
||||
args = append(args, "--push")
|
||||
}
|
||||
if build.Squash {
|
||||
@@ -124,7 +124,7 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd {
|
||||
|
||||
for _, arg := range build.Tags.Value() {
|
||||
args = append(args, "-t", fmt.Sprintf("%s:%s", build.Repo, arg))
|
||||
}
|
||||
}
|
||||
|
||||
return exec.Command(dockerExe, args...)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -27,7 +26,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
|
||||
BuildkitConfig string // Docker buildkit config
|
||||
}
|
||||
|
||||
// Login defines Docker login parameters.
|
||||
@@ -78,12 +77,6 @@ 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(
|
||||
@@ -131,7 +124,7 @@ func (p *Plugin) Execute() error {
|
||||
os.MkdirAll(dockerHome, 0600)
|
||||
|
||||
path := filepath.Join(dockerHome, "config.json")
|
||||
err := ioutil.WriteFile(path, []byte(p.settings.Login.Config), 0600)
|
||||
err := os.WriteFile(path, []byte(p.settings.Login.Config), 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing config.json: %s", err)
|
||||
}
|
||||
@@ -146,6 +139,13 @@ func (p *Plugin) Execute() error {
|
||||
}
|
||||
}
|
||||
|
||||
if p.settings.Daemon.BuildkitConfig != "" {
|
||||
err := os.WriteFile(buildkitConfig, []byte(p.settings.Daemon.BuildkitConfig), 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing buildkit.json: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case p.settings.Login.Password != "":
|
||||
fmt.Println("Detected registry credentials")
|
||||
|
||||
Reference in New Issue
Block a user