Selaa lähdekoodia

Merge pull request #30411 from thaJeztah/fix-build-from-local-github-directories

do not ignore local build-contexts starting with "github.com"
Alexander Morozov 8 vuotta sitten
vanhempi
commit
048fc98c09
1 muutettua tiedostoa jossa 8 lisäystä ja 1 poistoa
  1. 8 1
      cli/command/image/build.go

+ 8 - 1
cli/command/image/build.go

@@ -157,12 +157,14 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
 	switch {
 	switch {
 	case specifiedContext == "-":
 	case specifiedContext == "-":
 		buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)
 		buildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)
+	case isLocalDir(specifiedContext):
+		contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName)
 	case urlutil.IsGitURL(specifiedContext):
 	case urlutil.IsGitURL(specifiedContext):
 		tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, options.dockerfileName)
 		tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, options.dockerfileName)
 	case urlutil.IsURL(specifiedContext):
 	case urlutil.IsURL(specifiedContext):
 		buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName)
 		buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName)
 	default:
 	default:
-		contextDir, relDockerfile, err = build.GetContextFromLocalDir(specifiedContext, options.dockerfileName)
+		return fmt.Errorf("unable to prepare context: path %q not found", specifiedContext)
 	}
 	}
 
 
 	if err != nil {
 	if err != nil {
@@ -357,6 +359,11 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
 	return nil
 	return nil
 }
 }
 
 
+func isLocalDir(c string) bool {
+	_, err := os.Stat(c)
+	return err == nil
+}
+
 type translatorFunc func(context.Context, reference.NamedTagged) (reference.Canonical, error)
 type translatorFunc func(context.Context, reference.NamedTagged) (reference.Canonical, error)
 
 
 // validateTag checks if the given image name can be resolved.
 // validateTag checks if the given image name can be resolved.