-
Notifications
You must be signed in to change notification settings - Fork 1.3k
executor: optionally inject a docker registry prefixed url #48499
Changes from 2 commits
0996bf3
ca0be3e
a9313dc
cd14206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ const ScriptsPath = ".sourcegraph-executor" | |
| // given options. | ||
| func formatRawOrDockerCommand(spec CommandSpec, dir string, options Options, dockerConfigPath string) command { | ||
| // TODO - remove this once src-cli is not required anymore for SSBC. | ||
| // Note: unless the `native-ssbc-execution` feature-flag is enabled, this | ||
| // is the default execution method | ||
| if spec.Image == "" { | ||
| env := spec.Env | ||
| if dockerConfigPath != "" { | ||
|
|
@@ -36,6 +38,13 @@ func formatRawOrDockerCommand(spec CommandSpec, dir string, options Options, doc | |
| hostDir = filepath.Join(options.ResourceOptions.DockerHostMountPath, filepath.Base(dir)) | ||
| } | ||
|
|
||
| // TODO check that the original spec.Image isn't fully qualified so we don't inject our path | ||
| // and create an invalid docker name | ||
| image := spec.Image | ||
| if options.DockerOptions.RegistryUrl != "" { | ||
| image = fmt.Sprintf("%s/%s", options.DockerOptions.RegistryUrl, image) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've tried to resolve this with this pr: https://github.com/sourcegraph/sourcegraph/pull/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
According to the Artifact Registry documents, at the moment: no
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. |
||
| } | ||
|
|
||
| return command{ | ||
| Key: spec.Key, | ||
| Command: flatten( | ||
|
|
@@ -48,7 +57,7 @@ func formatRawOrDockerCommand(spec CommandSpec, dir string, options Options, doc | |
| dockerWorkingdirectoryFlags(spec.Dir), | ||
| dockerEnvFlags(spec.Env), | ||
| dockerEntrypointFlags(), | ||
| spec.Image, | ||
| image, | ||
| filepath.Join("/data", ScriptsPath, spec.ScriptPath), | ||
| ), | ||
| Operation: spec.Operation, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,10 @@ package config | |
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/url" | ||
| "runtime" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/c2h5oh/datasize" | ||
|
|
@@ -46,6 +48,7 @@ type Config struct { | |
| DockerRegistryNodeExporterURL string | ||
| WorkerHostname string | ||
| DockerRegistryMirrorURL string | ||
| DockerRegistryPrefixURL string | ||
| DockerAuthConfig types.DockerAuthConfig | ||
| dockerAuthConfigStr string | ||
| dockerAuthConfigUnmarshalError error | ||
|
|
@@ -82,6 +85,7 @@ func (c *Config) Load() { | |
| c.DockerRegistryNodeExporterURL = c.GetOptional("DOCKER_REGISTRY_NODE_EXPORTER_URL", "The URL of the Docker Registry instance's node_exporter, without the /metrics path.") | ||
| c.MaxActiveTime = c.GetInterval("EXECUTOR_MAX_ACTIVE_TIME", "0", "The maximum time that can be spent by the worker dequeueing records to be handled.") | ||
| c.DockerRegistryMirrorURL = c.GetOptional("EXECUTOR_DOCKER_REGISTRY_MIRROR_URL", "The address of a docker registry mirror to use in firecracker VMs. Supports multiple values, separated with a comma.") | ||
| c.DockerRegistryPrefixURL = c.GetOptional("EXECUTOR_DOCKER_REGISTRY_PREFIX_URL", "The address of a docker reigsry mirror to use in firecracker VMs that will be injected before all container names to fully qualify their URL. Supports only a single registry.") | ||
| c.dockerAuthConfigStr = c.GetOptional("EXECUTOR_DOCKER_AUTH_CONFIG", "The content of the docker config file including auth for services. If using firecracker, only static credentials are supported, not credential stores nor credential helpers.") | ||
|
|
||
| if c.dockerAuthConfigStr != "" { | ||
|
|
@@ -123,5 +127,19 @@ func (c *Config) Validate() error { | |
| } | ||
| } | ||
|
|
||
| // Verify that no Docker registry URLs contain a subpath that will crash the Docker daemon startup | ||
| // https://github.com/docker/engine/blob/8955d8da8951695a98eb7e15bead19d402c6eb27/registry/config.go#L303-L321 | ||
| registries := strings.Split(c.DockerRegistryMirrorURL, ",") | ||
| for _, registry := range registries { | ||
| uri, err := url.Parse(registry) | ||
| if err != nil { | ||
| 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")) | ||
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| return c.BaseConfig.Validate() | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.