Merge lp://qastaging/~johnsca/charm-helpers/docker into lp://qastaging/charm-helpers

Proposed by Cory Johns
Status: Needs review
Proposed branch: lp://qastaging/~johnsca/charm-helpers/docker
Merge into: lp://qastaging/charm-helpers
Diff against target: 627 lines (+552/-1)
7 files modified
charmhelpers/contrib/docker/__init__.py (+287/-0)
charmhelpers/core/host.py (+5/-0)
charmhelpers/core/services/base.py (+14/-1)
docs/api/charmhelpers.contrib.docker.rst (+8/-0)
docs/api/charmhelpers.contrib.rst (+1/-0)
docs/examples/docker.rst (+119/-0)
tests/contrib/docker/test_docker.py (+118/-0)
To merge this branch: bzr merge lp://qastaging/~johnsca/charm-helpers/docker
Reviewer Review Type Date Requested Status
amir sanjar (community) Approve
Benjamin Saller (community) Approve
charmers Pending
Charm Helper Maintainers Pending
Review via email: mp+231226@code.qastaging.launchpad.net

Description of the change

Added helpers for managing Docker containers in a charm, using the services framework. Includes documentation.

To post a comment you must log in.
Revision history for this message
Kapil Thangavelu (hazmat) wrote :
Download full text (25.0 KiB)

i'd also appreciate an option for docker install latest ala
https://docs.docker.com/installation/binaries/

On Mon, Aug 18, 2014 at 12:29 PM, Cory Johns <email address hidden>
wrote:

> Cory Johns has proposed merging lp:~johnsca/charm-helpers/docker into
> lp:charm-helpers.
>
> Requested reviews:
> Charm Helper Maintainers (charm-helpers)
>
> For more details, see:
> https://code.launchpad.net/~johnsca/charm-helpers/docker/+merge/231226
>
> Added helpers for managing Docker containers in a charm, using the
> services framework. Includes documentation.
> --
> https://code.launchpad.net/~johnsca/charm-helpers/docker/+merge/231226
> Your team Charm Helper Maintainers is requested to review the proposed
> merge of lp:~johnsca/charm-helpers/docker into lp:charm-helpers.
>
> === added directory 'charmhelpers/contrib/docker'
> === added file 'charmhelpers/contrib/docker/__init__.py'
> --- charmhelpers/contrib/docker/__init__.py 1970-01-01 00:00:00 +0000
> +++ charmhelpers/contrib/docker/__init__.py 2014-08-18 16:28:55 +0000
> @@ -0,0 +1,287 @@
> +
> +import os
> +import subprocess
> +
> +from charmhelpers import fetch
> +from charmhelpers.core import host
> +from charmhelpers.core import hookenv
> +from charmhelpers.core.services.base import ManagerCallback
> +from charmhelpers.core.services.helpers import RelationContext
> +
> +
> +def install_docker():
> + """
> + Install the Docker tools.
> + """
> + fetch.apt_install(['docker.io'])
> + if os.path.exists('/usr/local/bin/docker'):
> + os.unlink('/usr/local/bin/docker')
> + os.symlink('/usr/bin/docker.io', '/usr/local/bin/docker')
> + with open('/etc/bash_completion.d/docker.io', 'a') as fp:
> + fp.write('\ncomplete -F _docker docker')
> +
> +
> +def install_docker_unstable():
> + """
> + Install the Docker tools from the unstable (but potentially more
> + up-to-date) repository.
> + """
> + fetch.add_source('deb https://get.docker.io/ubuntu docker main',
> + key='36A1D7869245C8950F966E92D8576A8BA88D21E9')
> + fetch.apt_update(fatal=True)
> + fetch.apt_install(['lxc-docker'])
> +
> +
> +def docker_pull(container_name, registry=None, username=None,
> password=None):
> + """
> + Fetch a container from the Docker registry.
> +
> + If :param:`registry` is given, the container will be pulled from that
> + registry instead of the default. If the registry requires
> authentication,
> + provide the :param:`username` and :param:`password` arguments.
> + """
> + if registry is not None:
> + container_name = '/'.join([registry, container_name])
> + if any(username, password):
> + subprocess.check_call([
> + 'docker', 'login', '-u', username, '-p', password])
> + subprocess.check_call(['docker', 'pull', container_name])
> +
> +
> +class DockerCallback(ManagerCallback):
> + """
> + ServiceManager callback to manage starting up a Docker container.
> +
> + Can be referenced as ``docker_start`` or ``docker_stop``, and performs
> + the appropriate action. Requires one or more of
> + :class:`DockerPortMappings`, :class:`DockerVolumes`,
> + :c...

Revision history for this message
Cory Johns (johnsca) wrote :

> i'd also appreciate an option for docker install latest ala
> https://docs.docker.com/installation/binaries/

Their instructions for installing the latest version on Ubuntu say to use their apt repo: https://docs.docker.com/installation/ubuntulinux/

You think there's likely to be drift between their apt repo version and the latest binary to warrant installing the binaries manually?

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

fair enough.. i was considering cross platform and the way i always install
it (static bin dl), in addition to the oncoming pkg binary name change
(though it will be backwards compatible). but what your doing is good given
the XP is theoretical at this point.

On Tue, Aug 19, 2014 at 10:05 AM, Cory Johns <email address hidden>
wrote:

> > i'd also appreciate an option for docker install latest ala
> > https://docs.docker.com/installation/binaries/
>
> Their instructions for installing the latest version on Ubuntu say to use
> their apt repo: https://docs.docker.com/installation/ubuntulinux/
>
> You think there's likely to be drift between their apt repo version and
> the latest binary to warrant installing the binaries manually?
> --
> https://code.launchpad.net/~johnsca/charm-helpers/docker/+merge/231226
> Your team Charm Helper Maintainers is requested to review the proposed
> merge of lp:~johnsca/charm-helpers/docker into lp:charm-helpers.
>

Revision history for this message
Cory Johns (johnsca) wrote :

> fair enough.. i was considering cross platform and the way i always install
> it (static bin dl), in addition to the oncoming pkg binary name change
> (though it will be backwards compatible). but what your doing is good given
> the XP is theoretical at this point.

And since this is a helper, it will be easy enough to refactor it later as long as the API doesn't change (which is just a no-arg function call).

Revision history for this message
Benjamin Saller (bcsaller) wrote :

LGTM, thanks, Good Work.

review: Approve
Revision history for this message
amir sanjar (asanjar) wrote :

+1
As much as personally I don't think this should matter anymore, but charmers have frown at using
path as follow:
if os.path.exists('/usr/local/bin/docker'):
   os.unlink('/usr/local/bin/docker')

recommend to change to:
docker_path = os.path.join(os.path.sep, 'usr', 'local','bin','docker')

review: Approve

Unmerged revisions

195. By Cory Johns

Added Docker helpers and documentation

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches