summaryrefslogtreecommitdiff
path: root/docker/haproxy
diff options
context:
space:
mode:
Diffstat (limited to 'docker/haproxy')
-rwxr-xr-xdocker/haproxy/Dockerfile.j227
-rw-r--r--docker/haproxy/config-external.sh10
-rwxr-xr-xdocker/haproxy/ensure_latest_config.sh12
-rwxr-xr-xdocker/haproxy/start.sh20
4 files changed, 69 insertions, 0 deletions
diff --git a/docker/haproxy/Dockerfile.j2 b/docker/haproxy/Dockerfile.j2
new file mode 100755
index 000000000..2858f436a
--- /dev/null
+++ b/docker/haproxy/Dockerfile.j2
@@ -0,0 +1,27 @@
+FROM {{ namespace }}/{{ base_distro }}-{{ install_type }}-base:{{ tag }}
+MAINTAINER Kolla Project (https://launchpad.net/kolla)
+
+{% if base_distro in ['fedora', 'centos', 'oraclelinux'] %}
+
+RUN yum -y install \
+ haproxy \
+ && yum clean all
+
+{% elif base_distro == 'ubuntu' %}
+
+RUN apt-get install -y --no-install-recommends -t trusty-backports haproxy \
+ && apt-get clean
+
+{% elif base_distro == 'debian' %}
+
+RUN apt-get install -y --no-install-recommends haproxy \
+ && apt-get clean
+
+{% endif %}
+
+COPY start.sh /
+COPY config-external.sh ensure_latest_config.sh /opt/kolla/
+
+CMD ["/start.sh"]
+
+{{ include_footer }}
diff --git a/docker/haproxy/config-external.sh b/docker/haproxy/config-external.sh
new file mode 100644
index 000000000..0c41a5bdb
--- /dev/null
+++ b/docker/haproxy/config-external.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+SOURCE="/opt/kolla/haproxy/haproxy.cfg"
+TARGET="/etc/haproxy/haproxy.cfg"
+OWNER="root"
+
+if [[ -f "$SOURCE" ]]; then
+ cp -f $SOURCE $TARGET
+ chown ${OWNER}: $TARGET
+ chmod 0644 $TARGET
+fi
diff --git a/docker/haproxy/ensure_latest_config.sh b/docker/haproxy/ensure_latest_config.sh
new file mode 100755
index 000000000..b91189ca5
--- /dev/null
+++ b/docker/haproxy/ensure_latest_config.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+CURRENT_CONFIG_HASH=$(sha1sum /etc/haproxy/haproxy.cfg | cut -f1 -d' ')
+NEW_CONFIG_HASH=$(sha1sum /opt/kolla/haproxy/haproxy.cfg | cut -f1 -d' ')
+
+if [[ $CURRENT_CONFIG_HASH != $NEW_CONFIG_HASH ]]; then
+ changed=changed
+ source /opt/kolla/config-external.sh
+ /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -sf $(cat /run/haproxy.pid)
+fi
+
+echo $changed
diff --git a/docker/haproxy/start.sh b/docker/haproxy/start.sh
new file mode 100755
index 000000000..d1da4a607
--- /dev/null
+++ b/docker/haproxy/start.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+set -o errexit
+
+CMD='/usr/sbin/haproxy'
+ARGS="-f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid"
+
+# Loading common functions.
+source /opt/kolla/kolla-common.sh
+
+# Execute config strategy
+set_configs
+
+# We are intentionally not using exec so we can reload the haproxy config later
+$CMD $ARGS
+
+# TODO(SamYaple): This has the potential for a race condition triggered by a
+# config reload that could cause the container to exit
+while [[ -e "/proc/$(cat /run/haproxy.pid)" ]]; do
+ sleep 5
+done