mirror of https://github.com/docker/cli.git
build: use a separate upload request for early progress
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
b19294ee42
commit
8cf213bd0c
|
@ -27,6 +27,8 @@ import (
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const uploadRequestRemote = "upload-request"
|
||||||
|
|
||||||
func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
|
func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
|
||||||
ctx := appcontext.Context()
|
ctx := appcontext.Context()
|
||||||
|
|
||||||
|
@ -38,11 +40,14 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
|
||||||
return errors.Errorf("buildkit not supported by daemon")
|
return errors.Errorf("buildkit not supported by daemon")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildID := stringid.GenerateRandomID()
|
||||||
|
|
||||||
var remote string
|
var remote string
|
||||||
var body io.Reader
|
var body io.Reader
|
||||||
switch {
|
switch {
|
||||||
case options.contextFromStdin():
|
case options.contextFromStdin():
|
||||||
body = os.Stdin
|
body = os.Stdin
|
||||||
|
remote = uploadRequestRemote
|
||||||
case isLocalDir(options.context):
|
case isLocalDir(options.context):
|
||||||
remote = clientSessionRemote
|
remote = clientSessionRemote
|
||||||
case urlutil.IsGitURL(options.context):
|
case urlutil.IsGitURL(options.context):
|
||||||
|
@ -82,13 +87,27 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
|
||||||
return s.Run(context.TODO(), dockerCli.Client().DialSession)
|
return s.Run(context.TODO(), dockerCli.Client().DialSession)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if body != nil {
|
||||||
|
eg.Go(func() error {
|
||||||
|
buildOptions := types.ImageBuildOptions{
|
||||||
|
Version: types.BuilderBuildKit,
|
||||||
|
BuildID: uploadRequestRemote + ":" + buildID,
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := dockerCli.Client().ImageBuild(context.Background(), body, buildOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
defer func() { // make sure the Status ends cleanly on build errors
|
defer func() { // make sure the Status ends cleanly on build errors
|
||||||
s.Close()
|
s.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
buildID := stringid.GenerateRandomID()
|
|
||||||
|
|
||||||
configFile := dockerCli.ConfigFile()
|
configFile := dockerCli.ConfigFile()
|
||||||
buildOptions := types.ImageBuildOptions{
|
buildOptions := types.ImageBuildOptions{
|
||||||
Memory: options.memory.Value(),
|
Memory: options.memory.Value(),
|
||||||
|
@ -110,7 +129,7 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
|
||||||
ShmSize: options.shmSize.Value(),
|
ShmSize: options.shmSize.Value(),
|
||||||
Ulimits: options.ulimits.GetList(),
|
Ulimits: options.ulimits.GetList(),
|
||||||
BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), options.buildArgs.GetAll()),
|
BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), options.buildArgs.GetAll()),
|
||||||
// AuthConfigs: authConfigs,
|
// AuthConfigs: authConfigs, // handled by session
|
||||||
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
|
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
|
||||||
CacheFrom: options.cacheFrom,
|
CacheFrom: options.cacheFrom,
|
||||||
SecurityOpt: options.securityOpt,
|
SecurityOpt: options.securityOpt,
|
||||||
|
@ -125,7 +144,7 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
|
||||||
BuildID: buildID,
|
BuildID: buildID,
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := dockerCli.Client().ImageBuild(context.Background(), body, buildOptions)
|
response, err := dockerCli.Client().ImageBuild(context.Background(), nil, buildOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue