Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 65e0e80

Browse files
committed
docker_registry.app: Add a /_versions endpoint
For debugging it's good to know what package versions folks are running. This endpoint allows folks using floating dependencies (or just different versions of docker-registry) to figure out the exact version of all of their Python dependencies. The only basic dependency that *doesn't* define a __version__ is itsdangerous (as of v0.24), which doesn't provide a programmatically-accessible version number. I haven't checked all the peripheral dependencies outside of what gets pulled in by a stock: $ pip install depends/docker-registry-core/ $ pip install . To avoid accidentally leaking implementation details, the /_versions endpoint is disabled in the common config_sample.yml block, and only enabled by default in the dev block. In both cases, you can use the DEBUG_VERSIONS environment variable to enable/disable the endpoint for your particular instance.
1 parent 80459cd commit 65e0e80

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ When using the `config_sample.yml`, you can pass all options through as environm
149149
1. `loglevel`: string, level of debugging. Any of python's
150150
[logging](http://docs.python.org/2/library/logging.html) module levels:
151151
`debug`, `info`, `warn`, `error` or `critical`
152+
1. `debug_versions`: boolean, enable the `/_versions` endpoint for debugging.
152153
1. `storage_redirect`: Redirect resource requested if storage engine supports
153154
this, e.g. S3 will redirect signed URLs, this can be used to offload the
154155
server.

config/config_sample.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
common: &common
33
# Default log level is info
44
loglevel: _env:LOGLEVEL:info
5+
# Enable the debugging /_versions endpoint
6+
debug_versions: _env:DEBUG_VERSIONS:false
57
# By default, the registry acts standalone (eg: doesn't query the index)
68
standalone: _env:STANDALONE:true
79
# The default endpoint to use (if NOT standalone) is index.docker.io
@@ -143,6 +145,7 @@ elliptics:
143145
dev: &dev
144146
<<: *local
145147
loglevel: _env:LOGLEVEL:debug
148+
debug_versions: _env:DEBUG_VERSIONS:true
146149
search_backend: _env:SEARCH_BACKEND:sqlalchemy
147150

148151
# This flavor is used by unit tests

docker_registry/app.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import logging.handlers
55
import os
6+
import sys
67

78
try:
89
import bugsnag
@@ -32,6 +33,30 @@ def ping():
3233
return toolkit.response(headers=headers)
3334

3435

36+
@app.route('/_versions')
37+
@app.route('/v1/_versions')
38+
def versions():
39+
"""Return a JSON object ({"package-name": "package-version", ...}).
40+
41+
This is an unofficial endpoint for debugging your docker-registry
42+
install. If you're running a publicly-accessible endpoint, it's
43+
probably best to disable this endpoint to avoid leaking
44+
implementation details.
45+
"""
46+
versions = {}
47+
if cfg.debug_versions:
48+
for name, module in sys.modules.items():
49+
if name.startswith('_'):
50+
continue
51+
try:
52+
version = module.__version__
53+
except AttributeError:
54+
continue
55+
versions[name] = version
56+
versions['python'] = sys.version
57+
return toolkit.response(versions)
58+
59+
3560
@app.route('/')
3661
def root():
3762
return toolkit.response('docker-registry server ({0}) (v{1})'

0 commit comments

Comments
 (0)