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

Add Docker registries use_local_alias configuration option. #17265

Merged
merged 8 commits into from
Nov 8, 2022

Conversation

kaos
Copy link
Member

@kaos kaos commented Oct 18, 2022

Fixes #16354

If you run an Docker image locally, support using a shorter image name than the full registry url required when publishing the image, to keep the image names briefer in case of very long registry addresses (AWS cough cough)

When ./pants run <image target> only the first registry with a "use_local_alias" defined on any of the applicable registries will be built and executed, while ./pants package <image target> always tags the built image with all image names, including the short ones.

Example:

# pants.toml

[docker.registries.company]
address = 123456789987654321.dkr.ecr.us-west-1.amazonaws.com
use_local_alias = true

$ ./pants run myservice:img
Building docker image: company/myservice:latest
...

Where as when you package myservice:img, it would tag it with both the registry address, and the alias and for publish it would push only the image with the registry address.

[ci skip-build-wheels]

[ci skip-rust]
@kaos kaos added category:new feature backend: Docker Docker backend-related issues labels Oct 18, 2022
@kaos kaos requested a review from thejcannon October 18, 2022 23:45
@kaos kaos marked this pull request as draft October 19, 2022 11:55
kaos added 2 commits October 20, 2022 16:39
…ias instead as short name. + fix issue with build invocation from image run goal.
@kaos kaos changed the title Add Docker registries local_name configuration option. Add Docker registries run_as_alias configuration option. Oct 20, 2022
@kaos kaos marked this pull request as ready for review October 20, 2022 22:18
if registry.run_as_alias:
# We only need to tag a single image name for run requests if there is a registry with
# `run_as_alias` as true.
build_request = replace(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is arguably a little bit hackish, but we simply override the list of registries selected for the docker build field set in case of a run request to only include the registry alias as a hardcoded value, overriding any defaults or field values. Sneaky.

@kaos
Copy link
Member Author

kaos commented Oct 20, 2022

@thejcannon does this do what you wish it did?

Copy link
Member

@thejcannon thejcannon left a comment

Choose a reason for hiding this comment

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

The example LGTM. I'll leave the implementation up to whoever to review.

Thanks!

Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Neat! Couple of questions:

Should run_as_alias be local_alias? It may not be specific to the run goal so much as to local operations more generally?

Could we just always generate and use this alias? Do we need the flag?

@kaos
Copy link
Member Author

kaos commented Nov 6, 2022

Should run_as_alias be local_alias? It may not be specific to the run goal so much as to local operations more generally?

Thanks, I like that. 👍🏽

Could we just always generate and use this alias? Do we need the flag?

We could, yes. I was being a bit cautious in making this an opt-in feature. It could add up quite a few extra superfluous tags in case of multiple registries (although I don't know if that is a common thing or not).

I'm fine either way..

@benjyw
Copy link
Contributor

benjyw commented Nov 7, 2022

Could we just always generate and use this alias? Do we need the flag?

We could, yes. I was being a bit cautious in making this an opt-in feature. It could add up quite a few extra superfluous tags in case of multiple registries (although I don't know if that is a common thing or not).

I'm fine either way..

Ah, that makes sense. So yeah, opt-in makes sense, and people can set with __defaults__ if they want to always opt in.

So the name should probably be use_local_alias or something that indicates that the value is a boolean. local_alias seems like it should be the string alias to use...

@kaos
Copy link
Member Author

kaos commented Nov 7, 2022

Could we just always generate and use this alias? Do we need the flag?

We could, yes. I was being a bit cautious in making this an opt-in feature. It could add up quite a few extra superfluous tags in case of multiple registries (although I don't know if that is a common thing or not).
I'm fine either way..

Ah, that makes sense. So yeah, opt-in makes sense, and people can set with __defaults__ if they want to always opt in.

So the name should probably be use_local_alias or something that indicates that the value is a boolean. local_alias seems like it should be the string alias to use...

Gotcha. I'll change to use_local_alias. Just noting that this is a pants configuration, not target field, so __defaults__ doesn't apply.

@benjyw
Copy link
Contributor

benjyw commented Nov 7, 2022

Ah right, this is on the registry.

@kaos kaos changed the title Add Docker registries run_as_alias configuration option. Add Docker registries use_local_alias configuration option. Nov 8, 2022
@kaos kaos enabled auto-merge (squash) November 8, 2022 14:01
@kaos kaos merged commit 3c0214c into pantsbuild:main Nov 8, 2022
@kaos kaos deleted the docker-run-registry-name/16354 branch November 8, 2022 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Docker Docker backend-related issues category:new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow customization of registry when running a docker image
4 participants