Option to run docker-compose as container
diff --git a/README.rst b/README.rst
index ce18ed7..4039078 100644
--- a/README.rst
+++ b/README.rst
@@ -51,13 +51,22 @@
Compose
~~~~~~~
-Install docker-compose using Pip (default is distribution package)
+There are three options how to install docker-compose:
+
+- distribution package (default)
+- using Pip
+- using Docker container
+
+Install docker-compose using Docker (default is distribution package)
.. code-block:: yaml
docker:
client:
compose:
+ source:
+ engine: docker
+ image: docker/compose:1.8.0
django_web:
# Run up action, any positional argument to docker-compose CLI
# If not defined, only docker-compose.yml is generated
diff --git a/docker/client/compose.sls b/docker/client/compose.sls
index e1ee3a7..6c0eb88 100644
--- a/docker/client/compose.sls
+++ b/docker/client/compose.sls
@@ -2,6 +2,9 @@
include:
- docker.client
+ {%- if client.compose.source.engine == 'docker' %}
+ - docker.host
+ {%- endif %}
{%- if client.compose.source.engine == 'pkg' %}
docker_compose:
@@ -17,6 +20,21 @@
- name: docker-compose
- require:
- pkg: docker_compose_python_pip
+{%- elif client.compose.source.engine == 'docker' %}
+docker_compose_wrapper:
+ file.managed:
+ - name: /usr/local/bin/docker-compose
+ - source: salt://docker/files/docker-compose
+ - template: jinja
+ - defaults:
+ image: {{ client.compose.source.image|default('docker/compose') }}
+ - mode: 755
+
+docker_compose:
+ cmd.wait:
+ - name: /usr/local/bin/docker-compose version
+ - watch:
+ - file: docker_compose_wrapper
{%- endif %}
{%- for app, compose in client.compose.iteritems() %}
@@ -68,6 +86,8 @@
- pkg: docker_compose
{%- elif client.compose.source.engine == 'pip' %}
- pip: docker_compose
+ {%- elif client.compose.source.engine == 'docker' %}
+ - cmd: docker_compose
{%- endif %}
- watch_in:
- file: docker_{{ app }}_env
diff --git a/docker/files/docker-compose b/docker/files/docker-compose
new file mode 100755
index 0000000..f1ae5ad
--- /dev/null
+++ b/docker/files/docker-compose
@@ -0,0 +1,59 @@
+#!/bin/bash
+# =================================================
+# This file is managed by SaltStack docker formula.
+# Manual changes may be overwritten.
+# =================================================
+#
+# Run docker-compose in a container
+#
+# This script will attempt to mirror the host paths by using volumes for the
+# following paths:
+# * $(pwd)
+# * $(dirname $COMPOSE_FILE) if it's set
+# * $HOME if it's set
+#
+# You can add additional volumes (or any docker run options) using
+# the $COMPOSE_OPTIONS environment variable.
+#
+
+
+set -e
+
+IMAGE=${IMAGE:-"{{ image }}"}
+
+
+# Setup options for connecting to docker host
+if [ -z "$DOCKER_HOST" ]; then
+ DOCKER_HOST="/var/run/docker.sock"
+fi
+if [ -S "$DOCKER_HOST" ]; then
+ DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
+else
+ DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH"
+fi
+
+
+# Setup volume mounts for compose config and context
+if [ "$(pwd)" != '/' ]; then
+ VOLUMES="-v $(pwd):$(pwd)"
+fi
+if [ -n "$COMPOSE_FILE" ]; then
+ compose_dir=$(dirname $COMPOSE_FILE)
+fi
+# TODO: also check --file argument
+if [ -n "$compose_dir" ]; then
+ VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
+fi
+if [ -n "$HOME" ]; then
+ VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config
+fi
+
+# Only allocate tty if we detect one
+if [ -t 1 ]; then
+ DOCKER_RUN_OPTIONS="-t"
+fi
+if [ -t 0 ]; then
+ DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i"
+fi
+
+exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@"
diff --git a/docker/map.jinja b/docker/map.jinja
index d475371..d709b9f 100644
--- a/docker/map.jinja
+++ b/docker/map.jinja
@@ -25,6 +25,7 @@
'base': '/etc/docker/compose',
'source': {
'engine': 'pkg',
+ 'version': '1.8.0',
'pkgs': ['docker-compose'],
},
},