Skip to content

Commit

Permalink
- Fix discovery
Browse files Browse the repository at this point in the history
- Upgrade to alpine linux
- Update dockerignore
- bash --> sh (for alpine)
  • Loading branch information
sukrit007 committed Apr 20, 2016
1 parent 0c8786d commit 4126ad7
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 122 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ dev-requirements.txt
*.iml
LICENSE
local-*
docker-compose.yml
docker-compose.yml
local-server.py
local-celery.py
local-celery-beat.py
115 changes: 55 additions & 60 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,72 +1,67 @@
FROM python:2.7-slim
FROM python:2.7.11-alpine

ENV DEBIAN_FRONTEND noninteractive
ENV ETCDCTL_VERSION v2.3.1
ENV ETCDCTL_VERSION v2.2.5
ENV DUMB_INIT_VERSION 1.0.1
ENV CONFD_VERSION 0.12.0-alpha3

# Native packages, python global deps, gettext, supervisor, dumb-init, etcd
RUN apt-get update --fix-missing \
&& apt-get install -y \
gettext \
wget \
curl \
openssl \

# Upgrade pip
&& pip install --upgrade pip \

# Confd
&& curl -L https://github.com/kelseyhightower/confd/releases/download/v$CONFD_VERSION/confd-${CONFD_VERSION}-linux-amd64 -o /usr/local/bin/confd \
&& chmod 555 /usr/local/bin/confd \

# Etcd
&& curl -L https://github.com/coreos/etcd/releases/download/$ETCDCTL_VERSION/etcd-$ETCDCTL_VERSION-linux-amd64.tar.gz -o /tmp/etcd-$ETCDCTL_VERSION-linux-amd64.tar.gz \
&& cd /tmp && gzip -dc etcd-$ETCDCTL_VERSION-linux-amd64.tar.gz | tar -xof - \
&& cp -f /tmp/etcd-$ETCDCTL_VERSION-linux-amd64/etcdctl /usr/local/bin \
RUN apk add --no-cache --update \
pcre \
gettext \
curl \
openssl \

# Python Global Deps
&& pip install supervisor==3.2.3 supervisor-stdout \
# Etcdctl
&& curl -L https://github.com/coreos/etcd/releases/download/$ETCDCTL_VERSION/etcd-$ETCDCTL_VERSION-linux-amd64.tar.gz -o /tmp/etcd-$ETCDCTL_VERSION-linux-amd64.tar.gz \
&& cd /tmp && gzip -dc etcd-$ETCDCTL_VERSION-linux-amd64.tar.gz | tar -xof - \
&& cp -f /tmp/etcd-$ETCDCTL_VERSION-linux-amd64/etcdctl /usr/local/bin \

# Supervisor Directories
&& mkdir -p /var/log/supervisor \
&& mkdir -p /etc/supervisor/conf.d \
&& ln -sf /etc/supervisor/supervisord.conf /etc/supervisord.conf \
# Confd
&& curl -L https://github.com/kelseyhightower/confd/releases/download/v$CONFD_VERSION/confd-${CONFD_VERSION}-linux-amd64 -o /usr/local/bin/confd \
&& chmod 555 /usr/local/bin/confd \

# Dumb Init
&& wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.0.0/dumb-init_1.0.0_amd64 \
&& chmod +x /usr/bin/dumb-init \
# Dumb Init
&& wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 \
&& chmod +x /usr/bin/dumb-init \

# SSH Key for fleet
&& mkdir /root/.ssh \
&& chmod 500 /root/.ssh \
&& chown -R root:root /root/.ssh \
# SSH Key for fleet
&& mkdir /root/.ssh \
&& chmod 500 /root/.ssh \
&& chown -R root:root /root/.ssh \

# Cleanup
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /root/.cache/*
# Cleanup
&& rm -rf /tmp/*

# App dependencies
# Application dependencies
ADD requirements.txt /opt/cluster-deployer/requirements.txt
RUN apt-get update --fix-missing \
# Install dev packages for build (Remove them in the end)
&& apt-get install -y gcc libffi-dev libssl-dev \
&& pip install -r /opt/cluster-deployer/requirements.txt \
# Cleanup
&& apt-get -y remove gcc libffi-dev libssl-dev \
&& apt-get clean \
&& rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /tmp/* /root/.cache/*


# Supervisor Scripts
ADD bin/supervisord-wrapper.sh /usr/sbin/supervisord-wrapper.sh
RUN chmod +x /usr/sbin/supervisord-wrapper.sh

# Confd Defaults
ADD bin/confd-wrapper.sh /usr/sbin/confd-wrapper.sh
RUN chmod +x /usr/sbin/confd-wrapper.sh

# SSH Keys
ADD bin/decrypt-ssh-keys.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/decrypt-ssh-keys.sh
RUN apk add --no-cache --update --virtual build-dependencies \
musl-dev \
linux-headers \
build-base \
pcre-dev \
libffi-dev \
openssl-dev \

# Python depdencies
&& pip install --ignore-installed --no-cache-dir \
supervisor==3.2.3 \
supervisor-stdout \
-r /opt/cluster-deployer/requirements.txt \

# Supervisor (Post Setup)
&& mkdir -p /var/log/supervisor \
&& ln -sf /etc/supervisor/supervisord.conf /etc/supervisord.conf \

# Cleanup
&& apk del build-dependencies \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) -exec echo rm -rf '{}' + \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) -exec echo rm -f '{}' +


# Custom Scripts
ADD bin/*.sh /usr/sbin/
RUN chmod +x /usr/sbin/*.sh

# Etc Config
ADD etc /etc
Expand All @@ -77,4 +72,4 @@ EXPOSE 9000

WORKDIR /opt/cluster-deployer

CMD ["/usr/bin/dumb-init", "/usr/sbin/supervisord-wrapper.sh"]
CMD ["/usr/bin/dumb-init", "/usr/sbin/supervisord-wrapper.sh"]
4 changes: 3 additions & 1 deletion bin/confd-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -le
#!/bin/sh -e

. /usr/sbin/deployer-env.sh

sed -i -e "s|http[:]//172.17.42.1[:]4001|$ETCD_URL|g" -e "s|/totem|$ETCD_TOTEM_BASE|g" /etc/confd/confd.toml

Expand Down
4 changes: 3 additions & 1 deletion bin/decrypt-ssh-keys.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -el
#!/bin/sh -e

. /usr/sbin/deployer-env.sh

cp /root/.ssh/id_rsa.encrypted /root/.ssh/id_rsa.new
ssh-keygen -P "$SSH_PASSPHRASE" -N '' -p -f /root/.ssh/id_rsa.new
Expand Down
46 changes: 46 additions & 0 deletions bin/deployer-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh -e

export HOST_IP="${HOST_IP:-$(/sbin/ip route|awk '/default/ { print $3 }')}"
export ETCD_HOST="${ETCD_HOST:-$HOST_IP}"
export ETCD_PORT="${ETCD_PORT:-4001}"
export ETCD_URL="${ETCD_URL:-http://$ETCD_HOST:$ETCD_PORT}"
export ETCDCTL="${ETCDCTL:-etcdctl --peers $ETCD_URL}"
export TOTEM_ENV="${TOTEM_ENV:-local}"
export ETCD_TOTEM_BASE="${ETCD_TOTEM_BASE:-/totem}"
export ETCD_YODA_BASE="${ETCD_YODA_BASE:-/yoda}"
export CELERY_GEVENT_EXECUTORS="${CELERY_GEVENT_EXECUTORS:-1}"
export CELERY_GEVENT_CONCURRENCY="${CELERY_GEVENT_CONCURRENCY:-50}"
export CELERY_PREFORK_CONCURRENCY="${CELERY_PREFORK_CONCURRENCY:-2}"
export API_EXECUTORS="${API_EXECUTORS:-2}"
export C_FORCE_ROOT="${C_FORCE_ROOT:-true}"
export SSH_HOST_KEY="${SSH_HOST_KEY:-/root/.ssh/id_rsa}"
export AMQP_HOST="${AMQP_HOST:-$HOST_IP}"
export AMQP_PORT="${AMQP_PORT:-5672}"
export AMQP_USERNAME="${AMQP_USERNAME:-guest}"
export AMQP_PASSWORD="${AMQP_PASSWORD:-guest}"
export MONGODB_USERNAME="${MONGODB_USERNAME:-}"
export MONGODB_PASSWORD="${MONGODB_PASSWORD:-}"
export MONGODB_SERVERS="${MONGODB_SERVERS:-}"
export MONGODB_HOST="${MONGODB_HOST:-$HOST_IP}"
export MONGODB_PORT="${MONGODB_PORT:-27017}"
export MONGODB_DB="${MONGODB_DB}"
export MONGODB_AUTH_DB="${MONGODB_AUTH_DB}"
export BROKER_URL="${BROKER_URL}"
export SSH_PASSPHRASE="${SSH_PASSPHRASE}"
export GITHUB_TOKEN="${GITHUB_TOKEN}"
export FLEET_HOST="${FLEET_HOST:-$HOST_IP}"
export CLUSTER_NAME="${CLUSTER_NAME:-local}"
export QUAY_ORGANIZATION="${QUAY_ORGANIZATION:-totem}"
export QUAY_PREFIX="${QUAY_PREFIX:-totem-}"
export C_FORCE_ROOT=true
export ENCRYPTION_PASSPHRASE="${ENCRYPTION_PASSPHRASE:-changeit}"
export ENCRYPTION_S3_BUCKET="${ENCRYPTION_S3_BUCKET:-not-set}"
export ENCRYPTION_STORE="${ENCRYPTION_PROVIDER:-s3}"
export HIPCHAT_TOKEN="${HIPCHAT_TOKEN}"
export HIPCHAT_ENABLED="${HIPCHAT_ENABLED:-false}"
export HIPCHAT_TOKEN="${HIPCHAT_TOKEN}"
export HIPCHAT_ROOM="${HIPCHAT_ROOM:-not-set}"
export GITHUB_NOTIFICATION_ENABLED="${GITHUB_NOTIFICATION_ENABLED:-false}"
export BASE_URL="${BASE_URL:-http://$HOST_IP:9000}"
export LOG_IDENTIFIER="${LOG_IDENTIFIER:-cluster-deployer}"
export LOG_ROOT_LEVEL="${LOG_ROOT_LEVEL}"
74 changes: 17 additions & 57 deletions bin/supervisord-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
#!/bin/bash -le
#!/bin/sh -e

export HOST_IP="${HOST_IP:-$(/sbin/ip route|awk '/default/ { print $3 }')}"
export ETCD_HOST="${ETCD_HOST:-$HOST_IP}"
export ETCD_PORT="${ETCD_PORT:-4001}"
export ETCD_URL="${ETCD_URL:-http://$ETCD_HOST:$ETCD_PORT}"
export ETCDCTL="${ETCDCTL:-etcdctl --peers $ETCD_URL}"
export ETCD_TOTEM_BASE="${ETCD_TOTEM_BASE}"
export ETCD_YODA_BASE="${ETCD_YODA_BASE:-/yoda}"
export CELERY_GEVENT_EXECUTORS="${CELERY_GEVENT_EXECUTORS:-1}"
export CELERY_GEVENT_CONCURRENCY="${CELERY_GEVENT_CONCURRENCY:-50}"
export CELERY_PREFORK_CONCURRENCY="${CELERY_PREFORK_CONCURRENCY:-2}"
export API_EXECUTORS="${API_EXECUTORS:-2}"
export C_FORCE_ROOT="${C_FORCE_ROOT:-true}"
export SSH_HOST_KEY="${SSH_HOST_KEY:-/root/.ssh/id_rsa}"
export AMQP_HOST="${AMQP_HOST:-$HOST_IP}"
export AMQP_PORT="${AMQP_PORT:-5672}"
export AMQP_USERNAME="${AMQP_USERNAME:-guest}"
export AMQP_PASSWORD="${AMQP_PASSWORD:-guest}"
export MONGODB_USERNAME="${MONGODB_USERNAME:-}"
export MONGODB_PASSWORD="${MONGODB_PASSWORD:-}"
export MONGODB_SERVERS="${MONGODB_SERVERS:-}"
export MONGODB_HOST="${MONGODB_HOST:-$HOST_IP}"
export MONGODB_PORT="${MONGODB_PORT:-27017}"
export MONGODB_DB="${MONGODB_DB}"
export MONGODB_AUTH_DB="${MONGODB_AUTH_DB}"
export BROKER_URL="${BROKER_URL}"
export SSH_PASSPHRASE="${SSH_PASSPHRASE}"
export GITHUB_TOKEN="${GITHUB_TOKEN}"
export FLEET_HOST="${FLEET_HOST:-$HOST_IP}"
export CLUSTER_NAME="${CLUSTER_NAME:-local}"
export TOTEM_ENV="${TOTEM_ENV:-local}"
export QUAY_ORGANIZATION="${QUAY_ORGANIZATION:-totem}"
export QUAY_PREFIX="${QUAY_PREFIX:-totem-}"
export C_FORCE_ROOT=true
export ENCRYPTION_PASSPHRASE="${ENCRYPTION_PASSPHRASE:-changeit}"
export ENCRYPTION_S3_BUCKET="${ENCRYPTION_S3_BUCKET:-not-set}"
export ENCRYPTION_STORE="${ENCRYPTION_PROVIDER:-s3}"
export HIPCHAT_TOKEN="${HIPCHAT_TOKEN}"
export HIPCHAT_ENABLED="${HIPCHAT_ENABLED:-false}"
export HIPCHAT_TOKEN="${HIPCHAT_TOKEN}"
export HIPCHAT_ROOM="${HIPCHAT_ROOM:-not-set}"
export GITHUB_NOTIFICATION_ENABLED="${GITHUB_NOTIFICATION_ENABLED:-false}"
export BASE_URL="${BASE_URL:-http://$HOST_IP:9000}"
export LOG_IDENTIFIER="${LOG_IDENTIFIER:-cluster-deployer}"
export LOG_ROOT_LEVEL="${LOG_ROOT_LEVEL}"
. /usr/sbin/deployer-env.sh

until $ETCDCTL cluster-health; do
>&2 echo "Etcdctl cluster not healthy - sleeping"
Expand All @@ -56,20 +13,23 @@ if ls celerybeat* 2>/dev/null; then
fi

if [ "$DISCOVER_RABBITMQ" == "true" ]; then
AMQP_HOST="$($ETCDCTL ls ${ETCD_TOTEM_BASE}/rabbitmq/nodes | xargs -L1 etcdctl get | tr '\n' ',')"
if [ ! -z "$AMQP_HOST" ]; then
echo "No rabbitmq nodes could be discovered. Exiting cluster-deployer"
exit 1
fi
export AMQP_HOST="$($ETCDCTL ls $ETCD_TOTEM_BASE/rabbitmq/nodes | xargs -n 1 $ETCDCTL get | xargs echo -n | tr ' ' ',')"
until [ ! -z "$AMQP_HOST" ]; do
>&2 echo "Rabbitmq could not be discovered - sleeping"
sleep 10
export AMQP_HOST="$($ETCDCTL ls $ETCD_TOTEM_BASE/rabbitmq/nodes | xargs -n 1 $ETCDCTL get | xargs echo -n | tr ' ' ',')"
done
fi

if [ "$DISCOVER_MONGO" == "true" ]; then
MONGODB_SERVERS="$($ETCDCTL ls ${ETCD_TOTEM_BASE}/mongodb/nodes | xargs -L1 etcdctl get | tr '\n' ',')"
if [ ! -z "$MONGODB_SERVERS" ]; then
echo "No mongodb nodes could be discovered. Exiting cluster-deployer"
exit 1
fi
export MONGODB_SERVERS="$($ETCDCTL ls $ETCD_TOTEM_BASE/mongo/nodes | xargs -n 1 $ETCDCTL get | xargs echo -n | tr ' ' ',')"
until [ ! -z "$MONGODB_SERVERS" ]; do
>&2 echo "Mongo servers could not be discovered - sleeping"
sleep 10
export MONGODB_SERVERS="$($ETCDCTL ls $ETCD_TOTEM_BASE/mongo/nodes | xargs -n 1 $ETCDCTL get | xargs echo -n | tr ' ' ',')"
done
fi

/bin/bash -le -c " envsubst < /etc/supervisor/conf.d/supervisord.conf.template > /etc/supervisor/conf.d/supervisord.conf; \
/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf"
envsubst < /etc/supervisor/conf.d/supervisord.conf.template > /etc/supervisor/conf.d/supervisord.conf
/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf

2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
ETCD_HOST: 'etcd.local'
AMQP_HOST: 'rabbitmq.local'
MONGODB_SERVERS: 'mongo.local:27017'
DISCOVER_MONGO: 'false'
DISCOVER_RABBITMQ: 'true'
expose:
- 9000

Expand Down
2 changes: 1 addition & 1 deletion etc/confd/conf.d/id_rsa.encrypted.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ mode = "0600"
keys = [
"ssh"
]
reload_cmd = "/bin/bash -c '/usr/local/bin/decrypt-ssh-keys.sh 2>&1 | logger -p local0.info -t \"id_rsa_reload[$$]\"'"
reload_cmd = "/bin/bash -c '/usr/sbin/decrypt-ssh-keys.sh 2>&1 | logger -p local0.info -t \"id_rsa_reload[$$]\"'"
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ Flask==0.10.1
Flask-Cors==2.1.2
pymongo==3.2.2
gevent==1.1.1
uWSGI==2.0.12
# Uncomment below , when 2.0.13 is released See https://github.com/gliderlabs/docker-alpine/issues/158#issuecomment-205401343
# uWSGI==2.0.13
https://github.com/unbit/uwsgi/archive/uwsgi-2.0.zip#egg=uwsgi
python-etcd==0.3.2
future==0.15.2
pytz==2016.3
Expand Down

0 comments on commit 4126ad7

Please sign in to comment.