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

executor: optionally inject a docker registry prefixed url #48499

Closed
wants to merge 4 commits into from

Conversation

danieldides
Copy link
Contributor

@danieldides danieldides commented Mar 1, 2023

Part of https://github.com/sourcegraph/customer/issues/1872

Allow an new, optional configuration passed to the executor to configure a Docker registry that should be prefixed on all docker commands. E.g., turn ubuntu:latest into us-central1.pkg.dev/project/repo/ubuntu:latest. This will allow us to utilize Artifact Registry for executors.

Current solutions do not work because the Docker daemon does not support registry URLs with subpaths included in it.

This depends on sourcegraph/src-cli#945 for SSBC. I've tried my best to catch all other Docker commands but I'm not 100% sure I caught everything. Autoindexing in particular evades me a little.

Test plan

Ran it locally. Some basic unit tests. Cannot test Firecracker injection until a container is built and deployed.

@danieldides danieldides marked this pull request as ready for review March 1, 2023 23:50
@danieldides danieldides requested a review from a team March 1, 2023 23:50
enterprise/cmd/executor/internal/command/docker.go Outdated Show resolved Hide resolved
// and create an invalid docker name
image := spec.Image
if options.DockerOptions.RegistryUrl != "" {
image = fmt.Sprintf("%s/%s", options.DockerOptions.RegistryUrl, image)
Copy link
Member

Choose a reason for hiding this comment

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

does this work for non-docker hub images, and if the image is a full URL?

nodejs:16 // probably works
arm64/nodejs:16 // probably works as well
index.docker.io/nodejs:16 // does this work?
privateartifactory.sgdev.org/nodejs/nodejs:16 // does this work?

Also, I think for non-hub images we need to skip this mirror, as it cannot access the image.

Also, can the artifact registry handle/forward authentication? So for example if I use the image eseliger/private-nodejs:16 and configure a docker hub credential, will that just work? Otherwise, I think we'll have to bypass the mirror for auth'd requests, too even if it's docker hub. I think that is in line with how docker works when you actually configure a registry mirror.

Copy link
Member

Choose a reason for hiding this comment

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

Ah well, I've just seen the TODO comment above - so likely this needs tweaking before this is good to go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does this work for non-docker hub images, and if the image is a full URL?

I've tried to resolve this with this pr: #48659. It's a best-effort. Since the official Docker spec does not allow subpaths in the registry URL (and I understand why now 😭) there's no easy way to truly determine how to parse a full URL container image name when we allow an arbitrary number of / in the subpath.

Also, can the artifact registry handle/forward authentication? So for example if I use the image eseliger/private-nodejs:16 and configure a docker hub credential

According to the Artifact Registry documents, at the moment: no

Docker: For public images in Docker Hub.

If you'd like to use private containers you are instructed to pull from the private repos and push them to Aritfact registry, or configure a virtual repository that prioritizes your private images first.

Ultimately, I'm not sure this feature is really ready to be used by a wider audience without a LOT of disclaimers that you can very easily "hold it wrong". The primary user for this will be Cloud, for which I've tried to cover our specific use-case as best I can.

c.AddError(errors.Newf("invalid registry URL %s provided", uri))
}
if uri.Path != "" {
c.AddError(errors.Newf("registry URL %s contains a subpath, consider using EXECUTOR_DOCKER_REGISTRY_PREFIX_URL instead"))
Copy link
Member

Choose a reason for hiding this comment

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

Nice validation!

Co-authored-by: Erik Seliger <erikseliger@me.com>
@sourcegraph-bot
Copy link
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 8010604...cd14206.

Notify File(s)
@efritz enterprise/cmd/executor/internal/command/docker.go
enterprise/cmd/executor/internal/command/docker_test.go
enterprise/cmd/executor/internal/command/runner.go
enterprise/cmd/executor/internal/config/config.go
enterprise/cmd/executor/internal/run/util.go
enterprise/cmd/executor/internal/worker/handler.go

@sanderginn
Copy link
Contributor

@danieldides would you like additional reviews or is this ready to be merged?

@danieldides
Copy link
Contributor Author

Closing for now. Not sure this is the best path forward anymore. May revisit in the future as part of https://github.com/sourcegraph/customer/issues/2083

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.

None yet

5 participants