From fb0788f18fcd90dbe95a7c7324d2c22e05050d71 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 31 Aug 2022 17:50:47 +0200 Subject: [PATCH] build: replace uses of archive.CanonicalTarNameForPath As it's just an alias for filepath.IsAbs. Also added a normalize step in TrimBuildFilesFromExcludes, so that callers are not _required_ to first normalize the path. We are considering deprecating and/or removing this function in the archive package, so removing it in the cli code helps transitioning if we decide to deprecate and/or remove it. Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build.go | 2 +- cli/command/image/build/dockerignore.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/command/image/build.go b/cli/command/image/build.go index 40b246c5c4..1b03038b7c 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -265,7 +265,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error { } // And canonicalize dockerfile name to a platform-independent one - relDockerfile = archive.CanonicalTarNameForPath(relDockerfile) + relDockerfile = filepath.ToSlash(relDockerfile) excludes = build.TrimBuildFilesFromExcludes(excludes, relDockerfile, options.dockerfileFromStdin()) buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ diff --git a/cli/command/image/build/dockerignore.go b/cli/command/image/build/dockerignore.go index 38cde094ac..c7360d402e 100644 --- a/cli/command/image/build/dockerignore.go +++ b/cli/command/image/build/dockerignore.go @@ -32,6 +32,9 @@ func TrimBuildFilesFromExcludes(excludes []string, dockerfile string, dockerfile if keep, _ := fileutils.Matches(".dockerignore", excludes); keep { excludes = append(excludes, "!.dockerignore") } + + // canonicalize dockerfile name to be platform-independent. + dockerfile = filepath.ToSlash(dockerfile) if keep, _ := fileutils.Matches(dockerfile, excludes); keep && !dockerfileFromStdin { excludes = append(excludes, "!"+dockerfile) }