build: Add support for using dockerfile from stdin with buildkit

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2018-05-22 01:44:30 +00:00
parent e0b3921a03
commit 5314a8fc06
1 changed files with 17 additions and 5 deletions

View File

@ -44,8 +44,11 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
buildID := stringid.GenerateRandomID() buildID := stringid.GenerateRandomID()
var remote string var (
var body io.Reader remote string
body io.Reader
dockerfileName = filepath.Base(options.dockerfileName)
)
switch { switch {
case options.contextFromStdin(): case options.contextFromStdin():
rc, isArchive, err := build.DetectArchiveReader(os.Stdin) rc, isArchive, err := build.DetectArchiveReader(os.Stdin)
@ -70,12 +73,21 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
}, },
{ {
Name: "dockerfile", Name: "dockerfile",
Dir: string(dockerfileDir), Dir: dockerfileDir,
}, },
})) }))
remote = clientSessionRemote remote = clientSessionRemote
} }
case isLocalDir(options.context): case isLocalDir(options.context):
dockerfileDir := filepath.Dir(options.dockerfileName)
if options.dockerfileFromStdin() {
dockerfileDir, err = build.WriteTempDockerfile(os.Stdin)
if err != nil {
return err
}
defer os.RemoveAll(dockerfileDir)
dockerfileName = build.DefaultDockerfileName
}
s.Allow(filesync.NewFSSyncProvider([]filesync.SyncedDir{ s.Allow(filesync.NewFSSyncProvider([]filesync.SyncedDir{
{ {
Name: "context", Name: "context",
@ -84,7 +96,7 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
}, },
{ {
Name: "dockerfile", Name: "dockerfile",
Dir: filepath.Dir(options.dockerfileName), Dir: dockerfileDir,
}, },
})) }))
remote = clientSessionRemote remote = clientSessionRemote
@ -149,7 +161,7 @@ func runBuildBuildKit(dockerCli command.Cli, options buildOptions) error {
CPUQuota: options.cpuQuota, CPUQuota: options.cpuQuota,
CPUPeriod: options.cpuPeriod, CPUPeriod: options.cpuPeriod,
CgroupParent: options.cgroupParent, CgroupParent: options.cgroupParent,
Dockerfile: filepath.Base(options.dockerfileName), Dockerfile: dockerfileName,
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()),