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

Commit c4ead96

Browse files
author
Olivier Gambier
committed
Simpler run/wsgi
run: * no longer require half of the codebase, it's about starting gunicorn * no need for gevent monkey patching (gunicorn gives this) wsgi: * no longer depends on run * monkeypatch only if we need it * search is now conditionnally inserted, like the other index endpoints * debug and log levels are more consistently used Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
1 parent d4cfa79 commit c4ead96

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

docker_registry/run.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,14 @@
22

33
from __future__ import print_function
44

5-
# this must happen before anything else
6-
import gevent.monkey
7-
gevent.monkey.patch_all()
8-
9-
from argparse import ArgumentParser # noqa
10-
from argparse import RawTextHelpFormatter # noqa
11-
5+
import argparse
126
import distutils.spawn
137
import getpass
148
import logging
159
import os
1610
import sys
1711

18-
from .app import app # noqa
19-
from .tags import * # noqa
20-
from .images import * # noqa
21-
from .lib import config
2212
from .server import env
23-
from .status import * # noqa
24-
from .search import * # noqa
25-
26-
cfg = config.load()
27-
if cfg.standalone:
28-
# If standalone mode is enabled, load the fake Index routes
29-
from .index import * # noqa
3013

3114

3215
logger = logging.getLogger(__name__)
@@ -54,8 +37,9 @@ def run_gunicorn():
5437
"""
5538

5639
# this only exists to provide help/usage text
57-
parser = ArgumentParser(description=DESCRIPTION,
58-
formatter_class=RawTextHelpFormatter)
40+
parser = argparse.ArgumentParser(
41+
description=DESCRIPTION,
42+
formatter_class=argparse.RawTextHelpFormatter)
5943
parser.parse_args()
6044

6145
gunicorn_path = distutils.spawn.find_executable('gunicorn')

docker_registry/wsgi.py

100755100644
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
import logging
4+
# only needed if not using gunicorn gevent
5+
if __name__ == '__main__':
6+
import gevent.monkey
7+
gevent.monkey.patch_all()
58

9+
# start new relic if instructed to do so
610
from .extras import newrelic
711
from .server import env
812
newrelic.boot(env.source('NEW_RELIC_INI'), env.source('NEW_RELIC_STAGE'))
913

1014
from .extensions import factory
1115
factory.boot()
12-
from .run import app
16+
17+
import logging
18+
19+
from .app import app # noqa
20+
from .tags import * # noqa
21+
from .images import * # noqa
22+
from .lib import config
23+
24+
cfg = config.load()
25+
26+
if cfg.search_backend:
27+
from .search import * # noqa
28+
29+
if cfg.standalone:
30+
# If standalone mode is enabled, load the fake Index routes
31+
from .index import * # noqa
1332

1433
if __name__ == '__main__':
15-
# Bind to PORT if defined, otherwise default to 5000.
1634
host = env.source('REGISTRY_HOST')
1735
port = env.source('REGISTRY_PORT')
18-
app.debug = True
36+
app.debug = cfg.debug
1937
app.run(host=host, port=port)
2038
else:
21-
# For uwsgi
22-
app.logger.setLevel(logging.INFO)
39+
level = cfg.loglevel.upper()
40+
if not hasattr(logging, level):
41+
level = 'INFO'
42+
level = getattr(logging, level)
43+
app.logger.setLevel(level)
2344
stderr_logger = logging.StreamHandler()
24-
stderr_logger.setLevel(logging.INFO)
45+
stderr_logger.setLevel(level)
2546
stderr_logger.setFormatter(
2647
logging.Formatter('%(asctime)s %(levelname)s: %(message)s'))
2748
app.logger.addHandler(stderr_logger)
28-
2949
application = app

0 commit comments

Comments
 (0)