diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index 6d8b19beb1..8eb79140d8 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/builder" "github.com/docker/docker/builder/remotecontext" + "github.com/docker/docker/builder/remotecontext/urlutil" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/idtools" @@ -23,7 +24,6 @@ import ( "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/system" - "github.com/docker/docker/pkg/urlutil" "github.com/moby/buildkit/frontend/dockerfile/instructions" specs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" diff --git a/builder/remotecontext/detect.go b/builder/remotecontext/detect.go index 09f4d28434..3dae780275 100644 --- a/builder/remotecontext/detect.go +++ b/builder/remotecontext/detect.go @@ -11,9 +11,9 @@ import ( "github.com/containerd/continuity/driver" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/builder" + "github.com/docker/docker/builder/remotecontext/urlutil" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/urlutil" "github.com/moby/buildkit/frontend/dockerfile/dockerignore" "github.com/moby/buildkit/frontend/dockerfile/parser" "github.com/pkg/errors" diff --git a/pkg/urlutil/urlutil.go b/builder/remotecontext/urlutil/urlutil.go similarity index 93% rename from pkg/urlutil/urlutil.go rename to builder/remotecontext/urlutil/urlutil.go index aafd4314b4..01827d925d 100644 --- a/pkg/urlutil/urlutil.go +++ b/builder/remotecontext/urlutil/urlutil.go @@ -1,6 +1,6 @@ // Package urlutil provides helper function to check urls kind. // It supports http and git urls. -package urlutil // import "github.com/docker/docker/pkg/urlutil" +package urlutil // import "github.com/docker/docker/builder/remotecontext/urlutil" import ( "regexp" diff --git a/pkg/urlutil/urlutil_test.go b/builder/remotecontext/urlutil/urlutil_test.go similarity index 91% rename from pkg/urlutil/urlutil_test.go rename to builder/remotecontext/urlutil/urlutil_test.go index b1df56d508..6906118321 100644 --- a/pkg/urlutil/urlutil_test.go +++ b/builder/remotecontext/urlutil/urlutil_test.go @@ -1,4 +1,4 @@ -package urlutil // import "github.com/docker/docker/pkg/urlutil" +package urlutil // import "github.com/docker/docker/builder/remotecontext/urlutil" import "testing" diff --git a/hack/make.ps1 b/hack/make.ps1 index ea6d5269b3..a183253e27 100644 --- a/hack/make.ps1 +++ b/hack/make.ps1 @@ -251,6 +251,12 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) { $files=@(); $files = Invoke-Expression "git diff $upstreamCommit...$headCommit --diff-filter=ACMR --name-only -- `'pkg\*.go`'" $badFiles=@(); $files | ForEach-Object{ $file=$_ + if ($file -eq "pkg\urlutil\deprecated.go") { + # pkg/urlutil is deprecated, but has a temporary alias to help migration, + # see https://github.com/moby/moby/pull/43477 + # TODO(thaJeztah) remove this exception once pkg/urlutil aliases are removed + return + } # For the current changed file, get its list of dependencies, sorted and uniqued. $imports = Invoke-Expression "go list -e -f `'{{ .Deps }}`' $file" if ($LASTEXITCODE -ne 0) { Throw "Failed go list for dependencies on $file" } diff --git a/hack/validate/pkg-imports b/hack/validate/pkg-imports index f82e315f83..bba762d99f 100755 --- a/hack/validate/pkg-imports +++ b/hack/validate/pkg-imports @@ -10,6 +10,12 @@ unset IFS badFiles=() for f in "${files[@]}"; do + if [ "$f" = "pkg/urlutil/deprecated.go" ]; then + # pkg/urlutil is deprecated, but has a temporary alias to help migration, + # see https://github.com/moby/moby/pull/43477 + # TODO(thaJeztah) remove this exception once pkg/urlutil aliases are removed + continue + fi IFS=$'\n' badImports=($(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/docker/docker/pkg/' | grep -vE '^github.com/docker/docker/vendor' | grep -E '^github.com/docker/docker' || true)) unset IFS diff --git a/pkg/urlutil/deprecated.go b/pkg/urlutil/deprecated.go new file mode 100644 index 0000000000..c09e3efd47 --- /dev/null +++ b/pkg/urlutil/deprecated.go @@ -0,0 +1,21 @@ +package urlutil // import "github.com/docker/docker/pkg/urlutil" + +import "github.com/docker/docker/builder/remotecontext/urlutil" + +// IsURL returns true if the provided str is an HTTP(S) URL. +// +// Deprecated: use github.com/docker/docker/builder/remotecontext/urlutil.IsURL +// to detect build-context type, or use strings.HasPrefix() to check if the +// string has a https:// or http:// prefix. +func IsURL(str string) bool { + // TODO(thaJeztah) when removing this alias, remove the exception from hack/validate/pkg-imports and hack/make.ps1 (Validate-PkgImports) + return urlutil.IsURL(str) +} + +// IsGitURL returns true if the provided str is a git repository URL. +// +// Deprecated: use github.com/docker/docker/builder/remotecontext/urlutil.IsGitURL +func IsGitURL(str string) bool { + // TODO(thaJeztah) when removing this alias, remove the exception from hack/validate/pkg-imports and hack/make.ps1 (Validate-PkgImports) + return urlutil.IsGitURL(str) +}