diff --git a/images/dockerregistry/Dockerfile b/images/dockerregistry/Dockerfile index 5c20a8ac0821..827c10f09cfb 100644 --- a/images/dockerregistry/Dockerfile +++ b/images/dockerregistry/Dockerfile @@ -14,7 +14,7 @@ RUN INSTALL_PKGS="origin-dockerregistry" && \ COPY config.yml ${REGISTRY_CONFIGURATION_PATH} LABEL io.k8s.display-name="OpenShift Container Platform Image Registry" \ - io.k8s.description="This is a component ofOpenShift Container Platform and exposes a Docker registry that is integrated with the cluster for authentication and management." \ + io.k8s.description="This is a component of OpenShift Container Platform and exposes a Docker registry that is integrated with the cluster for authentication and management." \ io.openshift.tags="openshift,docker,registry" # The registry doesn't require a root user. @@ -23,4 +23,4 @@ EXPOSE 5000 VOLUME /registry ENV REGISTRY_CONFIGURATION_PATH=/config.yml -CMD DOCKER_REGISTRY_URL=${DOCKER_REGISTRY_SERVICE_HOST}:${DOCKER_REGISTRY_SERVICE_PORT} /usr/bin/dockerregistry ${REGISTRY_CONFIGURATION_PATH} +CMD /usr/bin/dockerregistry ${REGISTRY_CONFIGURATION_PATH} diff --git a/images/dockerregistry/Dockerfile.centos7 b/images/dockerregistry/Dockerfile.centos7 index abd9fa500b46..827c10f09cfb 100644 --- a/images/dockerregistry/Dockerfile.centos7 +++ b/images/dockerregistry/Dockerfile.centos7 @@ -14,14 +14,13 @@ RUN INSTALL_PKGS="origin-dockerregistry" && \ COPY config.yml ${REGISTRY_CONFIGURATION_PATH} LABEL io.k8s.display-name="OpenShift Container Platform Image Registry" \ - io.k8s.description="This is a component ofOpenShift Container Platform and exposes a Docker registry that is integrated with the cluster for authentication and management." \ + io.k8s.description="This is a component of OpenShift Container Platform and exposes a Docker registry that is integrated with the cluster for authentication and management." \ io.openshift.tags="openshift,docker,registry" # The registry doesn't require a root user. USER 1001 EXPOSE 5000 VOLUME /registry -ENV REGISTRY_CONFIGURATION_PATH=/config.yml \ - DOCKER_REGISTRY_URL=${DOCKER_REGISTRY_SERVICE_HOST}:${DOCKER_REGISTRY_SERVICE_PORT} +ENV REGISTRY_CONFIGURATION_PATH=/config.yml CMD /usr/bin/dockerregistry ${REGISTRY_CONFIGURATION_PATH} diff --git a/pkg/dockerregistry/server/blobdescriptorservice_test.go b/pkg/dockerregistry/server/blobdescriptorservice_test.go index 087358d05594..a2045731247a 100644 --- a/pkg/dockerregistry/server/blobdescriptorservice_test.go +++ b/pkg/dockerregistry/server/blobdescriptorservice_test.go @@ -89,7 +89,7 @@ func TestBlobDescriptorServiceIsApplied(t *testing.T) { if err != nil { t.Fatalf("error parsing server url: %v", err) } - os.Setenv("DOCKER_REGISTRY_URL", serverURL.Host) + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host) desc, _, err := registrytest.UploadRandomTestBlob(serverURL, nil, "user/app") if err != nil { diff --git a/pkg/dockerregistry/server/pullthroughblobstore_test.go b/pkg/dockerregistry/server/pullthroughblobstore_test.go index 14f6cfe9879c..1bab88065ad8 100644 --- a/pkg/dockerregistry/server/pullthroughblobstore_test.go +++ b/pkg/dockerregistry/server/pullthroughblobstore_test.go @@ -41,7 +41,7 @@ func TestPullthroughServeBlob(t *testing.T) { if err != nil { t.Fatalf("error parsing server url: %v", err) } - os.Setenv("DOCKER_REGISTRY_URL", serverURL.Host) + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host) testImage.DockerImageReference = fmt.Sprintf("%s/%s@%s", serverURL.Host, repoName, testImage.Name) fos, client := registrytest.NewFakeOpenShiftWithClient() @@ -268,7 +268,7 @@ func TestPullthroughServeNotSeekableBlob(t *testing.T) { if err != nil { t.Fatalf("error parsing server url: %v", err) } - os.Setenv("DOCKER_REGISTRY_URL", serverURL.Host) + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host) testImage, err := registrytest.NewImageForManifest(repoName, registrytest.SampleImageManifestSchema1, "", false) if err != nil { diff --git a/pkg/dockerregistry/server/pullthroughmanifestservice_test.go b/pkg/dockerregistry/server/pullthroughmanifestservice_test.go index 2eee558049df..b0b61427ca50 100644 --- a/pkg/dockerregistry/server/pullthroughmanifestservice_test.go +++ b/pkg/dockerregistry/server/pullthroughmanifestservice_test.go @@ -51,7 +51,7 @@ func createTestRegistryServer(t *testing.T, ctx context.Context) *httptest.Serve if err != nil { t.Fatalf("error parsing server url: %v", err) } - os.Setenv("DOCKER_REGISTRY_URL", serverURL.Host) + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host) return remoteRegistryServer } diff --git a/pkg/dockerregistry/server/repositorymiddleware.go b/pkg/dockerregistry/server/repositorymiddleware.go index d64a7f3c9f73..e7420653b7c5 100644 --- a/pkg/dockerregistry/server/repositorymiddleware.go +++ b/pkg/dockerregistry/server/repositorymiddleware.go @@ -32,8 +32,13 @@ const ( // DockerRegistryURLEnvVar is a mandatory environment variable name specifying url of internal docker // registry. All references to pushed images will be prefixed with its value. + // DEPRECATED: Use the OPENSHIFT_DEFAULT_REGISTRY instead. DockerRegistryURLEnvVar = "DOCKER_REGISTRY_URL" + // OpenShiftDefaultRegistry overrides the DockerRegistryURLEnvVar as in OpenShift the + // default registry URL is controller by this environment variable. + OpenShiftDefaultRegistry = "OPENSHIFT_DEFAULT_REGISTRY" + // EnforceQuotaEnvVar is a boolean environment variable that allows to turn quota enforcement on or off. // By default, quota enforcement is off. It overrides openshift middleware configuration option. // Recognized values are "true" and "false". @@ -165,10 +170,23 @@ func newRepositoryWithClient( repo distribution.Repository, options map[string]interface{}, ) (distribution.Repository, error) { + // TODO: Deprecate this environment variable. registryAddr := os.Getenv(DockerRegistryURLEnvVar) if len(registryAddr) == 0 { - return nil, fmt.Errorf("%s is required", DockerRegistryURLEnvVar) + registryAddr = os.Getenv(OpenShiftDefaultRegistry) + } else { + context.GetLogger(ctx).Infof("DEPRECATED: %q is deprecated, use the %q instead", DockerRegistryURLEnvVar, OpenShiftDefaultRegistry) + } + // TODO: This is a fallback to assuming there is a service named 'docker-registry'. This + // might change in the future and we should make this configurable. + if len(registryAddr) == 0 { + if len(os.Getenv("DOCKER_REGISTRY_SERVICE_HOST")) > 0 && len(os.Getenv("DOCKER_REGISTRY_SERVICE_PORT")) > 0 { + registryAddr = os.Getenv("DOCKER_REGISTRY_SERVICE_HOST") + ":" + os.Getenv("DOCKER_REGISTRY_SERVICE_PORT") + } else { + return nil, fmt.Errorf("%s variable must be set when running outside of Kubernetes cluster", DockerRegistryURLEnvVar) + } } + context.GetLogger(ctx).Infof("Using %q as Docker Registry URL", registryAddr) acceptschema2, err := getBoolOption(AcceptSchema2EnvVar, "acceptschema2", true, options) if err != nil { diff --git a/pkg/dockerregistry/server/signaturedispatcher_test.go b/pkg/dockerregistry/server/signaturedispatcher_test.go index da684b2258ac..332a3c141fc5 100644 --- a/pkg/dockerregistry/server/signaturedispatcher_test.go +++ b/pkg/dockerregistry/server/signaturedispatcher_test.go @@ -86,7 +86,7 @@ func TestSignatureGet(t *testing.T) { if err != nil { t.Fatalf("error parsing server url: %v", err) } - os.Setenv("DOCKER_REGISTRY_URL", serverURL.Host) + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host) url := fmt.Sprintf("http://%s/extensions/v2/user/app/signatures/%s", serverURL.Host, testImage.Name) @@ -189,7 +189,7 @@ func TestSignaturePut(t *testing.T) { if err != nil { t.Fatalf("error parsing server url: %v", err) } - os.Setenv("DOCKER_REGISTRY_URL", serverURL.Host) + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host) signData, err := json.Marshal(testSignature) if err != nil { diff --git a/test/integration/dockerregistry_pullthrough_test.go b/test/integration/dockerregistry_pullthrough_test.go index ce990f163a99..2d4c1349eb1e 100644 --- a/test/integration/dockerregistry_pullthrough_test.go +++ b/test/integration/dockerregistry_pullthrough_test.go @@ -61,7 +61,7 @@ middleware: storage: - name: openshift ` - os.Setenv("DOCKER_REGISTRY_URL", "127.0.0.1:5000") + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", "127.0.0.1:5000") go dockerregistry.Execute(strings.NewReader(config)) diff --git a/test/integration/v2_docker_registry_test.go b/test/integration/v2_docker_registry_test.go index fd7ffe5d8592..99cd2a5fdab8 100644 --- a/test/integration/v2_docker_registry_test.go +++ b/test/integration/v2_docker_registry_test.go @@ -123,7 +123,7 @@ middleware: os.Setenv("OPENSHIFT_CERT_DATA", string(clusterAdminClientConfig.CertData)) os.Setenv("OPENSHIFT_KEY_DATA", string(clusterAdminClientConfig.KeyData)) os.Setenv("OPENSHIFT_MASTER", clusterAdminClientConfig.Host) - os.Setenv("DOCKER_REGISTRY_URL", "127.0.0.1:5000") + os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", "127.0.0.1:5000") go dockerregistry.Execute(strings.NewReader(config))