mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12994 from Microsoft/10662-fixinvocation
Windows: Fix builder\dispatchers.go
This commit is contained in:
commit
e66ad40c4e
1 changed files with 32 additions and 8 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -38,6 +39,9 @@ func nullDispatch(b *Builder, args []string, attributes map[string]bool, origina
|
||||||
// in the dockerfile available from the next statement on via ${foo}.
|
// in the dockerfile available from the next statement on via ${foo}.
|
||||||
//
|
//
|
||||||
func env(b *Builder, args []string, attributes map[string]bool, original string) error {
|
func env(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return fmt.Errorf("ENV is not supported on Windows.")
|
||||||
|
}
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return fmt.Errorf("ENV requires at least one argument")
|
return fmt.Errorf("ENV requires at least one argument")
|
||||||
}
|
}
|
||||||
|
@ -279,10 +283,11 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
|
||||||
// RUN some command yo
|
// RUN some command yo
|
||||||
//
|
//
|
||||||
// run a command and commit the image. Args are automatically prepended with
|
// run a command and commit the image. Args are automatically prepended with
|
||||||
// 'sh -c' in the event there is only one argument. The difference in
|
// 'sh -c' under linux or 'cmd /S /C' under Windows, in the event there is
|
||||||
// processing:
|
// only one argument. The difference in processing:
|
||||||
//
|
//
|
||||||
// RUN echo hi # sh -c echo hi
|
// RUN echo hi # sh -c echo hi (Linux)
|
||||||
|
// RUN echo hi # cmd /S /C echo hi (Windows)
|
||||||
// RUN [ "echo", "hi" ] # echo hi
|
// RUN [ "echo", "hi" ] # echo hi
|
||||||
//
|
//
|
||||||
func run(b *Builder, args []string, attributes map[string]bool, original string) error {
|
func run(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||||
|
@ -297,7 +302,11 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
|
||||||
args = handleJsonArgs(args, attributes)
|
args = handleJsonArgs(args, attributes)
|
||||||
|
|
||||||
if !attributes["json"] {
|
if !attributes["json"] {
|
||||||
args = append([]string{"/bin/sh", "-c"}, args...)
|
if runtime.GOOS != "windows" {
|
||||||
|
args = append([]string{"/bin/sh", "-c"}, args...)
|
||||||
|
} else {
|
||||||
|
args = append([]string{"cmd", "/S /C"}, args...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd := flag.NewFlagSet("run", flag.ContinueOnError)
|
runCmd := flag.NewFlagSet("run", flag.ContinueOnError)
|
||||||
|
@ -360,7 +369,11 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string)
|
||||||
cmdSlice := handleJsonArgs(args, attributes)
|
cmdSlice := handleJsonArgs(args, attributes)
|
||||||
|
|
||||||
if !attributes["json"] {
|
if !attributes["json"] {
|
||||||
cmdSlice = append([]string{"/bin/sh", "-c"}, cmdSlice...)
|
if runtime.GOOS != "windows" {
|
||||||
|
cmdSlice = append([]string{"/bin/sh", "-c"}, cmdSlice...)
|
||||||
|
} else {
|
||||||
|
cmdSlice = append([]string{"cmd", "/S /C"}, cmdSlice...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Config.Cmd = runconfig.NewCommand(cmdSlice...)
|
b.Config.Cmd = runconfig.NewCommand(cmdSlice...)
|
||||||
|
@ -378,8 +391,8 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string)
|
||||||
|
|
||||||
// ENTRYPOINT /usr/sbin/nginx
|
// ENTRYPOINT /usr/sbin/nginx
|
||||||
//
|
//
|
||||||
// Set the entrypoint (which defaults to sh -c) to /usr/sbin/nginx. Will
|
// Set the entrypoint (which defaults to sh -c on linux, or cmd /S /C on Windows) to
|
||||||
// accept the CMD as the arguments to /usr/sbin/nginx.
|
// /usr/sbin/nginx. Will accept the CMD as the arguments to /usr/sbin/nginx.
|
||||||
//
|
//
|
||||||
// Handles command processing similar to CMD and RUN, only b.Config.Entrypoint
|
// Handles command processing similar to CMD and RUN, only b.Config.Entrypoint
|
||||||
// is initialized at NewBuilder time instead of through argument parsing.
|
// is initialized at NewBuilder time instead of through argument parsing.
|
||||||
|
@ -400,7 +413,11 @@ func entrypoint(b *Builder, args []string, attributes map[string]bool, original
|
||||||
b.Config.Entrypoint = nil
|
b.Config.Entrypoint = nil
|
||||||
default:
|
default:
|
||||||
// ENTRYPOINT echo hi
|
// ENTRYPOINT echo hi
|
||||||
b.Config.Entrypoint = runconfig.NewEntrypoint("/bin/sh", "-c", parsed[0])
|
if runtime.GOOS != "windows" {
|
||||||
|
b.Config.Entrypoint = runconfig.NewEntrypoint("/bin/sh", "-c", parsed[0])
|
||||||
|
} else {
|
||||||
|
b.Config.Entrypoint = runconfig.NewEntrypoint("cmd", "/S /C", parsed[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// when setting the entrypoint if a CMD was not explicitly set then
|
// when setting the entrypoint if a CMD was not explicitly set then
|
||||||
|
@ -472,6 +489,10 @@ func expose(b *Builder, args []string, attributes map[string]bool, original stri
|
||||||
// ENTRYPOINT/CMD at container run time.
|
// ENTRYPOINT/CMD at container run time.
|
||||||
//
|
//
|
||||||
func user(b *Builder, args []string, attributes map[string]bool, original string) error {
|
func user(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return fmt.Errorf("USER is not supported on Windows.")
|
||||||
|
}
|
||||||
|
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return fmt.Errorf("USER requires exactly one argument")
|
return fmt.Errorf("USER requires exactly one argument")
|
||||||
}
|
}
|
||||||
|
@ -489,6 +510,9 @@ func user(b *Builder, args []string, attributes map[string]bool, original string
|
||||||
// Expose the volume /foo for use. Will also accept the JSON array form.
|
// Expose the volume /foo for use. Will also accept the JSON array form.
|
||||||
//
|
//
|
||||||
func volume(b *Builder, args []string, attributes map[string]bool, original string) error {
|
func volume(b *Builder, args []string, attributes map[string]bool, original string) error {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return fmt.Errorf("VOLUME is not supported on Windows.")
|
||||||
|
}
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return fmt.Errorf("VOLUME requires at least one argument")
|
return fmt.Errorf("VOLUME requires at least one argument")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue