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

Commit d6ffacf

Browse files
committed
Merge pull request #473 from wking/versions-endpoint
docker_registry.app: Add a /_versions endpoint
2 parents a1d0f92 + 65e0e80 commit d6ffacf

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
@@ -37,6 +38,30 @@ def ping():
3738
return toolkit.response(headers=headers)
3839

3940

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

0 commit comments

Comments
 (0)