Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyseek committed Jun 8, 2015
2 parents d756b3c + e028a3c commit 6d4c548
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.2.0
files = setup.py flask_docker.py docs/conf.py
commit = True
tag = False
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.rst
@@ -0,0 +1,14 @@
Changelog
---------

0.2.0 - 2015-06-08
~~~~~~~~~~~~~~~~~~

* Make ``app`` attribute always be accessible in :class:`flask_docker.Docker`.
* Add ``zip_safe=False`` flag to ``setup.py``.
* Fix some description in the document.

0.1.0 - 2015-02-01
~~~~~~~~~~~~~~~~~~

* Initial release.
10 changes: 7 additions & 3 deletions README.rst
Expand Up @@ -3,13 +3,17 @@
Flask-Docker
============

Flask-Docker is an extension for Flask_ that integrates a Docker_ client into
your application. It is based on the official docker-py_.
Flask-Docker is an extension for Flask_ that integrates Docker_ client into
your application. It is based on the official client docker-py_.

.. _Flask: http://flask.pocoo.org
.. _Docker: https://www.docker.com
.. _docker-py: https://github.com/docker/docker-py#readme

The document is in ReadTheDocs_.

.. _ReadTheDocs: https://flask-docker.readthedocs.org


Installation
------------
Expand Down Expand Up @@ -40,7 +44,7 @@ You can send a pull reueqst on
.. |Coverage Status| image:: https://img.shields.io/coveralls/tonyseek/flask-docker.svg?style=flat
:target: https://coveralls.io/r/tonyseek/flask-docker
:alt: Coverage Status
.. |Wheel Status| image:: https://pypip.in/wheel/Flask-Docker/badge.svg?style=flat
.. |Wheel Status| image:: https://img.shields.io/pypi/wheel/Flask-Docker.svg?style=flat
:target: https://warehouse.python.org/project/Flask-Docker
:alt: Wheel Status
.. |PyPI Version| image:: https://img.shields.io/pypi/v/Flask-Docker.svg?style=flat
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -55,9 +55,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1.0'
version = '0.2.0'
# The full version, including alpha/beta/rc tags.
release = '0.1.0'
release = '0.2.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
14 changes: 7 additions & 7 deletions docs/index.rst
Expand Up @@ -19,7 +19,7 @@ Installation
Configuration
-------------

You can configure it like mostly extensions of Flask.
You can configure it like most extensions of Flask.

For single file applications:

Expand Down Expand Up @@ -52,7 +52,6 @@ For large applications which following the application factory pattern:
The Flask-Docker has some configuration values that describes how to connect
to the Docker server.


============================ ==================================================
`DOCKER_URL` The URL of Docker server. **REQUIRED**
`DOCKER_VERSION` The API version of Docker server.
Expand All @@ -76,8 +75,8 @@ to the Docker server.
certificate.
Because the client certificate have two files (a
public and a private), this configuration value
should be a tuple of their path. (e.g.
``('/path/to/cert.pem', '/path/to/key.pem')``)
should be a colon-separated tuple of their path.
(e.g. ``"/path/to/cert.pem:/path/to/key.pem"``)
This defaults to ``None``.
`DOCKER_TLS_CA_CERT` The file path to the CA certificate.
It is usually be used with a self-signed
Expand All @@ -86,9 +85,8 @@ to the Docker server.
`DOCKER_TLS_CERT_PATH` This defaults to ``None``. Once it be specified,
The default value of `DOCKER_TLS_CLIENT_CERT` and
`DOCKER_TLS_CA_CERT` will be filled to
``("{DOCKER_TLS_CERT_PATH}/cert.pem",
"{DOCKER_TLS_CERT_PATH}/key.pem")`` and
``"{DOCKER_TLS_CERT_PATH}/ca.pem"`` instead of
``"{0}/cert.pem:{0}/key.pem"`` and
``"{0}/ca.pem"`` instead of
``None``. It is usually be used with boot2docker_.
============================ ==================================================

Expand Down Expand Up @@ -146,3 +144,5 @@ API Reference

.. autoclass:: flask_docker.Docker
:members:

.. include:: ../CHANGELOG.rst
24 changes: 12 additions & 12 deletions flask_docker.py
Expand Up @@ -6,7 +6,7 @@


__all__ = ['Docker']
__version__ = '0.1.0'
__version__ = '0.2.0'


class Docker(object):
Expand All @@ -17,7 +17,9 @@ class Docker(object):
"""

def __init__(self, app=None):
if app:
if app is None:
self.app = current_app
else:
self.app = app
self.init_app(app)

Expand Down Expand Up @@ -49,18 +51,16 @@ def client(self):
docker.create_container('ubuntu')
docker.client.create_container('ubuntu') # equivalent
"""
app = getattr(self, 'app', current_app)

if not app.config['DOCKER_URL']:
if not self.app.config['DOCKER_URL']:
raise RuntimeError('"DOCKER_URL" must be specified')

if not app.extensions['docker.client']:
app.extensions['docker.client'] = Client(
base_url=app.config['DOCKER_URL'],
version=app.config['DOCKER_VERSION'],
timeout=app.config['DOCKER_TIMEOUT'],
tls=make_tls_config(app.config))
return app.extensions['docker.client']
if not self.app.extensions['docker.client']:
self.app.extensions['docker.client'] = Client(
base_url=self.app.config['DOCKER_URL'],
version=self.app.config['DOCKER_VERSION'],
timeout=self.app.config['DOCKER_TIMEOUT'],
tls=make_tls_config(self.app.config))
return self.app.extensions['docker.client']

def __getattr__(self, name):
if name != 'app' and hasattr(self.client, name):
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Expand Up @@ -9,9 +9,9 @@

setup(
name='Flask-Docker',
description='Uses Docker client in your Flask application.',
description='Using Docker client in your Flask application.',
long_description=long_description,
version='0.1.0',
version='0.2.0',
author='Jiangge Zhang',
author_email='tonyseek@gmail.com',
url='https://github.com/tonyseek/flask-docker',
Expand All @@ -29,9 +29,12 @@
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities',
],
zip_safe=False,
py_modules=['flask_docker'],
install_requires=['flask', 'docker-py'],
platforms=['Any'])
29 changes: 18 additions & 11 deletions tests/test_factory.py
@@ -1,4 +1,4 @@
from flask import Flask
from flask import Flask, current_app
from flask_docker import Docker
from pytest import fixture, raises
import responses
Expand All @@ -14,7 +14,7 @@ def create_app():


@fixture
def current_app(request):
def app(request):
app = create_app()
ctx = app.app_context()
ctx.push()
Expand All @@ -23,42 +23,49 @@ def current_app(request):


def test_factory():
assert not hasattr(docker, 'app')
assert docker.app is current_app


def test_out_of_context():
docker.app # nothing raises

# but if we...
with raises(RuntimeError) as error:
docker.app.name
assert error.value.args[0] == 'working outside of application context'

with raises(RuntimeError) as error:
docker.client
assert error.value.args[0] == 'working outside of application context'


def test_url_missing(current_app):
def test_url_missing(app):
with raises(RuntimeError) as error:
docker.client
assert error.value.args[0] == '"DOCKER_URL" must be specified'


@responses.activate
def test_versioned(current_app):
def test_versioned(app):
responses.add(
responses.GET, 'http://docker-testing:2375/v1.11/info',
body='{"message": "Yo! Gotcha."}', status=200,
content_type='application/json')
current_app.config['DOCKER_URL'] = 'http://docker-testing:2375'
current_app.config['DOCKER_VERSION'] = '1.11'
app.config['DOCKER_URL'] = 'http://docker-testing:2375'
app.config['DOCKER_VERSION'] = '1.11'

assert docker.client.info() == {'message': 'Yo! Gotcha.'}


def test_lazy_creation(current_app):
current_app.config['DOCKER_URL'] = 'http://docker-testing:2375'
def test_lazy_creation(app):
app.config['DOCKER_URL'] = 'http://docker-testing:2375'

assert current_app.extensions['docker.client'] is None
assert app.extensions['docker.client'] is None

client1 = docker.client
client2 = docker.client

assert current_app.extensions['docker.client'] is client1 is client2
assert app.extensions['docker.client'] is client1 is client2


def test_isolation():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_simple.py
@@ -1,4 +1,4 @@
from flask import Flask
from flask import Flask, current_app
from flask_docker import Docker
from pytest import fixture, raises
import responses
Expand All @@ -13,6 +13,7 @@ def docker():

def test_singleton(docker):
assert docker.app
assert docker.app is not current_app


def test_url_missing(docker):
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py33,py34,pypy
envlist = py27,py33,py34,pypy,docs
[testenv]
deps =
setuptools>=12.0
Expand All @@ -10,3 +10,11 @@ deps =
responses
commands =
py.test
[testenv:docs]
changedir = docs
deps =
--requirement=docs/requirements.txt
whitelist_externals =
make
commands =
make html

0 comments on commit 6d4c548

Please sign in to comment.