Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#712 Infer registry URL from Template image name #807

Merged
merged 8 commits into from
May 25, 2023

Conversation

Dohbedoh
Copy link
Contributor

@Dohbedoh Dohbedoh commented Jul 27, 2020

Addresses #712. Infer the registry URL from image name using the org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint#fromImageName

Fixes #712

@Dohbedoh
Copy link
Contributor Author

Dohbedoh commented Jul 29, 2020

A fix might be needed upstream as the org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint#fromImageName does not accept the V2 syntax registry/path/to/image:tag. Which is a bug / improvement for docker-commons.

String hostname = NameParser.resolveRepositoryName(
NameParser.parseRepositoryTag(getImage()).repos).hostname;
if(!hostname.startsWith("https://")) {
hostname = "https://" + hostname;
Copy link
Member

Choose a reason for hiding this comment

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

Are you 100% sure that https:// is the correct default here?
I know that docker registries can use https, and if one is authenticating then it's best to use an encrypted means of communicating, but it looks like the code here would prevent someone from using "http://hostname.domain" as this would be turned into "https://http://hostname.domain" which is unlikely to work at all.

I suspect that it'd be better to only prefix with https:// if there was no protocol specified at all ... but I'm not entirely sure of that here (I'm not in a position to experiment/evaluate right now either - current work pressures are such that my time for this is limited to "review, ask questions, push merge button and hope").

Copy link
Contributor Author

@Dohbedoh Dohbedoh Aug 12, 2020

Choose a reason for hiding this comment

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

I suspect that it'd be better to only prefix with https:// if there was no protocol specified at all ...

NameParser#resolveRepositoryName actually throw an exception if you provide the scheme in the image name. That is to say that http://hostname.domain/repo/name:tag is not a valid image name. So you cannot specify http://.
However NameParser#resolveRepositoryName use https://index.docker.io/v1/ if there no registry specified, hence the condition.
I agree that we could just do this if there is no protocol at all.

Are you 100% sure that https:// is the correct default here?

DockerRegistryEndpoint is also setting https:// for the scheme. The help says The url is built from registry:port into https://registry:port, the same way docker push does..

@@ -567,7 +567,13 @@ public void setExtraDockerLabelsString(String extraDockerLabelsString) {

public DockerRegistryEndpoint getRegistry() {
if (registry == null) {
registry = new DockerRegistryEndpoint(null, pullCredentialsId);
/* TODO: Use DockerRegistryEndpoint#fromImageName when JENKINS-63243 is fixed */
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 PR for this issue yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

That PR had to wait a long time, but it looks like that PR was merged in on 24 Aug, and went into docker-commons 1.20 onwards.

Could you update this PR to use the new code (i.e. resolve the TODO comment)?

@pjdarton pjdarton added the enhancement A PR providing an enhancement to existing functionality. label Aug 3, 2020
@basil basil requested a review from a team as a code owner May 24, 2023 16:21
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

TODO needs to be resolved

@basil basil merged commit e96ccab into jenkinsci:master May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A PR providing an enhancement to existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to specify private docker registry in Configure Jenkins -> Cloud
3 participants