Merge lp:~samuel-cozannet/charms/trusty/docker-compose/dev into lp:~zoology/charms/trusty/docker-compose/trunk

Proposed by Samuel Cozannet
Status: Merged
Merged at revision: 3
Proposed branch: lp:~samuel-cozannet/charms/trusty/docker-compose/dev
Merge into: lp:~zoology/charms/trusty/docker-compose/trunk
Diff against target: 179 lines (+63/-23)
6 files modified
README.md (+30/-5)
config.yaml (+1/-1)
hooks/config-changed (+24/-9)
hooks/install (+2/-6)
hooks/stop (+0/-2)
hooks/upgrade-charm (+6/-0)
To merge this branch: bzr merge lp:~samuel-cozannet/charms/trusty/docker-compose/dev
Reviewer Review Type Date Requested Status
Charles Butler Approve
Review via email: mp+277137@code.launchpad.net

Description of the change

Hi LazyPower,

This branch fixes the problem of config, and adds auto-opening ports on the host, as well as management of Swarm Clusters.

I also added an example to run it on Swarm.

++
Sam

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

+1 LGTM with this particular implementation.

I think we should move the docker-compose version identifier to config.yaml and let user config drive that, so the end user isn't blocked on us updating the charm. Otherwise LGTM

Thanks for the contribution Sam! Big thanks for the README updates, and the port-openening code. This is the first time i've seen shyaml, looks nifty.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.md'
--- README.md 2015-06-18 18:31:28 +0000
+++ README.md 2015-11-10 14:39:49 +0000
@@ -8,11 +8,11 @@
8Ensure you have a docker-cluster running complete with the registrator charm:8Ensure you have a docker-cluster running complete with the registrator charm:
99
10 juju deploy docker10 juju deploy docker
11 juju deploy registrator11 juju deploy cs:~zoology/trusty/registrator registrator
12 juju deploy consul12 juju deploy cs:~zoology/trusty/consul consul
13 juju deploy nginx-proxy13 juju deploy nginx-proxy
14 juju add-relation registrator docker14 juju add-relation registrator docker
15 juju add-relation registrator:api consul:api15 juju add-relation registrator:consul-api consul:api
16 juju add-relation nginx-proxy:template consul:api16 juju add-relation nginx-proxy:template consul:api
1717
18Using the example of deploying the 2048 HTML5 game running in a docker container:18Using the example of deploying the 2048 HTML5 game running in a docker container:
@@ -21,9 +21,32 @@
21 juju set twentry-fourty-eight repository=https://github.com/chuckbutler/docker-demos.git path=204821 juju set twentry-fourty-eight repository=https://github.com/chuckbutler/docker-demos.git path=2048
22 juju add-relation twenty-fourty-eight docker22 juju add-relation twenty-fourty-eight docker
2323
24## Scale out usage
25
26Scaling out in the case of Docker means using a Docker Cluster, which can be achieved with Swarm.
27
28 juju deploy -n3 --constraints "mem=4G cpu-cores=4 root-disk=32G" cs:~lazypower/trusty/swarm
29 juju deploy -n3 etcd
30 juju add-relation swarm etcd
31
32Now you can deploy a RabbitMQ server encapsulated as a docker container:
33
34 juju deploy cs:~lazypower/trustydocker-compose rabbitmq
35 juju set rabbitmq repository=https://github.com/SaMnCo/docker-app.git path=rabbitmq/templates
36 juju add-relation rabbitmq swarm
37 juju expose rabbitmq
38
24## Known Limitations and Issues39## Known Limitations and Issues
2540
26[todo]41### Connecting to containerized apps
42
43In the current design it's not possible to relate two containers together, or an app deployed via Juju to a containerized app.
44
45To connect to a container you have to use the Juju command
46
47 juju status --format tabular
48
49And look at IP addresses and ports.
2750
28# Configuration51# Configuration
2952
@@ -31,5 +54,7 @@
3154
32# Contact Information55# Contact Information
3356
34[todo]57Charles Butler (LazyPower) <charles.butler@canonical.com>
58Samuel Cozannet (SaMnCo) <samuel.cozannet@canonical.com>
59
3560
3661
=== modified file 'config.yaml'
--- config.yaml 2015-06-18 18:31:28 +0000
+++ config.yaml 2015-11-10 14:39:49 +0000
@@ -1,7 +1,7 @@
1options:1options:
2 repository:2 repository:
3 type: string3 type: string
4 default: https://github.com/chuckbutler/docker-demos4 default:
5 description: "repository to clone that holds the docker-compose.yaml or fig.yaml"5 description: "repository to clone that holds the docker-compose.yaml or fig.yaml"
6 path:6 path:
7 type: string7 type: string
88
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2015-06-18 18:31:28 +0000
+++ hooks/config-changed 2015-11-10 14:39:49 +0000
@@ -1,14 +1,14 @@
1#!/bin/bash1#!/bin/bash
2# config-changed occurs everytime a new configuration value is updated (juju set)
3
4set -ex2set -ex
53
6COMPOSE_REPO=$(config-get repository)4COMPOSE_REPO=$(config-get repository)
7COMPOSE_PATH=$(config-get path)5COMPOSE_PATH=$(config-get path)
8COMPOSE_ARGS=$(config-get arguments)6COMPOSE_ARGS=$(config-get arguments)
97
8IS_SWARM_CLUSTER=$(docker ps | grep "swarm" | wc -l)
9IS_SWARM_MASTER=$(docker ps | grep "swarm" | grep "manage" | wc -l)
1010
11if [ -z $COMPOSE_REPO ]; then11if [ -z ${COMPOSE_REPO} ]; then
12 juju-log "Missing repository. Doing nothing"12 juju-log "Missing repository. Doing nothing"
13 status-set blocked "Missing repository config"13 status-set blocked "Missing repository config"
14 exit 014 exit 0
@@ -29,12 +29,27 @@
29 cd $COMPOSE_PATH29 cd $COMPOSE_PATH
30fi30fi
3131
32docker-compose pull32# We execute only if we are on a standalone docker node or on the swarm master
33docker-compose build33if [[ ${IS_SWARM_CLUSTER} -lt 1 || ${IS_SWARM_MASTER} -eq 1 ]]; then
34 docker-compose pull
35 docker-compose build
3436
35if [ -z $COMPOSE_ARGS ]; then37 if [ -z $COMPOSE_ARGS ]; then
36 docker-compose up -d38 docker-compose up -d
37else39 else
38 docker-compose $COMPOSE_ARGS40 docker-compose $COMPOSE_ARGS
41 fi
39fi42fi
4043
44# Now as we can't predict where the container will be we open all ports on all machines
45WORKLOADS=$(cat docker-compose.yml | shyaml keys)
46PORTS=""
47for workload in ${WORKLOADS}; do
48 PORTS="${PORTS} $(cat docker-compose.yml | shyaml get-values ${workload}.ports | cut -f1 -d':')"
49done
50
51for port in ${PORTS}; do
52 open-port ${port}
53done
54
55exit 0
41\ No newline at end of file56\ No newline at end of file
4257
=== modified file 'hooks/install'
--- hooks/install 2015-06-18 21:10:49 +0000
+++ hooks/install 2015-11-10 14:39:49 +0000
@@ -1,14 +1,10 @@
1#!/bin/bash1#!/bin/bash
2# Here do anything needed to install the service
3# i.e. apt-get install -y foo or bzr branch http://myserver/mycode /srv/webroot
4# Make sure this hook exits cleanly and is idempotent, common problems here are
5# failing to account for a debconf question on a dependency, or trying to pull
6# from github without installing git firstw
72
8COMPOSE_INSTALLED=$(which docker-compose)3COMPOSE_INSTALLED=$(which docker-compose)
94
10if [ -z $COMPOSE_INSTALLED ]; then5if [ -z $COMPOSE_INSTALLED ]; then
11 pip install --upgrade docker-compose==1.2.06 pip install --upgrade docker-compose==1.5.0
12fi7fi
138
14apt-get install -y git9apt-get install -y git
10pip install --upgrade shyaml
15\ No newline at end of file11\ No newline at end of file
1612
=== modified file 'hooks/stop'
--- hooks/stop 2015-06-18 18:31:28 +0000
+++ hooks/stop 2015-11-10 14:39:49 +0000
@@ -1,5 +1,4 @@
1#!/bin/bash1#!/bin/bash
2# config-changed occurs everytime a new configuration value is updated (juju set)
32
4COMPOSE_REPO=$(config-get repository)3COMPOSE_REPO=$(config-get repository)
5COMPOSE_PATH=$(config-get path)4COMPOSE_PATH=$(config-get path)
@@ -18,4 +17,3 @@
18docker compose rm17docker compose rm
19cd $CHARM_DIR18cd $CHARM_DIR
20rm -rf compose_app19rm -rf compose_app
21
2220
=== added file 'hooks/upgrade-charm'
--- hooks/upgrade-charm 1970-01-01 00:00:00 +0000
+++ hooks/upgrade-charm 2015-11-10 14:39:49 +0000
@@ -0,0 +1,6 @@
1#!/bin/bash
2
3hooks/stop
4
5hooks/config-changed
6

Subscribers

People subscribed via source and target branches