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

Commit d695902

Browse files
committed
Merge pull request #444 from dotcloud/config-enhance
Config rehaul
2 parents 2f12b06 + 8f55218 commit d695902

File tree

21 files changed

+416
-219
lines changed

21 files changed

+416
-219
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ common:
252252
mirroring:
253253
source: https://registry-1.docker.io
254254
source_index: https://index.docker.io
255-
tags_cache_ttl: 864000 # 10 days
255+
tags_cache_ttl: 172800 # 2 days
256256
```
257257

258258
### Cache options

config/config_mirror.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# The `common' part is automatically included (and possibly overriden by all
22
# other flavors)
3-
common:
3+
common: &common
44
mirroring:
55
source: https://registry-1.docker.io
66
source_index: https://index.docker.io
7-
tags_cache_ttl: 864000 # seconds
7+
tags_cache_ttl: 172800 # seconds
88

99
dev:
10+
<<: *common
1011
storage: local
1112
storage_path: /tmp/registry
1213
loglevel: debug

config/config_sample.yml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
# The `common' part is automatically included (and possibly overriden by all
2-
# other flavors)
3-
common:
4-
loglevel: _env:LOGLEVEL:debug
1+
# All other flavors inherit the `common' config snippet
2+
common: &common
3+
# Default log level is info
4+
loglevel: _env:LOGLEVEL:info
5+
# By default, the registry acts standalone (eg: doesn't query the index)
6+
standalone: _env:STANDALONE:true
7+
# The default endpoint to use (if NOT standalone) is index.docker.io
8+
index_endpoint: _env:INDEX_ENDPOINT:https://index.docker.io
9+
# Storage redirect is disabled
510
storage_redirect: _env:STORAGE_REDIRECT
6-
standalone: true
7-
index_endpoint: _env:INDEX_ENDPOINT
11+
# Token auth is enabled (if NOT standalone)
812
disable_token_auth: _env:DISABLE_TOKEN_AUTH
13+
# No priv key
914
privileged_key: _env:PRIVILEGED_KEY
10-
15+
# No search backend
1116
search_backend: _env:SEARCH_BACKEND
17+
# SQLite search backend
1218
sqlalchemy_index_database: _env:SQLALCHEMY_INDEX_DATABASE:sqlite:////tmp/docker-registry.db
1319

20+
# Mirroring is not enabled
1421
mirroring:
1522
source: _env:MIRROR_SOURCE # https://registry-1.docker.io
1623
source_index: _env:MIRROR_SOURCE_INDEX # https://index.docker.io
17-
tags_cache_ttl: _env:MIRROR_TAGS_CACHE_TTL # 864000 # seconds
24+
tags_cache_ttl: _env:MIRROR_TAGS_CACHE_TTL:172800 # seconds
25+
26+
# cache:
27+
# host: _env:CACHE_REDIS_HOST:localhost
28+
# port: _env:CACHE_REDIS_PORT:6379
29+
# db: 0
30+
# password: _env:CACHE_REDIS_PASSWORD
1831

19-
# Enabling LRU cache for small files. This speeds up read/write on small files
32+
# Enabling LRU cache for small files
33+
# This speeds up read/write on small files
2034
# when using a remote storage backend (like S3).
21-
cache:
22-
host: _env:CACHE_REDIS_HOST
23-
port: _env:CACHE_REDIS_PORT
24-
password: _env:CACHE_REDIS_PASSWORD
25-
cache_lru:
26-
host: _env:CACHE_LRU_REDIS_HOST
27-
port: _env:CACHE_LRU_REDIS_PORT
28-
password: _env:CACHE_LRU_REDIS_PASSWORD
35+
# cache_lru:
36+
# host: _env:CACHE_LRU_REDIS_HOST:localhost
37+
# port: _env:CACHE_LRU_REDIS_PORT:6379
38+
# db: 0
39+
# password: _env:CACHE_LRU_REDIS_PASSWORD
2940

3041
# Enabling these options makes the Registry send an email on each code Exception
3142
email_exceptions:
@@ -40,14 +51,14 @@ common:
4051
# Enable bugsnag (set the API key)
4152
bugsnag: _env:BUGSNAG
4253

43-
44-
4554
local: &local
55+
<<: *common
4656
storage: local
4757
storage_path: _env:STORAGE_PATH:/tmp/registry
4858

4959

5060
s3: &s3
61+
<<: *common
5162
storage: s3
5263
s3_region: _env:AWS_REGION
5364
s3_bucket: _env:AWS_BUCKET
@@ -63,6 +74,7 @@ s3: &s3
6374
# https://developers.google.com/storage/docs/reference/v1/getting-startedv1#keys
6475
# for details on access and secret keys.
6576
gcs:
77+
<<: *common
6678
storage: gcs
6779
boto_bucket: _env:GCS_BUCKET
6880
storage_path: _env:STORAGE_PATH:/registry
@@ -79,6 +91,7 @@ gcs:
7991

8092
# This flavor is for storing images in Openstack Swift
8193
swift: &swift
94+
<<: *common
8295
storage: swift
8396
storage_path: _env:STORAGE_PATH:/registry
8497
# keystone authorization
@@ -92,8 +105,9 @@ swift: &swift
92105
# This flavor stores the images in Glance (to integrate with openstack)
93106
# See also: https://github.com/dotcloud/openstack-docker
94107
glance: &glance
108+
<<: *common
95109
storage: glance
96-
storage_alternate: _env:GLANCE_STORAGE_ALTERNATE:local
110+
storage_alternate: _env:GLANCE_STORAGE_ALTERNATE:file
97111
storage_path: _env:STORAGE_PATH:/tmp/registry
98112

99113
openstack:
@@ -110,6 +124,7 @@ openstack-swift:
110124
<<: *glance-swift
111125

112126
elliptics:
127+
<<: *common
113128
storage: elliptics
114129
elliptics_nodes: _env:ELLIPTICS_NODES
115130
elliptics_wait_timeout: _env:ELLIPTICS_WAIT_TIMEOUT:60
@@ -127,13 +142,15 @@ elliptics:
127142
# This is the default configuration when no flavor is specified
128143
dev: &dev
129144
<<: *local
145+
loglevel: _env:LOGLEVEL:debug
130146
search_backend: _env:SEARCH_BACKEND:sqlalchemy
131147

132-
# This flavor is automatically used by unit tests
148+
# This flavor is used by unit tests
133149
test:
134150
<<: *dev
151+
index_endpoint: https://indexstaging-docker.dotcloud.com
135152
standalone: True
136-
storage_path: _env:STORAGE_PATH:~/tmp/test
153+
storage_path: _env:STORAGE_PATH:./tmp/test
137154

138155
# To specify another flavor, set the environment variable SETTINGS_FLAVOR
139156
# $ export SETTINGS_FLAVOR=prod

depends/docker-registry-core/docker_registry/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
__credits__ = []
4040

4141
__license__ = 'Apache 2.0'
42-
__version__ = '1.0.7'
42+
__version__ = '2.0.0'
4343
__maintainer__ = 'Docker'
4444
__email__ = '[email protected]'
4545
__status__ = 'Production'

depends/docker-registry-core/docker_registry/core/boto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Base(driver.Base):
129129

130130
def __init__(self, path=None, config=None):
131131
self._config = config
132-
self._root_path = config.get('storage_path', '/test')
132+
self._root_path = path or '/test'
133133
self._boto_conn = self.makeConnection()
134134
self._boto_bucket = self._boto_conn.get_bucket(
135135
self._config.boto_bucket)

depends/docker-registry-core/docker_registry/testing/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def __repr__(self):
4242
return repr(self._config)
4343

4444
def __getattr__(self, key):
45-
if key in self._config:
46-
return self._config[key]
45+
if key not in self._config:
46+
return None
47+
return self._config[key]
4748

48-
def get(self, *args, **kwargs):
49-
return self._config.get(*args, **kwargs)
49+
def __getitem__(self, key):
50+
return getattr(self, key)

docker_registry/app.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818

1919
app = flask.Flask('docker-registry')
2020
cfg = config.load()
21-
loglevel = getattr(logging, cfg.get('loglevel', 'INFO').upper())
2221
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
23-
level=loglevel)
22+
level=getattr(logging, cfg.loglevel.upper()))
2423

2524

2625
@app.route('/_ping')
@@ -48,20 +47,20 @@ def after_request(response):
4847
def init():
4948
# Configure the email exceptions
5049
info = cfg.email_exceptions
51-
if info and 'smtp_host' in info:
52-
mailhost = info['smtp_host']
53-
mailport = info.get('smtp_port')
50+
if info and info.smtp_host:
51+
mailhost = info.smtp_host
52+
mailport = info.smtp_port
5453
if mailport:
5554
mailhost = (mailhost, mailport)
56-
smtp_secure = info.get('smtp_secure', None)
55+
smtp_secure = info.smtp_secure
5756
secure_args = _adapt_smtp_secure(smtp_secure)
5857
mail_handler = logging.handlers.SMTPHandler(
5958
mailhost=mailhost,
60-
fromaddr=info['from_addr'],
61-
toaddrs=[info['to_addr']],
59+
fromaddr=info.from_addr,
60+
toaddrs=[info.to_addr],
6261
subject='Docker registry exception',
63-
credentials=(info['smtp_login'],
64-
info['smtp_password']),
62+
credentials=(info.smtp_login,
63+
info.smtp_password),
6564
secure=secure_args)
6665
mail_handler.setLevel(logging.ERROR)
6766
app.logger.addHandler(mail_handler)
@@ -91,9 +90,9 @@ def _adapt_smtp_secure(value):
9190
if isinstance(value, basestring):
9291
# a string - wrap it in the tuple
9392
return (value,)
94-
if isinstance(value, dict):
93+
if isinstance(value, config.Config):
9594
assert set(value.keys()) <= set(['keyfile', 'certfile'])
96-
return (value['keyfile'], value.get('certfile', None))
95+
return (value.keyfile, value.certfile)
9796
if value:
9897
return ()
9998

docker_registry/lib/cache.py

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,48 @@
77

88
from . import config
99

10-
11-
# Default options
10+
logger = logging.getLogger(__name__)
1211

1312
redis_conn = None
1413
cache_prefix = None
1514

15+
cfg = config.load()
16+
1617

1718
def init():
18-
cfg = config.load()
19-
enable_redis_cache(cfg)
20-
enable_redis_lru(cfg)
19+
enable_redis_cache(cfg.cache, cfg.storage_path)
20+
enable_redis_lru(cfg.cache_lru, cfg.storage_path)
2121

2222

23-
def enable_redis_cache(cfg):
23+
def enable_redis_cache(cache, path):
2424
global redis_conn, cache_prefix
25-
cache = cfg.cache
26-
if not cache:
25+
if not cache or not cache.host:
26+
logger.warn('Cache storage disabled!')
2727
return
2828

29-
logging.info('Enabling storage cache on Redis')
30-
if not isinstance(cache, dict):
31-
cache = {}
32-
redis_opts = {
33-
'host': 'localhost',
34-
'port': 6379,
35-
'db': 0,
36-
'password': None
37-
}
38-
for k, v in cache.iteritems():
39-
redis_opts[k] = v
40-
logging.info('Redis config: {0}'.format(redis_opts))
41-
redis_conn = redis.StrictRedis(host=redis_opts['host'],
42-
port=int(redis_opts['port']),
43-
db=int(redis_opts['db']),
44-
password=redis_opts['password'])
45-
cache_prefix = 'cache_path:{0}'.format(cfg.get('storage_path', '/'))
29+
logger.info('Enabling storage cache on Redis')
30+
logger.info('Redis config: {0}'.format(cache))
31+
redis_conn = redis.StrictRedis(
32+
host=cache.host,
33+
port=int(cache.port),
34+
db=int(cache.db),
35+
password=cache.password
36+
)
37+
cache_prefix = 'cache_path:{0}'.format(path or '/')
4638

4739

48-
def enable_redis_lru(cfg):
49-
cache = cfg.cache_lru
50-
if not cache:
40+
def enable_redis_lru(cache, path):
41+
if not cache or not cache.host:
42+
logger.warn('LRU cache disabled!')
5143
return
52-
logging.info('Enabling lru cache on Redis')
53-
if not isinstance(cache, dict):
54-
cache = {}
55-
redis_opts = {
56-
'host': 'localhost',
57-
'port': 6379,
58-
'db': 0,
59-
'password': None
60-
}
61-
for k, v in cache.iteritems():
62-
redis_opts[k] = v
63-
64-
logging.info('Redis lru config: {0}'.format(redis_opts))
44+
logger.info('Enabling lru cache on Redis')
45+
logger.info('Redis lru config: {0}'.format(cache))
6546
lru.init(
66-
host=redis_opts['host'],
67-
port=int(redis_opts['port']),
68-
db=int(redis_opts['db']),
69-
password=redis_opts['password'],
70-
path=cfg.get('storage_path', '/')
47+
host=cache.host,
48+
port=cache.port,
49+
db=cache.db,
50+
password=cache.password,
51+
path=path or '/'
7152
)
7253

7354
init()

0 commit comments

Comments
 (0)