From 9998ecd5ac675a74d7bcbbfcc2df62ce58a97029 Mon Sep 17 00:00:00 2001 From: Charles Butler Date: Wed, 23 Mar 2016 20:40:22 -0400 Subject: [PATCH 1/6] Module Restructuring This commit restructures the core of charms.docker to follow the python best practice of import modules in the __init__.py file for a nicer UX You can now import like so: `from charms.docker import Compose` or `from charms.docker import DockerOpts` This also brings with it a pretty hefty update to the Compose class, implementing methods and tests for the following methods: - start - stop - pull - restart - build - scale It also splits apart the private __run method into a separate module known as 'runner'. --- charms/docker/__init__.py | 91 ++----------------------- charms/docker/compose.py | 124 ++++++++++++++++++++++++----------- charms/docker/docker.py | 87 ++++++++++++++++++++++++ charms/docker/dockeropts.py | 18 +++-- charms/docker/runner.py | 31 +++++++++ tests/test_docker_compose.py | 108 +++++++++++++++++++++++------- 6 files changed, 303 insertions(+), 156 deletions(-) create mode 100644 charms/docker/docker.py create mode 100644 charms/docker/runner.py diff --git a/charms/docker/__init__.py b/charms/docker/__init__.py index 58166a9..9231952 100644 --- a/charms/docker/__init__.py +++ b/charms/docker/__init__.py @@ -1,87 +1,4 @@ -import os -import subprocess - -from shlex import split - -from .workspace import Workspace - - -class Docker: - ''' - Wrapper class to communicate with the Docker daemon on behalf of - a charmer. Provides stateless operations of a running docker daemon - ''' - - def __init__(self, socket="unix:///var/run/docker.sock", workspace=None): - ''' - @param socket - URI to the Docker daemon socket - default: unix://var/run/docker.sock - - @param workspace - Path to directory containing a Dockerfile - default: None - ''' - self.socket = socket - if workspace: - self.workspace = Workspace(workspace) - - def running(self): - ''' - Predicate method to determine if the daemon we are talking to is - actually online and recieving events. - - ex: bootstrap = Docker(socket="unix://var/run/docker-boostrap.sock") - bootstrap.running() - > True - ''' - # TODO: Add TCP:// support for running check - return os.path.isfile(self.socket) - - def run(self, image, options=[], commands=[], arg=[]): - ''' - Docker Run exposed as a method. This wont be as natural as the - command line docker experience. - - Docker CLI output example: - Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] - - @param image - string of the container to pull from the registry, - eg: ubuntu:latest - @param options - array of string options, eg: ['-d', '-v /tmp:/tmp'] - @param commands - array of string commands, eg: ['ls'] - @param arg - array of string command args, eg: ['-al'] - ''' - options = ' '.join(options) - command = ' '.join(commands) - args = ' '.join(arg) - cmd = "docker run {0} {1} {2} {3}".format( - options, image, command, args) - - try: - subprocess.check_output(split(cmd)) - except subprocess.CalledProcessError as expect: - print("Error: ", expect.returncode, expect.output) - - def login(self, user, password, email): - ''' - Docker login exposed as a method. - - @param user - Username in the registry - @param password - Password for the registry - @param email - Email address on account (dockerhub) - ''' - cmd = ['docker', 'login', '-u', user, '-p', password, '-e', email] - subprocess.check_call(cmd) - - def ps(self): - ''' - return a string of docker status output - ''' - cmd = ['docker', 'ps'] - return subprocess.check_output(cmd) - - def pull(self, image): - ''' - Pull an image from the docker hub - ''' - cmd = ['docker', 'pull', image] - return subprocess.check_output(cmd) +from .docker import Docker # noqa +from .compose import Compose # noqa +from .dockeropts import DockerOpts # noqa +from .workspace import Workspace # noqa diff --git a/charms/docker/compose.py b/charms/docker/compose.py index 17e6577..9d45380 100644 --- a/charms/docker/compose.py +++ b/charms/docker/compose.py @@ -1,8 +1,4 @@ -import os - -from contextlib import contextmanager -from shlex import split -from subprocess import check_output +from .runner import run from .workspace import Workspace @@ -13,75 +9,125 @@ def __init__(self, workspace, strict=True): a natural language for performing common tasks with docker in juju charms. - @param workspace - Define the CWD for docker-compose execution + :param workspace: Define the CWD for docker-compose execution - @param strict - Enable/disable workspace validation + :param strict: - Enable/disable workspace validation ''' self.workspace = Workspace(workspace) if strict: self.workspace.validate() - def up(self, service=None): + def build(self, service=None, force_rm=True, no_cache=False, pull=False): ''' - Convenience method that wraps `docker-compose up` + Build or rebuild services. - usage: c.up('nginx') to start the 'nginx' service from the - defined `docker-compose.yml` as a daemon + Services are built once and then tagged as `project_service`. If you + change a service's Dockerfile or the contents of its build directory + you can invoke this method to rebuild it. + + :param service: if provided will rebuild scoped to that service + :param force_rm: Always remove intermediate containers. + :param no_cache: Do not use cache when building the image + :param pull: Always attempt to pull a newer version of the image ''' + cmd = "docker-compose build" + + if force_rm: + cmd = "{} --force-rm".format(cmd) + if no_cache: + cmd = "{} --no-cache".format(cmd) + if pull: + cmd = "{} --pull".format(cmd) if service: - cmd = "docker-compose up -d {}".format(service) - else: - cmd = "docker-compose up -d" - self.run(cmd) + cmd = "{} {}".format(cmd, service) + + run(cmd, self.workspace) def kill(self, service=None): ''' Convenience method that wraps `docker-compose kill` - usage: c.kill('nginx') to kill the 'nginx' service from the - defined `docker-compose.yml` + :param service: if defined will only kill that service. ''' if service: cmd = "docker-compose kill {}".format(service) else: cmd = "docker-compose kill" - self.run(cmd) + run(cmd, self.workspace) + + def pull(self, service=None): + ''' + Pulls service images + + :param service: if defined, only pulls the image for specified service. + ''' + if service: + cmd = "docker-compose pull {}".format(service) + else: + cmd = "docker-compose pull" + run(cmd, self.workspace) + + def restart(self, service=None): + ''' + Restart services + + :param service: if defined, only restarts the specified service. + ''' + if service: + cmd = "docker-compose restart {}".format(service) + else: + cmd = "docker-compose restart" + run(cmd, self.workspace) def rm(self, service=None): ''' Convenience method that wraps `docker-compose rm` - usage: c.rm('nginx') to remove the 'nginx' service from the - defined `docker-compose.yml` + :param service: if defined only the specified service. ''' if service: cmd = "docker-compose rm -f {}".format(service) else: cmd = "docker-compose rm -f" - self.run(cmd) + run(cmd, self.workspace) - def run(self, cmd): + def scale(self, service, count): ''' - chdir sets working context on the workspace + Set number of containers to run for a service. - @param: cmd - String of the command to run. eg: echo "hello world" - the string is passed through shlex.parse() for convenience. + :param service: Service to scale as defined in docker-compose.yml + :param count: number of containers to scale + ''' + cmd = "docker-compose scale {}={}".format(service, count) + run(cmd, self.workspace) - returns STDOUT of command execution + def start(self, service): + ''' + Start existing containers - usage: c.run('docker-compose ps') + :param service: Service to start ''' - with chdir("{}".format(self.workspace)): - out = check_output(split(cmd)) - return out + cmd = "docker-compose start {}".format(service) + run(cmd, self.workspace) + def stop(self, service, timeout=10): + ''' + Stop running containers without removing them. + + :param service: Service to stop. + :param timeout: specify a shutdown timeout in seconds. + ''' + cmd = "docker-compose stop -t {} {}".format(timeout, service) + run(cmd, self.workspace) -# This is helpful for setting working directory context -@contextmanager -def chdir(path): - '''Change the current working directory to a different directory to run - commands and return to the previous directory after the command is done.''' - old_dir = os.getcwd() - os.chdir(path) - yield - os.chdir(old_dir) + def up(self, service=None): + ''' + Convenience method that wraps `docker-compose up` + + :param service: if defined only launches the specified service + ''' + if service: + cmd = "docker-compose up -d {}".format(service) + else: + cmd = "docker-compose up -d" + run(cmd, self.workspace) diff --git a/charms/docker/docker.py b/charms/docker/docker.py new file mode 100644 index 0000000..3a39056 --- /dev/null +++ b/charms/docker/docker.py @@ -0,0 +1,87 @@ +import os +import subprocess + +from shlex import split + +from .workspace import Workspace + + +class Docker: + ''' + Wrapper class to communicate with the Docker daemon on behalf of + a charmer. Provides stateless operations of a running docker daemon + ''' + + def __init__(self, socket="unix:///var/run/docker.sock", workspace=None): + ''' + :param socket: URI to the Docker daemon socket + default: unix://var/run/docker.sock + + :param workspace: Path to directory containing a Dockerfile + default: None + ''' + self.socket = socket + if workspace: + self.workspace = Workspace(workspace) + + def running(self): + ''' + Predicate method to determine if the daemon we are talking to is + actually online and recieving events. + + ex: bootstrap = Docker(socket="unix://var/run/docker-boostrap.sock") + bootstrap.running() + > True + ''' + # TODO: Add TCP:// support for running check + return os.path.isfile(self.socket) + + def run(self, image, options=[], commands=[], arg=[]): + ''' + Docker Run exposed as a method. This wont be as natural as the + command line docker experience. + + Docker CLI output example: + Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] + + :param image: string of the container to pull from the registry, + eg: ubuntu:latest + :param options: array of string options, eg: ['-d', '-v /tmp:/tmp'] + :param commands: array of string commands, eg: ['ls'] + :param arg: array of string command args, eg: ['-al'] + ''' + options = ' '.join(options) + command = ' '.join(commands) + args = ' '.join(arg) + cmd = "docker run {0} {1} {2} {3}".format( + options, image, command, args) + + try: + subprocess.check_output(split(cmd)) + except subprocess.CalledProcessError as expect: + print("Error: ", expect.returncode, expect.output) + + def login(self, user, password, email): + ''' + Docker login exposed as a method. + + :param user: Username in the registry + :param password: - Password for the registry + :param email: - Email address on account (dockerhub) + ''' + cmd = ['docker', 'login', '-u', user, '-p', password, '-e', email] + subprocess.check_call(cmd) + + def ps(self): + ''' + return a string of docker status output + ''' + cmd = ['docker', 'ps'] + return subprocess.check_output(cmd) + + def pull(self, image): + ''' + Pull an image from the docker hub + ''' + cmd = ['docker', 'pull', image] + return subprocess.check_output(cmd) diff --git a/charms/docker/dockeropts.py b/charms/docker/dockeropts.py index d6b0aea..afc0476 100644 --- a/charms/docker/dockeropts.py +++ b/charms/docker/dockeropts.py @@ -2,8 +2,8 @@ class DockerOpts: - - ''' DockerOptsManager - A Python class for managing the DEFAULT docker + ''' + DockerOptsManager - A Python class for managing the DEFAULT docker options on a daemon dynamically. As a docker daemon integrates with more services it becomes quickly unweidly to just "template and go" for this solution. Having a data bag to stuff in options/multioptions and render to @@ -14,7 +14,7 @@ class DockerOpts: Summary: opts = DockerOpts() - opts.add('mtu', flannel_mtu) + opts.add('bip', '192.168.22.2') opts.to_s() ''' @@ -29,7 +29,8 @@ def __save(self): self.db.set('docker_opts', self.data) def add(self, key, value): - ''' Adds data to the map of values for the DockerOpts file. + ''' + Adds data to the map of values for the DockerOpts file. Supports single values, or "multiopt variables" eg: @@ -50,17 +51,22 @@ def add(self, key, value): self.__save() def remove(self, key, value): - ''' Remove a flag value from the DockerOpts manager + ''' + Remove a flag value from the DockerOpts manager Assuming the data is currently {'foo': ['bar', 'baz']} d.remove('foo', 'bar') > {'foo': ['baz']} + + :params key: + :params value: ''' self.data[key].remove(value) self.__save() def to_s(self): - ''' Render the flags to a single string, prepared for the Docker + ''' + Render the flags to a single string, prepared for the Docker Defaults file. Typically in /etc/default/docker d.to_s() diff --git a/charms/docker/runner.py b/charms/docker/runner.py new file mode 100644 index 0000000..ff491f7 --- /dev/null +++ b/charms/docker/runner.py @@ -0,0 +1,31 @@ +from contextlib import contextmanager +from shlex import split +from subprocess import check_output +import os + + +def run(cmd, workspace): + ''' + wrapper for executing the commands generated by the class members. + commands are passed through shlex.parse for convenience. + + :param cmd: - String of the command to run. eg: echo "hello world". + + :returns: STDOUT of command execution + + :usage: c.run('docker-compose ps') + ''' + with chdir("{}".format(workspace)): + out = check_output(split(cmd)) + return out + + +# This is helpful for setting working directory context +@contextmanager +def chdir(path): + '''Change the current working directory to a different directory to run + commands and return to the previous directory after the command is done.''' + old_dir = os.getcwd() + os.chdir(path) + yield + os.chdir(old_dir) diff --git a/tests/test_docker_compose.py b/tests/test_docker_compose.py index aeaf5e3..05db558 100644 --- a/tests/test_docker_compose.py +++ b/tests/test_docker_compose.py @@ -1,8 +1,8 @@ -from charms.docker.compose import Compose -from charms.docker import compose +from charms.docker import Compose from mock import patch import pytest + class TestCompose: # This has limited usefulness, it fails when used with the @patch @@ -14,51 +14,111 @@ def compose(self): def test_init_strict(self): with patch('charms.docker.compose.Workspace.validate') as f: - c = Compose('test', strict=True) + Compose('test', strict=True) # Is this the beast? is mock() doing the right thing here? f.assert_called_with() def test_init_workspace(self, compose): assert "{}".format(compose.workspace) == "files/test" - def test_start_service(self, compose): - with patch('charms.docker.compose.Compose.run') as s: - compose.up('nginx') - expect = 'docker-compose up -d nginx' - s.assert_called_with(expect) + def test_build(self, compose): + with patch('charms.docker.compose.run') as s: + compose.build() + s.assert_called_with('docker-compose build --force-rm', + compose.workspace) + compose.build('foobar') + expect = 'docker-compose build --force-rm foobar' + s.assert_called_with(expect, compose.workspace) - def test_start_default_formation(self, compose): - with patch('charms.docker.compose.Compose.run') as s: - compose.up() - expect = 'docker-compose up -d' - s.assert_called_with(expect) + compose.build('foobar', no_cache=True, pull=True) + expect = 'docker-compose build --force-rm --no-cache --pull foobar' + s.assert_called_with(expect, compose.workspace) + + compose.build('foobar', force_rm=False) + expect = 'docker-compose build foobar' + s.assert_called_with(expect, compose.workspace) + + compose.build(no_cache=True) + expect = 'docker-compose build --force-rm --no-cache' def test_kill_service(self, compose): - with patch('charms.docker.compose.Compose.run') as s: + with patch('charms.docker.compose.run') as s: compose.kill('nginx') expect = 'docker-compose kill nginx' - s.assert_called_with(expect) + s.assert_called_with(expect, compose.workspace) def test_kill_service_default(self, compose): - with patch('charms.docker.compose.Compose.run') as s: + with patch('charms.docker.compose.run') as s: compose.kill() expect = 'docker-compose kill' - s.assert_called_with(expect) + s.assert_called_with(expect, compose.workspace) + + def test_pull_service(self, compose): + with patch('charms.docker.compose.run') as s: + compose.pull('nginx') + s.assert_called_with('docker-compose pull nginx', + compose.workspace) + + def test_pull_service_default(self, compose): + with patch('charms.docker.compose.run') as s: + compose.pull() + s.assert_called_with('docker-compose pull', compose.workspace) + + def test_restart(self, compose): + with patch('charms.docker.compose.run') as s: + compose.restart('nginx') + s.assert_called_with('docker-compose restart nginx', + compose.workspace) + + def test_restart_default(self, compose): + with patch('charms.docker.compose.run') as s: + compose.restart() + s.assert_called_with('docker-compose restart', compose.workspace) + + def test_up_service(self, compose): + with patch('charms.docker.compose.run') as s: + compose.up('nginx') + expect = 'docker-compose up -d nginx' + s.assert_called_with(expect, compose.workspace) + + def test_up_default_formation(self, compose): + with patch('charms.docker.compose.run') as s: + compose.up() + expect = 'docker-compose up -d' + s.assert_called_with(expect, compose.workspace) + + def test_start_service(self, compose): + with patch('charms.docker.compose.run') as s: + compose.start('nginx') + expect = 'docker-compose start nginx' + s.assert_called_with(expect, compose.workspace) def test_rm_service_default(self, compose): - with patch('charms.docker.compose.Compose.run') as s: + with patch('charms.docker.compose.run') as s: compose.rm() expect = 'docker-compose rm -f' - s.assert_called_with(expect) + s.assert_called_with(expect, compose.workspace) def test_rm_service(self, compose): - with patch('charms.docker.compose.Compose.run') as s: + with patch('charms.docker.compose.run') as s: compose.rm('nginx') expect = 'docker-compose rm -f nginx' - s.assert_called_with(expect) + s.assert_called_with(expect, compose.workspace) + + def test_scale(self, compose): + with patch('charms.docker.compose.run') as s: + compose.scale('nginx', 3) + expect = 'docker-compose scale nginx=3' + s.assert_called_with(expect, compose.workspace) + + def test_stop_service(self, compose): + with patch('charms.docker.compose.run') as s: + compose.stop('nginx') + expect = 'docker-compose stop -t 10 nginx' + s.assert_called_with(expect, compose.workspace) - @patch('charms.docker.compose.chdir') - @patch('charms.docker.compose.check_output') + @patch('charms.docker.runner.chdir') + @patch('charms.docker.runner.check_output') def test_run(self, ccmock, chmock): compose = Compose('files/workspace', strict=False) compose.up('nginx') @@ -71,7 +131,7 @@ def test_context_manager(self, cwdmock): cwdmock.return_value = '/tmp' with patch('os.chdir') as chmock: compose = Compose('files/workspace', strict=False) - with patch('charms.docker.compose.check_output'): + with patch('charms.docker.runner.check_output'): compose.up('nginx') # We can only test the return called with in this manner. # So check that we at least reset context From db2fdb9640f6d291516ae62ad871283e4c09db2e Mon Sep 17 00:00:00 2001 From: Charles Butler Date: Wed, 23 Mar 2016 20:41:14 -0400 Subject: [PATCH 2/6] Adds VERSION file to track project version --- VERSION | 1 + setup.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..c5d54ec --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.9 diff --git a/setup.py b/setup.py index 7955893..9df7ea2 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,18 @@ import os from setuptools import setup +version_file = os.path.abspath( + os.path.join( + os.path.dirname(os.path.dirname(__file__)), 'VERSION')) + +with open(version_file) as v: + VERSION = v.read().strip() + + + setup( name = "charms.docker", - version = "0.0.8", + version = VERSION, author = "Charles Butler", author_email = "charles.butler@ubuntu.com", url = "http://github.com/juju-solutions/charms.docker", From 3de5650bd52f6e1457aed4b9fdd7168dc4ec333a Mon Sep 17 00:00:00 2001 From: Charles Butler Date: Wed, 23 Mar 2016 20:44:36 -0400 Subject: [PATCH 3/6] bump to 0.1.0 per PR --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index c5d54ec..6e8bf73 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.9 +0.1.0 From aaad87f846df406f397472c5c92db3dd10516d04 Mon Sep 17 00:00:00 2001 From: Charles Butler Date: Wed, 23 Mar 2016 22:31:48 -0400 Subject: [PATCH 4/6] Docs to accompany the 0.1.0 release --- Makefile | 23 +++ docs/Makefile | 216 ++++++++++++++++++++++++ docs/source/charms.docker.rst | 46 ++++++ docs/source/conf.py | 303 ++++++++++++++++++++++++++++++++++ docs/source/index.rst | 37 +++++ docs/source/installation.rst | 39 +++++ docs/source/modules.rst | 7 + docs/source/quickstart.rst | 0 docs/test/charms.docker.rst | 46 ++++++ docs/test/charms.rst | 17 ++ docs/test/modules.rst | 7 + 11 files changed, 741 insertions(+) create mode 100644 Makefile create mode 100644 docs/Makefile create mode 100644 docs/source/charms.docker.rst create mode 100644 docs/source/conf.py create mode 100644 docs/source/index.rst create mode 100644 docs/source/installation.rst create mode 100644 docs/source/modules.rst create mode 100644 docs/source/quickstart.rst create mode 100644 docs/test/charms.docker.rst create mode 100644 docs/test/charms.rst create mode 100644 docs/test/modules.rst diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..50ef185 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +PY := .venv/bin/python + +.PHONY: clean +clean: + find . -name '*.pyc' -delete + find . -name '*.bak' -delete + find . -name __pycache__ -delete + rm -f .coverage + +# DEPLOY +.PHONY: docs +docs: + pip3 list | grep Sphinx || pip3 install -U sphinx + cd docs && make html && cd - + +.PHONY: dist +dist: docs + $(PY) setup.py sdist + +.PHONY: publish +publish: docs + $(PY) setup.py sdist upload_docs --upload-dir=docs/build/html + diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..3e87355 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,216 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/* + +.PHONY: html +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +.PHONY: dirhtml +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: pickle +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +.PHONY: json +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +.PHONY: htmlhelp +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +.PHONY: qthelp +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/charmsdocker.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/charmsdocker.qhc" + +.PHONY: applehelp +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +.PHONY: devhelp +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/charmsdocker" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/charmsdocker" + @echo "# devhelp" + +.PHONY: epub +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +.PHONY: latex +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: latexpdfja +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: text +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +.PHONY: man +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +.PHONY: texinfo +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +.PHONY: info +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +.PHONY: gettext +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +.PHONY: changes +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +.PHONY: linkcheck +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +.PHONY: doctest +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: coverage +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +.PHONY: xml +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +.PHONY: pseudoxml +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/source/charms.docker.rst b/docs/source/charms.docker.rst new file mode 100644 index 0000000..c0b868d --- /dev/null +++ b/docs/source/charms.docker.rst @@ -0,0 +1,46 @@ +charms.docker package +===================== + +Submodules +---------- + +charms.docker.compose module +---------------------------- + +.. automodule:: charms.docker.compose + :members: + :undoc-members: + :show-inheritance: + +charms.docker.docker module +--------------------------- + +.. automodule:: charms.docker.docker + :members: + :undoc-members: + :show-inheritance: + +charms.docker.dockeropts module +------------------------------- + +.. automodule:: charms.docker.dockeropts + :members: + :undoc-members: + :show-inheritance: + +charms.docker.workspace module +------------------------------ + +.. automodule:: charms.docker.workspace + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: charms.docker + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..4192f05 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,303 @@ +# -*- coding: utf-8 -*- +# +# charms.docker documentation build configuration file, created by +# sphinx-quickstart on Wed Mar 23 06:29:35 2016. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import datetime +import sys +import os + +version_file = os.path.abspath( + os.path.join( + os.path.dirname(os.path.dirname(__file__)), '..', 'VERSION')) + +with open(version_file) as v: + VERSION = v.read().strip() + +sys.path.append(os.path.abspath('../../')) +# sys.path.append(os.path.abspath('_extensions/')) + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', + 'sphinx.ext.coverage', + 'sphinx.ext.ifconfig', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'charms.docker' +copyright = '{}, Charles Butler'.format(datetime.datetime.utcnow().year) +author = u'Charles Butler' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'0.0.8' +# The full version, including alpha/beta/rc tags. +release = u'0.0.8' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'charmsdockerdoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'charmsdocker.tex', u'charms.docker Documentation', + u'Charles Butler', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'charmsdocker', u'charms.docker Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'charmsdocker', u'charms.docker Documentation', + author, 'charmsdocker', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +# intersphinx_mapping = {'https://docs.python.org/': None} diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..5f84072 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,37 @@ +.. charms.docker documentation master file, created by + sphinx-quickstart on Wed Mar 23 06:29:35 2016. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +charms.docker - a convience library +========================================= + +charms.docker is a Python library for interacting with and configuring +a docker daemon. + +With charms.docker you can: + +- Configure any docker daemon +- Map and store DOCKEROPTS, and re-render to the appropriate file on the host +- Execute one off docker commands +- Login to a docker distribution/registry +- Stand up complex stacks of application containers with docker-compose + +Table of Contents +---------------- + +.. toctree:: + :maxdepth: 2 + + installation + quickstart + modules + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/source/installation.rst b/docs/source/installation.rst new file mode 100644 index 0000000..d94e958 --- /dev/null +++ b/docs/source/installation.rst @@ -0,0 +1,39 @@ +Installation +------------ + +charms.docker is available via pip. For source packages, see `GitHub`_. + +Pip +~~~~~~ + +Ideally you will do this in a virtualenv, and are familiar with working +with the virtualenv package. + +.. code:: bash + + pip install charms.docker + +Source +~~~~~~ + +charms.docker is built with Python3, so please make sure it’s installed prior +to following these steps. While you can run Amulet from source, it’s not +recommended as it requires several changes to environment variables in +order for Amulet to operate as it does in the packaged version. + +To install Amulet from source, first get the source: + +.. code:: bash + + git clone https://github.com/juju-solutions/charms.docker.git + +Move in to the ``charms.docker`` directory and run: + +.. code:: bash + + sudo python3 setup.py install + + You can also access the Python libraries; however, your ``PYTHONPATH`` + will need to be amended in order for it to find the amulet directory. + +.. _GitHub: https://github.com/juju/amulet/releases diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..a57aa72 --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,7 @@ +API Docs +======== + +.. toctree:: + :maxdepth: 4 + + charms.docker diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst new file mode 100644 index 0000000..e69de29 diff --git a/docs/test/charms.docker.rst b/docs/test/charms.docker.rst new file mode 100644 index 0000000..c0b868d --- /dev/null +++ b/docs/test/charms.docker.rst @@ -0,0 +1,46 @@ +charms.docker package +===================== + +Submodules +---------- + +charms.docker.compose module +---------------------------- + +.. automodule:: charms.docker.compose + :members: + :undoc-members: + :show-inheritance: + +charms.docker.docker module +--------------------------- + +.. automodule:: charms.docker.docker + :members: + :undoc-members: + :show-inheritance: + +charms.docker.dockeropts module +------------------------------- + +.. automodule:: charms.docker.dockeropts + :members: + :undoc-members: + :show-inheritance: + +charms.docker.workspace module +------------------------------ + +.. automodule:: charms.docker.workspace + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: charms.docker + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/test/charms.rst b/docs/test/charms.rst new file mode 100644 index 0000000..8a5f241 --- /dev/null +++ b/docs/test/charms.rst @@ -0,0 +1,17 @@ +charms package +============== + +Subpackages +----------- + +.. toctree:: + + charms.docker + +Module contents +--------------- + +.. automodule:: charms + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/test/modules.rst b/docs/test/modules.rst new file mode 100644 index 0000000..a858509 --- /dev/null +++ b/docs/test/modules.rst @@ -0,0 +1,7 @@ +charms +====== + +.. toctree:: + :maxdepth: 4 + + charms From 928d11cf45a9d34547408bb3c8f415cdb7a9eb68 Mon Sep 17 00:00:00 2001 From: Charles Butler Date: Thu, 31 Mar 2016 17:31:28 -0400 Subject: [PATCH 5/6] Remove leftover traces that I copied the template tree from amulet --- docs/source/installation.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index d94e958..cf3a140 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -17,11 +17,9 @@ Source ~~~~~~ charms.docker is built with Python3, so please make sure it’s installed prior -to following these steps. While you can run Amulet from source, it’s not -recommended as it requires several changes to environment variables in -order for Amulet to operate as it does in the packaged version. +to following these steps. -To install Amulet from source, first get the source: +To install charms.docker from source, first get the source: .. code:: bash @@ -34,6 +32,6 @@ Move in to the ``charms.docker`` directory and run: sudo python3 setup.py install You can also access the Python libraries; however, your ``PYTHONPATH`` - will need to be amended in order for it to find the amulet directory. + will need to be amended in order for it to find the charms.docker directory. -.. _GitHub: https://github.com/juju/amulet/releases +.. _GitHub: https://github.com/juju-solutions/charms.docker/releases From 26debea34a49c89277d4ff023c4f09895a8a564c Mon Sep 17 00:00:00 2001 From: Charles Butler Date: Thu, 31 Mar 2016 17:37:20 -0400 Subject: [PATCH 6/6] Correct the incorrect unix sockets --- charms/docker/docker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charms/docker/docker.py b/charms/docker/docker.py index 3a39056..be9e7e7 100644 --- a/charms/docker/docker.py +++ b/charms/docker/docker.py @@ -15,7 +15,7 @@ class Docker: def __init__(self, socket="unix:///var/run/docker.sock", workspace=None): ''' :param socket: URI to the Docker daemon socket - default: unix://var/run/docker.sock + default: unix:///var/run/docker.sock :param workspace: Path to directory containing a Dockerfile default: None @@ -29,7 +29,7 @@ def running(self): Predicate method to determine if the daemon we are talking to is actually online and recieving events. - ex: bootstrap = Docker(socket="unix://var/run/docker-boostrap.sock") + ex: bootstrap = Docker(socket="unix:///var/run/docker-boostrap.sock") bootstrap.running() > True '''