From f03bd561e8f2f33ddc75350a359b247f790ab7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 19 Sep 2017 13:31:31 +0200 Subject: [PATCH] Move all docker relevant files from CE into core --- Dockerfile | 1 + Dockerfile.public | 37 +++++++++++++++++++++++++ docker/entrypoint | 61 +++++++++++++++++++++++++++++++++++++++++ docker/proxy | 5 ++++ docker/proxy.conf.erb | 11 ++++++++ docker/supervisord.conf | 52 +++++++++++++++++++++++++++++++++++ vendored-plugins/.keep | 0 7 files changed, 167 insertions(+) create mode 100644 Dockerfile.public create mode 100755 docker/entrypoint create mode 100755 docker/proxy create mode 100644 docker/proxy.conf.erb create mode 100644 docker/supervisord.conf create mode 100644 vendored-plugins/.keep diff --git a/Dockerfile b/Dockerfile index 770c1ac166..c430ff478f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ RUN echo "loglevel=info" >> /usr/local/etc/npmrc COPY Gemfile ./Gemfile COPY Gemfile.* ./ +COPY vendored-plugins ./vendored-plugins RUN chown -R app:app /usr/src/app USER app diff --git a/Dockerfile.public b/Dockerfile.public new file mode 100644 index 0000000000..a08f56fdb7 --- /dev/null +++ b/Dockerfile.public @@ -0,0 +1,37 @@ +FROM openproject/community:edge-base +MAINTAINER operations@openproject.com + +ENV DATABASE_URL=postgres://openproject:openproject@127.0.0.1/openproject +ENV RAILS_ENV=production +ENV HEROKU=true +ENV ATTACHMENTS_STORAGE_PATH=/var/db/openproject/files +ENV RAILS_CACHE_STORE=memcache +ENV SECRET_KEY_BASE=OVERWRITE_ME + +USER root +RUN apt-get update -qq && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + memcached \ + postfix \ + postgresql \ + apache2 \ + supervisor && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN a2enmod proxy proxy_http && rm -f /etc/apache2/sites-enabled/000-default.conf + +RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.4/main/pg_hba.conf +RUN echo "listen_addresses='*'" >> /etc/postgresql/9.4/main/postgresql.conf +RUN rm -rf /var/lib/postgresql/9.4/main && mkdir -p /var/lib/postgresql/9.4/main && chown -R postgres:postgres /var/lib/postgresql/9.4 +RUN mkdir -p /var/db/openproject/{files,git,svn} && chown -R app:app /var/db/openproject + +COPY docker /usr/src/app/docker +COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# ports +EXPOSE 80 5432 + +# volumes to export +VOLUME ["/var/lib/postgresql/9.4/main", "/var/db/openproject"] + +CMD ["/usr/src/app/docker/entrypoint"] \ No newline at end of file diff --git a/docker/entrypoint b/docker/entrypoint new file mode 100755 index 0000000000..c8c2d822bf --- /dev/null +++ b/docker/entrypoint @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e +set -o pipefail + +PGDATA=${PGDATA:=/var/lib/postgresql/9.4/main} +PGUSER=${PGUSER:=postgres} +PGPASSWORD=${PGPASSWORD:=postgres} +PGBIN="/usr/lib/postgresql/9.4/bin" + +if [ ! -z "$ATTACHMENTS_STORAGE_PATH" ]; then + mkdir -p "$ATTACHMENTS_STORAGE_PATH" + chown -R app:app "$ATTACHMENTS_STORAGE_PATH" +fi + +dbhost=$(ruby -ruri -e 'puts URI(ENV.fetch("DATABASE_URL")).host') +pwfile=$(mktemp) +chown postgres $pwfile +echo "$PGPASSWORD" > $pwfile + +indent() { + sed -u 's/^/ /' +} + +migrate() { + pushd /usr/src/app + /etc/init.d/memcached start + rake db:migrate db:seed + /etc/init.d/memcached stop + chown app:app db/schema.rb + popd +} + +if [ "$dbhost" = "127.0.0.1" ]; then + # initialize cluster if it does not exist yet + if [ -f "$PGDATA/PG_VERSION" ]; then + echo "-----> Database cluster already exists, not modifying." + /etc/init.d/postgresql start | indent + migrate | indent + /etc/init.d/postgresql stop | indent + else + echo "-----> Database cluster not found. Creating a new one in $PGDATA..." + chown -R postgres:postgres $PGDATA + su postgres -c "$PGBIN/initdb --pgdata=${PGDATA} --username=${PGUSER} --encoding=unicode --auth=trust --pwfile=$pwfile" | indent + rm -f $pwfile + /etc/init.d/postgresql start | indent + su postgres -c "$PGBIN/psql --command \"CREATE USER openproject WITH SUPERUSER PASSWORD 'openproject';\"" | indent + su postgres -c "$PGBIN/createdb -O openproject openproject" | indent + migrate | indent + /etc/init.d/postgresql stop | indent + fi +else + echo "-----> You're using an external database. Not initializing a local database cluster." + migrate | indent +fi + +echo "-----> Database setup finished." +echo " On first installation, the default admin credentials are login: admin, password: admin" + +echo "-----> Launching supervisord..." +exec /usr/bin/supervisord diff --git a/docker/proxy b/docker/proxy new file mode 100755 index 0000000000..370d6caeb6 --- /dev/null +++ b/docker/proxy @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +[ -f /etc/apache2/sites-enabled/openproject.conf ] || erb -r time /usr/src/app/docker/proxy.conf.erb > /etc/apache2/sites-enabled/openproject.conf +exec /usr/sbin/apache2ctl -DFOREGROUND diff --git a/docker/proxy.conf.erb b/docker/proxy.conf.erb new file mode 100644 index 0000000000..360c70bd5d --- /dev/null +++ b/docker/proxy.conf.erb @@ -0,0 +1,11 @@ + + ServerName <%= ENV.fetch('SERVER_NAME') { "_default_" } %> + DocumentRoot /usr/src/app/public + + ProxyRequests off + + + ProxyPass http://127.0.0.1:8080/ retry=0 + ProxyPassReverse http://127.0.0.1:8080/ + + diff --git a/docker/supervisord.conf b/docker/supervisord.conf new file mode 100644 index 0000000000..c8f40ccbf6 --- /dev/null +++ b/docker/supervisord.conf @@ -0,0 +1,52 @@ +[supervisord] +nodaemon=true + +[program:web] +priority=4 +user=app +directory=/usr/src/app +command=./docker/web +autorestart=true +stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log +stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log + +[program:worker] +priority=5 +user=app +directory=/usr/src/app +command=./docker/worker +autorestart=true +stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log +stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log + +[program:memcached] +priority=100 +user=app +command=/usr/bin/memcached +autorestart=true +stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log +stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log + +[program:apache2] +priority=2 +directory=/usr/src/app +command=./docker/proxy +stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log +stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log + +[program:postfix] +priority=100 +directory=/etc/postfix +command=/usr/sbin/postfix -c /etc/postfix start +startsecs=0 +autorestart=false +stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log +stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log + +[program:postgres] +user=postgres +priority=1 +command=/usr/lib/postgresql/9.4/bin/postgres -D /var/lib/postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf +autorestart=true +stderr_logfile = /var/log/supervisor/%(program_name)s-stderr.log +stdout_logfile = /var/log/supervisor/%(program_name)s-stdout.log diff --git a/vendored-plugins/.keep b/vendored-plugins/.keep new file mode 100644 index 0000000000..e69de29bb2