From cbd42ca6e90cca2ff4b84f5e4e46224e6455e8b2 Mon Sep 17 00:00:00 2001 From: Sam Yaple Date: Fri, 28 Aug 2015 12:16:53 +0000 Subject: Move docker_templates to docker dir Updated build.py to reflect this change. Deprecate --template option and make it a noop. Change-Id: I7cd98d1ee684a4c64984a49597159868152683b2 Partially-Implements: blueprint remove-docker-dir --- docker/haproxy/Dockerfile.j2 | 27 +++++++++++++++++++++++++++ docker/haproxy/config-external.sh | 10 ++++++++++ docker/haproxy/ensure_latest_config.sh | 12 ++++++++++++ docker/haproxy/start.sh | 20 ++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100755 docker/haproxy/Dockerfile.j2 create mode 100644 docker/haproxy/config-external.sh create mode 100755 docker/haproxy/ensure_latest_config.sh create mode 100755 docker/haproxy/start.sh (limited to 'docker/haproxy') 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 -- cgit v1.2.3