From 39467745f1395d52143890a1e11488fedab0d457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20MOUCHET?= Date: Sun, 30 Nov 2014 15:04:51 +0000 Subject: [PATCH] ADDED: - Data only container for Postgres db & CKAN FileStore - Nginx container (still based on official container, but copies the config for portability) UPDATED: - Postgres Dockerfile to allow custom PGDATA directory & initiate it if it's not there or is empty - fig.ml to reflect the latest changes (datapusher, nginx, data container) --- Dockerfile | 2 +- docker/data/Dockerfile | 19 +++++++++++++++++++ docker/nginx/Dockerfile | 2 ++ {_etc => docker}/nginx/nginx.conf | 0 docker/postgres/Dockerfile | 7 +++++-- docker/postgres/svc/postgresql/run | 29 ++++++++++++++++++++++++++++- fig.yml | 15 ++++++++++++--- 7 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 docker/data/Dockerfile create mode 100644 docker/nginx/Dockerfile rename {_etc => docker}/nginx/nginx.conf (100%) diff --git a/Dockerfile b/Dockerfile index 570a752..fd08e56 100755 --- a/Dockerfile +++ b/Dockerfile @@ -90,7 +90,7 @@ ADD docker/ckan/svc/ /etc/service/ CMD ["/sbin/my_init"] -VOLUME ["/usr/lib/ckan", "/etc/ckan"] +VOLUME ["/usr/lib/ckan", "/var/lib/ckan", "/etc/ckan"] EXPOSE 8080 RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/docker/data/Dockerfile b/docker/data/Dockerfile new file mode 100644 index 0000000..781bb7b --- /dev/null +++ b/docker/data/Dockerfile @@ -0,0 +1,19 @@ +FROM phusion/baseimage:0.9.15 +MAINTAINER Open Knowledge + +# set UTF-8 locale +RUN locale-gen en_US.UTF-8 && \ + echo 'LANG="en_US.UTF-8"' > /etc/default/locale + +ENV CKAN_DATA /var/lib/ckan +ENV PGDATA /etc/postgresql/9.3/main + +RUN mkdir -p $CKAN_DATA && chown -R www-data:www-data $CKAN_DATA + +RUN echo "postgres:x:107:" >> /etc/group +RUN echo "postgres:x:103:107:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash" >> /etc/passwd +RUN mkdir -p $PGDATA && chown -R postgres:postgres $PGDATA + +CMD ["/sbin/my_init"] + +VOLUME ["/var/lib/ckan", "/etc/postgresql/9.3/main"] diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..77b4243 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:1.7.6 +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/_etc/nginx/nginx.conf b/docker/nginx/nginx.conf similarity index 100% rename from _etc/nginx/nginx.conf rename to docker/nginx/nginx.conf diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile index df47e8e..18962b5 100755 --- a/docker/postgres/Dockerfile +++ b/docker/postgres/Dockerfile @@ -24,9 +24,12 @@ ENV DATASTORE_DB datastore ENV DATASTORE_USER datastore_user ENV DATASTORE_PASS datastore_pass +ENV PGDATA /etc/postgresql/9.3/main +RUN mkdir -p $PGDATA && chown -R postgres $PGDATA && chmod -R 700 $PGDATA + # Allow connections from anywhere with valid credentials (md5) -RUN sed -i -e"s/^#listen_addresses =.*$/listen_addresses = '*'/" /etc/postgresql/9.3/main/postgresql.conf -RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf +RUN sed -i -e "s|^#listen_addresses =.*$|listen_addresses = '*'|" $PGDATA/postgresql.conf +RUN echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf # Configure runit RUN touch /configure_db diff --git a/docker/postgres/svc/postgresql/run b/docker/postgres/svc/postgresql/run index 9f2a59c..2cfb8dc 100755 --- a/docker/postgres/svc/postgresql/run +++ b/docker/postgres/svc/postgresql/run @@ -76,8 +76,35 @@ init_db_when_ready () { init_db } +if [[ ! -d "$PGDATA" ]]; then + echo "Creating Postgres Directory..." + # create dirs if needed + mkdir -p $PGDATA + # Ensure postgres owns the PGDATA + chown -R postgres $PGDATA + # Ensure we have the right permissions set on the PGDATA + chmod -R 700 $PGDATA +fi + +# initialize db if needed +if [[ ! "$(ls -A $PGDATA)" ]]; then + echo "Initializing PostgreSQL..." + chown -R postgres $PGDATA + # postgres initdb + setuser postgres /usr/lib/postgresql/9.3/bin/initdb --locale=en_US.UTF-8 --encoding=UNICODE $PGDATA/ + # Update postgresql.conf settings + sed -i -e "s|^#listen_addresses =.*$|listen_addresses = '*'|" $PGDATA/postgresql.conf + sed -i -e "s|^#data_directory =.*$|data_directory = '/var/lib/postgresql/9.3/main'|" $PGDATA/postgresql.conf + sed -i -e "s|^#hba_file =.*$|hba_file = '/etc/postgresql/9.3/main/pg_hba.conf'|" $PGDATA/postgresql.conf + sed -i -e "s|^#ident_file =.*$|ident_file = '/etc/postgresql/9.3/main/pg_ident.conf'|" $PGDATA/postgresql.conf + sed -i -e "s|^#external_pid_file =.*$|external_pid_file = '/var/run/postgresql/9.3-main.pid'|" $PGDATA/postgresql.conf + # Allow connections from anywhere with valid credentials (md5) + echo "local all postgres peer" >> $PGDATA/pg_hba.conf + echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf +fi + init_db_when_ready & # Start PostgreSQL echo "Starting PostgreSQL..." -setuser postgres /usr/lib/postgresql/9.3/bin/postgres -D /etc/postgresql/9.3/main +setuser postgres /usr/lib/postgresql/9.3/bin/postgres -D $PGDATA diff --git a/fig.yml b/fig.yml index 61ed296..ccff58c 100755 --- a/fig.yml +++ b/fig.yml @@ -1,9 +1,16 @@ +data: + build: docker/data + hostname: data + domainname: localdomain + postgres: build: docker/postgres hostname: postgres domainname: localdomain ports: - "5432:5432" + volumes_from: + - data environment: - CKAN_PASS=ckan_pass - DATASTORE_PASS=datastore_pass @@ -18,7 +25,7 @@ solr: - ./_src/ckan/ckan/config/solr/schema.xml:/opt/solr/example/solr/ckan/conf/schema.xml datapusher: - build: _service-provider/datapusher + build: _service-provider/_datapusher hostname: datapusher domainname: localdomain ports: @@ -37,13 +44,15 @@ ckan: - solr:solr - datapusher:datapusher command: /sbin/my_init --enable-insecure-key + volumes_from: + - data volumes: - ./_src:/usr/lib/ckan/default/src - ./_etc/ckan/custom_options.ini:/etc/ckan/default/custom_options.ini - ./_etc/supervisor/conf.d:/etc/supervisor/conf.d nginx: - image: nginx:1.7.6 + build: docker/nginx hostname: nginx domainname: localdomain links: @@ -51,7 +60,7 @@ nginx: ports: - "80:80" volumes: - - ./_etc/nginx/nginx.conf:/etc/nginx/nginx.conf + - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf