mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
create: load default buildkit config if none specified
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
98439f7f08
commit
8257a04a7d
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/docker/buildx/store"
|
"github.com/docker/buildx/store"
|
||||||
"github.com/docker/buildx/store/storeutil"
|
"github.com/docker/buildx/store/storeutil"
|
||||||
"github.com/docker/buildx/util/cobrautil"
|
"github.com/docker/buildx/util/cobrautil"
|
||||||
|
"github.com/docker/buildx/util/confutil"
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
@ -191,6 +192,16 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if in.configFile == "" {
|
||||||
|
// if buildkit config is not provided, check if the default one is
|
||||||
|
// available and use it
|
||||||
|
if f, ok := confutil.DefaultConfigFile(dockerCli); ok {
|
||||||
|
logrus.Warnf("Using default BuildKit config in %s", f)
|
||||||
|
in.configFile = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := ng.Update(in.nodeName, ep, in.platform, setEp, in.actionAppend, flags, in.configFile, m); err != nil {
|
if err := ng.Update(in.nodeName, ep, in.platform, setEp, in.actionAppend, flags, in.configFile, m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,11 @@ Specifies the configuration file for the buildkitd daemon to use. The configurat
|
|||||||
can be overridden by [`--buildkitd-flags`](#buildkitd-flags).
|
can be overridden by [`--buildkitd-flags`](#buildkitd-flags).
|
||||||
See an [example buildkitd configuration file](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md).
|
See an [example buildkitd configuration file](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md).
|
||||||
|
|
||||||
|
If the configuration file is not specified, will look for one by default in:
|
||||||
|
* `$BUILDX_CONFIG/buildkitd.default.toml`
|
||||||
|
* `$DOCKER_CONFIG/buildx/buildkitd.default.toml`
|
||||||
|
* `~/.docker/buildx/buildkitd.default.toml`
|
||||||
|
|
||||||
Note that if you create a `docker-container` builder and have specified
|
Note that if you create a `docker-container` builder and have specified
|
||||||
certificates for registries in the `buildkitd.toml` configuration, the files
|
certificates for registries in the `buildkitd.toml` configuration, the files
|
||||||
will be copied into the container under `/etc/buildkit/certs` and configuration
|
will be copied into the container under `/etc/buildkit/certs` and configuration
|
||||||
|
@ -2,6 +2,7 @@ package confutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
@ -24,6 +25,15 @@ func ConfigDir(dockerCli command.Cli) string {
|
|||||||
return buildxConfig
|
return buildxConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultConfigFile returns the default BuildKit configuration file path
|
||||||
|
func DefaultConfigFile(dockerCli command.Cli) (string, bool) {
|
||||||
|
f := path.Join(ConfigDir(dockerCli), "buildkitd.default.toml")
|
||||||
|
if _, err := os.Stat(f); err == nil {
|
||||||
|
return f, true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
// loadConfigTree loads BuildKit config toml tree
|
// loadConfigTree loads BuildKit config toml tree
|
||||||
func loadConfigTree(fp string) (*toml.Tree, error) {
|
func loadConfigTree(fp string) (*toml.Tree, error) {
|
||||||
f, err := os.Open(fp)
|
f, err := os.Open(fp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user