From 3d47814c5e09706e0db58e38aae35452b219f15a Mon Sep 17 00:00:00 2001 From: Feike Steenbergen Date: Wed, 15 Jun 2016 12:51:07 +0200 Subject: [PATCH 1/3] Upgrade to Ubuntu 16.04 And make the Dockerfile build again --- Dockerfile | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 12f6157c..a4977f85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,38 @@ ## This Dockerfile is meant to aid in the building and debugging patroni whilst developing on your local machine ## It has all the necessary components to play/debug with a single node appliance, running etcd -FROM ubuntu:14.04 +FROM ubuntu:16.04 MAINTAINER Feike Steenbergen # We need curl -RUN apt-get update -y && apt-get install curl -y +RUN echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/01norecommend +RUN echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/01norecommend # Add PGDG repositories -RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list -RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - -RUN apt-get update -y -RUN apt-get upgrade -y - ENV PGVERSION 9.5 -RUN apt-get install postgresql-${PGVERSION} postgresql-server-dev-${PGVERSION} -y -RUN apt-get install python python-dev python-pip -y -ADD requirements-py2.txt /requirements-py2.txt -RUN pip install -r /requirements-py2.txt +RUN apt-get update -y \ + && apt-get upgrade -y \ + && apt-get install -y curl postgresql-${PGVERSION} python-psycopg2 python-yaml python-requests python-six python-click \ + python-dateutil python-tzlocal python-urllib3 python-dnspython python-pip python-setuptools python-kazoo python \ + && pip install python-etcd==0.4.3 python-consul \ + && apt-get remove -y python-pip python-setuptools \ + && apt-get autoremove -y \ + # Clean up + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* ENV PATH /usr/lib/postgresql/${PGVERSION}/bin:$PATH -ADD patroni.py /patroni.py -ADD patronictl.py /patronictl.py -ADD patroni/ /patroni +ADD patronictl.py patroni.py docker/entrypoint.sh / +ADD patroni /patroni/ +RUN ln -s /patroni/patroni.py /usr/local/bin/patroni \ + && ln -s /patroni/patronictl.py /usr/local/bin/patronictl -RUN ln -s /patroni.py /usr/local/bin/patroni -RUN ln -s /patronictl.py /usr/local/bin/patronictl - -ENV ETCDVERSION 2.2.5 +ENV ETCDVERSION 2.3.6 RUN curl -L https://github.com/coreos/etcd/releases/download/v${ETCDVERSION}/etcd-v${ETCDVERSION}-linux-amd64.tar.gz | tar xz -C /bin --strip=1 --wildcards --no-anchored etcd etcdctl ### Setting up a simple script that will serve as an entrypoint -RUN mkdir /data/ && touch /var/log/etcd.log /var/log/etcd.err /pgpass /patroni/postgres.yml -RUN chown postgres:postgres -R /patroni/ /data/ /pgpass /var/log/etcd.* /patroni/postgres.yml -ADD docker/entrypoint.sh /entrypoint.sh +RUN mkdir /data/ && touch /var/log/etcd.log /var/log/etcd.err /pgpass /patroni/postgres.yml \ + && chown postgres:postgres -R /patroni/ /data/ /pgpass /var/log/etcd.* /patroni/postgres.yml EXPOSE 4001 5432 2380 From 8ddb5908f29cd6338f2bae99e57d481bbd3afb9f Mon Sep 17 00:00:00 2001 From: Feike Steenbergen Date: Wed, 15 Jun 2016 13:15:17 +0200 Subject: [PATCH 2/3] Reduce configuration for Docker dev environment And rely mostly on the newly implemented environment variables --- docker/entrypoint.sh | 67 +++++++++++++------------------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 9bf176bb..ab1cd817 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -70,6 +70,7 @@ while getopts "$optspec" optchar; do esac done +## We start an etcd if [ -z ${ETCD_CLUSTER} ] then etcd --data-dir /tmp/etcd.data \ @@ -79,61 +80,33 @@ then ETCD_CLUSTER="127.0.0.1:4001" fi -mkdir -p ~postgres/.config/patroni -cat > ~postgres/.config/patroni/patronictl.yaml <<__EOF__ -{dcs_api: 'etcd://${ETCD_CLUSTER}', namespace: /service/} -__EOF__ +export PATRONI_SCOPE +export PATRONI_NAME="${HOSTNAME}" +export PATRONI_ETCD_HOST="$ETCD_CLUSTER" +export PATRONI_RESTAPI_CONNECT_ADDRESS="${DOCKER_IP}:8008" +export PATRONI_RESTAPI_LISTEN="0.0.0.0:8008" +export PATRONI_admin_PASSWORD="admin" +export PATRONI_admin_OPTIONS="createdb, createrole" +export PATRONI_POSTGRESQL_CONNECT_ADDRESS="${DOCKER_IP}:5432" +export PATRONI_POSTGRESQL_LISTEN="0.0.0.0:5432" +export PATRONI_POSTGRESQL_DATA_DIR="data/${PATRONI_SCOPE}" +export PATRONI_REPLICATION_USERNAME="replicator" +export PATRONI_REPLICATION_PASSWORD="abcd" +export PATRONI_SUPERUSER_USERNAME="postgres" +export PATRONI_SUPERUSER_PASSWORD="postgres" +export PATRONI_POSTGRESQL_PGPASS="$HOME/.pgpass" cat > /patroni/postgres.yaml <<__EOF__ +bootstrap: + dcs: + postgresql: + use_pg_rewind: true -ttl: &ttl 30 -loop_wait: &loop_wait 10 -scope: &scope '${PATRONI_SCOPE}' -namespace: 'patroni' -restapi: - listen: 0.0.0.0:8008 - connect_address: ${DOCKER_IP}:8008 -etcd: - scope: *scope - ttl: *ttl - host: ${ETCD_CLUSTER} -postgresql: - name: ${HOSTNAME} - scope: *scope - listen: 0.0.0.0:5432 - connect_address: ${DOCKER_IP}:5432 - data_dir: data/postgresql0 - maximum_lag_on_failover: 1048576 # 1 megabyte in bytes pg_hba: - host all all 0.0.0.0/0 md5 - - hostssl all all 0.0.0.0/0 md5 - host replication replicator ${DOCKER_IP}/16 md5 - replication: - username: replicator - password: rep-pass - network: 127.0.0.1/32 - superuser: - password: zalando - restore: patroni/scripts/restore.py - admin: - username: admin - password: admin - parameters: - archive_mode: "on" - wal_level: hot_standby - archive_command: 'true' - max_wal_senders: 20 - listen_addresses: 0.0.0.0 - max_wal_size: 1GB - min_wal_size: 128MB - wal_keep_segments: 64 - archive_timeout: 1800s - max_replication_slots: 20 - hot_standby: "on" __EOF__ -cat /patroni/postgres.yaml - if [ ! -z $CHEAT ] then while : From 8e59118271553b6ec80a086a81af272631e1c897 Mon Sep 17 00:00:00 2001 From: Feike Steenbergen Date: Wed, 15 Jun 2016 13:37:32 +0200 Subject: [PATCH 3/3] Remove leftovers --- .gitignore | 1 + Dockerfile | 2 -- docker/entrypoint.sh | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 699794c2..fbb294d4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ build/ coverage.xml junit.xml pgpass +scm-source.json diff --git a/Dockerfile b/Dockerfile index a4977f85..421e775f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,11 +3,9 @@ FROM ubuntu:16.04 MAINTAINER Feike Steenbergen -# We need curl RUN echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/01norecommend RUN echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/01norecommend -# Add PGDG repositories ENV PGVERSION 9.5 RUN apt-get update -y \ && apt-get upgrade -y \ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index ab1cd817..c329d2bb 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -107,6 +107,9 @@ bootstrap: - host replication replicator ${DOCKER_IP}/16 md5 __EOF__ +mkdir -p "$HOME/.config/patroni" +ln -s /patroni/postgres.yaml "$HOME/.config/patroni/patronictl.yaml" + if [ ! -z $CHEAT ] then while :