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
1=== modified file 'README.md'
2--- README.md 2015-06-18 18:31:28 +0000
3+++ README.md 2015-11-10 14:39:49 +0000
4@@ -8,11 +8,11 @@
5 Ensure you have a docker-cluster running complete with the registrator charm:
6
7 juju deploy docker
8- juju deploy registrator
9- juju deploy consul
10+ juju deploy cs:~zoology/trusty/registrator registrator
11+ juju deploy cs:~zoology/trusty/consul consul
12 juju deploy nginx-proxy
13 juju add-relation registrator docker
14- juju add-relation registrator:api consul:api
15+ juju add-relation registrator:consul-api consul:api
16 juju add-relation nginx-proxy:template consul:api
17
18 Using the example of deploying the 2048 HTML5 game running in a docker container:
19@@ -21,9 +21,32 @@
20 juju set twentry-fourty-eight repository=https://github.com/chuckbutler/docker-demos.git path=2048
21 juju add-relation twenty-fourty-eight docker
22
23+## Scale out usage
24+
25+Scaling out in the case of Docker means using a Docker Cluster, which can be achieved with Swarm.
26+
27+ juju deploy -n3 --constraints "mem=4G cpu-cores=4 root-disk=32G" cs:~lazypower/trusty/swarm
28+ juju deploy -n3 etcd
29+ juju add-relation swarm etcd
30+
31+Now you can deploy a RabbitMQ server encapsulated as a docker container:
32+
33+ juju deploy cs:~lazypower/trustydocker-compose rabbitmq
34+ juju set rabbitmq repository=https://github.com/SaMnCo/docker-app.git path=rabbitmq/templates
35+ juju add-relation rabbitmq swarm
36+ juju expose rabbitmq
37+
38 ## Known Limitations and Issues
39
40-[todo]
41+### Connecting to containerized apps
42+
43+In the current design it's not possible to relate two containers together, or an app deployed via Juju to a containerized app.
44+
45+To connect to a container you have to use the Juju command
46+
47+ juju status --format tabular
48+
49+And look at IP addresses and ports.
50
51 # Configuration
52
53@@ -31,5 +54,7 @@
54
55 # Contact Information
56
57-[todo]
58+Charles Butler (LazyPower) <charles.butler@canonical.com>
59+Samuel Cozannet (SaMnCo) <samuel.cozannet@canonical.com>
60+
61
62
63=== modified file 'config.yaml'
64--- config.yaml 2015-06-18 18:31:28 +0000
65+++ config.yaml 2015-11-10 14:39:49 +0000
66@@ -1,7 +1,7 @@
67 options:
68 repository:
69 type: string
70- default: https://github.com/chuckbutler/docker-demos
71+ default:
72 description: "repository to clone that holds the docker-compose.yaml or fig.yaml"
73 path:
74 type: string
75
76=== modified file 'hooks/config-changed'
77--- hooks/config-changed 2015-06-18 18:31:28 +0000
78+++ hooks/config-changed 2015-11-10 14:39:49 +0000
79@@ -1,14 +1,14 @@
80 #!/bin/bash
81-# config-changed occurs everytime a new configuration value is updated (juju set)
82-
83 set -ex
84
85 COMPOSE_REPO=$(config-get repository)
86 COMPOSE_PATH=$(config-get path)
87 COMPOSE_ARGS=$(config-get arguments)
88
89+IS_SWARM_CLUSTER=$(docker ps | grep "swarm" | wc -l)
90+IS_SWARM_MASTER=$(docker ps | grep "swarm" | grep "manage" | wc -l)
91
92-if [ -z $COMPOSE_REPO ]; then
93+if [ -z ${COMPOSE_REPO} ]; then
94 juju-log "Missing repository. Doing nothing"
95 status-set blocked "Missing repository config"
96 exit 0
97@@ -29,12 +29,27 @@
98 cd $COMPOSE_PATH
99 fi
100
101-docker-compose pull
102-docker-compose build
103+# We execute only if we are on a standalone docker node or on the swarm master
104+if [[ ${IS_SWARM_CLUSTER} -lt 1 || ${IS_SWARM_MASTER} -eq 1 ]]; then
105+ docker-compose pull
106+ docker-compose build
107
108-if [ -z $COMPOSE_ARGS ]; then
109- docker-compose up -d
110-else
111- docker-compose $COMPOSE_ARGS
112+ if [ -z $COMPOSE_ARGS ]; then
113+ docker-compose up -d
114+ else
115+ docker-compose $COMPOSE_ARGS
116+ fi
117 fi
118
119+# Now as we can't predict where the container will be we open all ports on all machines
120+WORKLOADS=$(cat docker-compose.yml | shyaml keys)
121+PORTS=""
122+for workload in ${WORKLOADS}; do
123+ PORTS="${PORTS} $(cat docker-compose.yml | shyaml get-values ${workload}.ports | cut -f1 -d':')"
124+done
125+
126+for port in ${PORTS}; do
127+ open-port ${port}
128+done
129+
130+exit 0
131\ No newline at end of file
132
133=== modified file 'hooks/install'
134--- hooks/install 2015-06-18 21:10:49 +0000
135+++ hooks/install 2015-11-10 14:39:49 +0000
136@@ -1,14 +1,10 @@
137 #!/bin/bash
138-# Here do anything needed to install the service
139-# i.e. apt-get install -y foo or bzr branch http://myserver/mycode /srv/webroot
140-# Make sure this hook exits cleanly and is idempotent, common problems here are
141-# failing to account for a debconf question on a dependency, or trying to pull
142-# from github without installing git firstw
143
144 COMPOSE_INSTALLED=$(which docker-compose)
145
146 if [ -z $COMPOSE_INSTALLED ]; then
147- pip install --upgrade docker-compose==1.2.0
148+ pip install --upgrade docker-compose==1.5.0
149 fi
150
151 apt-get install -y git
152+pip install --upgrade shyaml
153\ No newline at end of file
154
155=== modified file 'hooks/stop'
156--- hooks/stop 2015-06-18 18:31:28 +0000
157+++ hooks/stop 2015-11-10 14:39:49 +0000
158@@ -1,5 +1,4 @@
159 #!/bin/bash
160-# config-changed occurs everytime a new configuration value is updated (juju set)
161
162 COMPOSE_REPO=$(config-get repository)
163 COMPOSE_PATH=$(config-get path)
164@@ -18,4 +17,3 @@
165 docker compose rm
166 cd $CHARM_DIR
167 rm -rf compose_app
168-
169
170=== added file 'hooks/upgrade-charm'
171--- hooks/upgrade-charm 1970-01-01 00:00:00 +0000
172+++ hooks/upgrade-charm 2015-11-10 14:39:49 +0000
173@@ -0,0 +1,6 @@
174+#!/bin/bash
175+
176+hooks/stop
177+
178+hooks/config-changed
179+

Subscribers

People subscribed via source and target branches