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

Commit c0f03ca

Browse files
author
shin-
committed
Merge branch 'python-packaging' of github.com:mhrivnak/docker-registry into mhrivnak-python-packaging
Conflicts: docker_registry/app.py docker_registry/images.py registry/__init__.py run.sh test/base.py
2 parents 44af620 + e59fce6 commit c0f03ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+266
-171
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
language: python
22
python:
33
- "2.7"
4-
install: pip install tox
4+
install:
5+
- pip install tox
6+
- pip install .
57
script: tox
68
before_install:
79
- sudo apt-get update

Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ RUN cd /tmp; wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.p
1515
RUN cd /tmp; python ez_setup.py; easy_install pip; \
1616
rm ez_setup.py
1717

18-
ADD requirements.txt /docker-registry/
19-
RUN cd /docker-registry && pip install -r requirements.txt
20-
2118
ADD . /docker-registry
2219
ADD ./config/boto.cfg /etc/boto.cfg
2320

24-
RUN cp --no-clobber /docker-registry/config/config_sample.yml /docker-registry/config/config.yml
21+
RUN pip install /docker-registry/
22+
23+
ENV DOCKER_REGISTRY_CONFIG /docker-registry/config/config_sample.yml
2524

2625
EXPOSE 5000
2726

28-
CMD cd /docker-registry && ./setup-configs.sh && exec ./run.sh
27+
CMD cd /docker-registry && ./setup-configs.sh && exec docker-registry

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ sudo apt-get install build-essential python-dev libevent-dev python-pip libssl-d
349349
Then install the Registry app:
350350
351351
```
352-
sudo pip install -r requirements.txt
352+
sudo pip install .
353353
```
354354
355355
#### On Red Hat-based systems:
@@ -365,13 +365,13 @@ should not require the additional repositories.
365365
Then install the Registry app:
366366
367367
```
368-
sudo python-pip install -r requirements.txt
368+
sudo python-pip install .
369369
```
370370
371371
#### Run it
372372
373373
```
374-
gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5000 -w 1 wsgi:application
374+
gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5000 -w 1 docker_registry.wsgi:application
375375
```
376376
377377
### How do I setup user accounts?
@@ -388,7 +388,7 @@ You could use for instance supervisord to spawn the registry with 8 workers
388388
using this command:
389389
390390
```
391-
gunicorn -k gevent --max-requests 100 --graceful-timeout 3600 -t 3600 -b localhost:5000 -w 8 wsgi:application
391+
gunicorn -k gevent --max-requests 100 --graceful-timeout 3600 -t 3600 -b localhost:5000 -w 8 docker_registry.wsgi:application
392392
```
393393
394394
Note that when using multiple workers, the secret_key for the Flask session

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cd $SERVICE_APPROOT
77
. ~/env/bin/activate
88

99
[ -f requirements.txt ] &&
10-
pip install --download-cache=~/.pip-cache -r requirements.txt || exit 1
10+
pip install --download-cache=~/.pip-cache . || exit 1
1111

1212
cp -R * ~/
1313

docker_registry/__init__.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8 -*-
2+
# flake8: noqa
3+
4+
from __future__ import print_function
5+
6+
# this must happen before anything else
7+
import gevent.monkey
8+
gevent.monkey.patch_all()
9+
10+
from argparse import ArgumentParser
11+
from argparse import RawTextHelpFormatter
12+
import distutils.spawn
13+
import os
14+
import sys
15+
16+
from .app import app
17+
from .tags import *
18+
from .images import *
19+
from .lib import config
20+
from .status import *
21+
22+
cfg = config.load()
23+
if cfg.standalone is not False:
24+
# If standalone mode is enabled (default), load the fake Index routes
25+
from .index import *
26+
27+
28+
DESCRIPTION = """run the docker-registry with gunicorn, honoring the following environment variables:
29+
30+
GUNICORN_WORKERS: number of worker processes gunicorn should start
31+
REGISTRY_PORT: TCP port to bind to on all ipv4 addresses; default is 5000
32+
GUNICORN_GRACEFUL_TIMEOUT: timeout in seconds for graceful worker restart
33+
GUNiCORN_SILENT_TIMEOUT: timeout in seconds for restarting silent workers
34+
"""
35+
36+
37+
def run_gunicorn():
38+
"""
39+
Exec gunicorn with our wsgi app.
40+
41+
Settings are taken from environment variables as listed in the help text.
42+
This is intended to be called as a console_script entry point.
43+
"""
44+
45+
# this only exists to provide help/usage text
46+
parser = ArgumentParser(description=DESCRIPTION,
47+
formatter_class=RawTextHelpFormatter)
48+
parser.parse_args()
49+
50+
workers = os.environ.get('GUNICORN_WORKERS', '4')
51+
port = os.environ.get('REGISTRY_PORT', '5000')
52+
graceful_timeout = os.environ.get('GUNICORN_GRACEFUL_TIMEOUT', '3600')
53+
silent_timeout = os.environ.get('GUNICORN_SILENT_TIMEOUT', '3600')
54+
55+
address = '0.0.0.0:{0}'.format(port)
56+
57+
gunicorn_path = distutils.spawn.find_executable('gunicorn')
58+
if gunicorn_path is None:
59+
print('error: gunicorn executable not found', file=sys.stderr)
60+
sys.exit(1)
61+
62+
os.execl(gunicorn_path, 'gunicorn', '--access-logfile', '-', '--debug',
63+
'--max-requests', '100', '--graceful-timeout', graceful_timeout,
64+
'-t', silent_timeout, '-k', 'gevent', '-b', address, '-w', workers,
65+
'docker_registry.wsgi:application')

registry/app.py renamed to docker_registry/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
bugsnag = None
1010
import flask
1111

12-
import config
13-
import toolkit
12+
from . import toolkit
13+
from .lib import config
1414

1515

1616
VERSION = '0.6.8'

registry/images.py renamed to docker_registry/images.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
import flask
88
import simplejson as json
99

10-
import cache
11-
import checksums
12-
import mirroring
13-
import storage
14-
import toolkit
1510

11+
from . import storage
12+
from . import toolkit
1613
from .app import app
1714
from .app import cfg
18-
import layers
15+
from .lib import cache
16+
from .lib import checksums
17+
from .lib import layers
18+
from .lib import mirroring
19+
from .storage import local
20+
1921

20-
import storage.local
2122
store = storage.load()
2223
logger = logging.getLogger(__name__)
2324

@@ -62,7 +63,7 @@ def _get_image_layer(image_id, headers=None, bytes_range=None):
6263
accel_uri_prefix = cfg.nginx_x_accel_redirect
6364
path = store.image_layer_path(image_id)
6465
if accel_uri_prefix:
65-
if isinstance(store, storage.local.LocalStorage):
66+
if isinstance(store, local.LocalStorage):
6667
accel_uri = '/'.join([accel_uri_prefix, path])
6768
headers['X-Accel-Redirect'] = accel_uri
6869
logger.debug('send accelerated {0} ({1})'.format(

registry/index.py renamed to docker_registry/index.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import flask
44
import simplejson as json
55

6-
import config
7-
import mirroring
8-
import signals
9-
import storage
10-
import toolkit
6+
from . import storage
7+
from . import toolkit
8+
from .lib import config
9+
from .lib import mirroring
10+
from .lib import signals
1111

1212
from .app import app
1313

File renamed without changes.

lib/cache.py renamed to docker_registry/lib/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import redis
44

5-
import config
5+
from . import config
66

77

88
# Default options

0 commit comments

Comments
 (0)