Skip to content

pkg/urlutil: deprecate, and move to builder/remotecontext/urlutil#43477

Merged
thaJeztah merged 3 commits intomoby:masterfrom
thaJeztah:deprecate_urlutil
Apr 13, 2022
Merged

pkg/urlutil: deprecate, and move to builder/remotecontext/urlutil#43477
thaJeztah merged 3 commits intomoby:masterfrom
thaJeztah:deprecate_urlutil

Conversation

@thaJeztah
Copy link
Member

follow-up to #43476 (only last three commits are new)

pkg/urlutil: remove unused IsTransportURL()

This function is no longer used (either internally, or externally), so can be removed.

pkg/urlutil: deprecate, and move to builder/remotecontext/urlutil

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic utility to handle URLs, and should only be used by the builder to handle (remote) build contexts.

  • IsURL() only does a very rudimentary check for http(s):// prefixes, without any other validation, but due to its name may give incorrect expectations.
  • IsGitURL() is written specifically with docker build remote git contexts in mind, and has handling for backward-compatibility, where strings that are not URLs, but start with "github.com/" are accepted.

Because of the above, this patch:

  • moves the package inside builder/remotecontext, close to where it's intended to be used (ideally this would be part of build/remotecontext itself, but this package imports many other dependencies, which would introduce those as extra dependencies in the CLI).
  • deprecates pkg/urlutil, but adds aliases as there are some external consumers.

builder/remotecontext/urlutil: simplify and improve documentation

Simplify some of the logic, and add documentation about the package, as well as warnings that this package should not be used as a general-purpose utility.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 22.04.0 milestone Apr 10, 2022
@thaJeztah thaJeztah force-pushed the deprecate_urlutil branch 3 times, most recently from 828167b to da8bf54 Compare April 11, 2022 16:08
@thaJeztah thaJeztah marked this pull request as ready for review April 11, 2022 19:52
@thaJeztah thaJeztah requested a review from tonistiigi as a code owner April 11, 2022 19:52
@thaJeztah
Copy link
Member Author

@tonistiigi @crazy-max ptal

//
// | Build Syntax Suffix | Git reference used | Build Context Used |
// |--------------------------------|----------------------|--------------------|
// | my-repo.git | refs/heads/master | / |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me change this to main instead of master (and describe "default branch")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, actually, looks like we still have that hardcoded, so we'll have to look at that in a follow-up.

@thaJeztah
Copy link
Member Author

Ah dang; can't create an alias;

These files import internal code: (either directly or indirectly)
  - pkg/urlutil/deprecated.go imports github.com/docker/docker/builder/remotecontext/urlutil

@thaJeztah thaJeztah requested a review from tianon as a code owner April 12, 2022 08:03
// 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.
IsURL = urlutil.IsURL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason you went with the variable approach here rather than providing these as functions? I can't think (off the top of my head) of any particular reason why it would break a consumer as-is, but (public) variables are writable globals, so it's conceivable that another package could modify these and inject unintended behavior into a consumer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a habit (not sure if "good" or "bad") it's slightly easier to create a list of aliases when deprecating a package (which could be slightly clearer "hey, don't use this; here's where to look"), and in some cases may remove imports that are used in the signature of the aliased function 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and in some cases may remove imports that are used in the signature of the aliased function 😅

🤯 I can see why this can matter, though here both IsURL and IsGitURL are both func (string) bool, so there's nothing outside builtin types used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, you're right. In this case it doesn't bring much; let me change it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

This function is no longer used (either internally, or externally), so
can be removed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

- IsURL() only does a very rudimentary check for http(s):// prefixes, without any
  other validation, but due to its name may give incorrect expectations.
- IsGitURL() is written specifically with docker build remote git contexts in
  mind, and has handling for backward-compatibility, where strings that are
  not URLs, but start with "github.com/" are accepted.

Because of the above, this patch:

- moves the package inside builder/remotecontext, close to where it's intended
  to be used (ideally this would be part of build/remotecontext itself, but this
  package imports many other dependencies, which would introduce those as extra
  dependencies in the CLI).
- deprecates pkg/urlutil, but adds aliases as there are some external consumers.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Simplify some of the logic, and add documentation about the package,
as well as warnings that this package should not be used as a general-
purpose utility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother with pkg/urlutil and just remove it.

@thaJeztah
Copy link
Member Author

Yeah, definitely not planning to keep it for long, but found it used in various external projects, so wanted to give a tiny amount of room for those to move away from it.

@thaJeztah
Copy link
Member Author

Interesting error on CI (DCO check test)

git openssh-client && cd /workspace && hack/validate/dco
[2022-04-12T21:37:15.034Z] Unable to find image 'alpine:latest' locally
[2022-04-12T21:37:15.293Z] latest: Pulling from library/alpine
[2022-04-12T21:37:15.293Z] df9b9388f04a: Pulling fs layer
[2022-04-12T21:37:15.860Z] df9b9388f04a: Pull complete
[2022-04-12T21:37:15.860Z] Digest: sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454
[2022-04-12T21:37:15.860Z] Status: Downloaded newer image for alpine:latest
[2022-04-12T21:37:23.999Z] fatal: unsafe repository ('/workspace' is owned by someone else)
[2022-04-12T21:37:23.999Z] To add an exception for this directory, call:
[2022-04-12T21:37:23.999Z] 
[2022-04-12T21:37:23.999Z] 	git config --global --add safe.directory /workspace
script returned exit code 128

@thaJeztah
Copy link
Member Author

I see it's using an alpine:latest image to run the check in; wondering if alpine was updated (or the git version in alpine)

Copy link
Member

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from whatever weirdness is going on with CI.

@thaJeztah
Copy link
Member Author

Looks to be related to a vulnerability that was fixed in git; https://github.blog/2022-04-12-git-security-vulnerability-announced/

@thaJeztah
Copy link
Member Author

Triggered CI with the DCO check skipped (to check if the rest of the pipeline also needs adjustments)

I'll have a look at fixing the DCO stage to adjust for the git security fix (looks to be because the source is checked out on the worker by Jenkins, but then accessed inside a container, in which case the user doesn't match the user on the host, triggering the security warning)

@thaJeztah
Copy link
Member Author

opened #43485 to fix the DCO check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants