Merge pull request #1 from tcpcloud/docker
Allow installation of aptly-publisher using pip or docker
diff --git a/aptly/files/aptly-publisher b/aptly/files/aptly-publisher
new file mode 100755
index 0000000..8d65aad
--- /dev/null
+++ b/aptly/files/aptly-publisher
@@ -0,0 +1,61 @@
+#!/bin/bash
+# =================================================
+# This file is managed by SaltStack aptly formula.
+# Manual changes may be overwritten.
+# =================================================
+#
+# Run aptly-publisher in a container
+#
+# This script will attempt to mirror the host paths by using volumes for the
+# following paths:
+# * /etc/aptly-publisher.yaml
+# * /etc/aptly
+# * $(pwd)
+# * $HOME if it's set
+#
+# You can add additional volumes (or any docker run options) using
+# the $APTLY_PUBLISHER_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):ro"
+fi
+
+if [ -e /etc/aptly-publisher.yaml ]; then
+ VOLUMES="-v /etc/aptly-publisher.yaml:/etc/aptly-publisher.yaml:ro"
+fi
+
+if [ -d /etc/aptly ]; then
+ VOLUMES="-v /etc/aptly:/etc/aptly:ro"
+fi
+
+if [ -n "$HOME" ]; then
+ VOLUMES="$VOLUMES -v $HOME:$HOME:ro"
+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 $APTLY_PUBLISHER_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@"
diff --git a/aptly/map.jinja b/aptly/map.jinja
index 751ade0..cd5db66 100644
--- a/aptly/map.jinja
+++ b/aptly/map.jinja
@@ -11,4 +11,11 @@
},
}, merge=salt['pillar.get']('aptly:server')) %}
-{%- set publisher=salt['pillar.get']('aptly:publisher') %}
+{%- set publisher = salt['grains.filter_by']({
+ 'default': {
+ 'source' {
+ 'engine': 'pkg',
+ 'pkgs': ['aptly-publisher'],
+ },
+ },
+}, merge=salt['pillar.get']('aptly:publisher')) %}
diff --git a/aptly/publisher.sls b/aptly/publisher.sls
index e0404a1..bd7a1e0 100644
--- a/aptly/publisher.sls
+++ b/aptly/publisher.sls
@@ -1,9 +1,36 @@
{%- from "aptly/map.jinja" import publisher with context %}
{%- if publisher.enabled %}
-publisher_packages:
- pkg.latest:
- - names: ['python-aptly']
+{%- if publisher.source.engine == 'pkg' %}
+publisher_installed:
+ pkg.installed:
+ - names: {{ publisher.source.pkgs }}
+{%- elif publisher.source.engine == 'pip' %}
+publisher_python_pip:
+ pkg.installed:
+ - name: python-pip
+
+publisher_installed:
+ pip.installed:
+ - name: python-aptly
+ - require:
+ - pkg: publisher_python_pip
+{%- elif publisher.source.engine == 'docker' %}
+publisher_wrapper:
+ file.managed:
+ - name: /usr/local/bin/aptly-publisher
+ - source: salt://docker/files/aptly-publisher
+ - template: jinja
+ - defaults:
+ image: {{ client.compose.source.image|default('tcpcloud/aptly-publisher') }}
+ - mode: 755
+
+publisher_installed:
+ cmd.wait:
+ - name: "/usr/local/bin/aptly-publisher --help"
+ - watch:
+ - file: publisher_wrapper
+{%- endif %}
publisher_yaml:
file.managed: