Skip to content

Commit

Permalink
image: Fix Windows usage of Image resource
Browse files Browse the repository at this point in the history
The context dir must be validated and made into an absolute dir. Methods from
`docker/cli/image/build` are used to massage the input path and validate it
before using it in build options.
  • Loading branch information
AaronFriel committed Mar 13, 2023
1 parent f396f03 commit 91b79ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/moby/buildkit/session/auth/authprovider"
"github.com/moby/moby/registry"

clibuild "github.com/docker/cli/cli/command/image/build"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/credentials"
Expand Down Expand Up @@ -106,6 +107,15 @@ func (p *dockerNativeProvider) dockerBuild(ctx context.Context,
return "", nil, fmt.Errorf("error reading ignore file: %w", err)
}

contextDir, err := clibuild.ResolveAndValidateContextPath(build.Context)
if err != nil {
return "", nil, fmt.Errorf("error resolving context: %w", err)
}

if err := clibuild.ValidateContextDirectory(contextDir, initialIgnorePatterns); err != nil {
return "", nil, fmt.Errorf("error validating context: %w", err)
}

// un-ignore build files so the docker daemon can use them
ignorePatterns := buildCmd.TrimBuildFilesFromExcludes(
initialIgnorePatterns,
Expand Down
2 changes: 1 addition & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *dockerNativeProvider) Check(ctx context.Context, req *rpc.CheckRequest)
os = "linux"
}
arch := runtime.GOARCH
hostPlatform := filepath.Join(os, arch)
hostPlatform := os + "/" + arch
msg := fmt.Sprintf(
"Building your image for %s architecture.\n"+
"To ensure you are building for the correct platform, consider "+
Expand Down

0 comments on commit 91b79ab

Please sign in to comment.