From: Sam Date: Wed, 20 Aug 2014 03:17:08 +0000 (+1000) Subject: - Update base image X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=be82e068978bce338f50c33bb929b65357dd2049;p=discourse_docker.git - Update base image - Update discourse image - Include cron and rsyslogd in base image - Mount /var/log on host so we have access to nginx logs - Introduce log rotation - Correct symlink creation so it works with admin/upgrade - All sample paths are /var/discourse --- diff --git a/image/base/Dockerfile b/image/base/Dockerfile index f76927e..ac1c1a7 100644 --- a/image/base/Dockerfile +++ b/image/base/Dockerfile @@ -1,7 +1,9 @@ # Official repo only has a ppa for postgresql 9.3 at the moment (14/3/2014) # When new LTS ships we can upgrade -# VERSION 0.2.2 +# NAME: discourse_base +# VERSION: 1.0.0 + FROM ubuntu:14.04 MAINTAINER Sam Saffron "https://twitter.com/samsaffron" @@ -30,17 +32,11 @@ RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections &&\ postgresql-9.3 postgresql-client-9.3 \ postgresql-contrib-9.3 libpq-dev libreadline-dev \ nginx language-pack-en sudo cron \ - psmisc rsyslog &&\ + psmisc rsyslog vim &&\ dpkg-divert --local --rename --add /sbin/initctl &&\ sh -c "test -f /sbin/initctl || ln -s /bin/true /sbin/initctl" &&\ apt-get -y install redis-server haproxy openssh-server &&\ - echo 'gem: --no-document' >> /usr/local/etc/gemrc &&\ - mkdir /src && cd /src && git clone https://github.com/sstephenson/ruby-build.git &&\ - cd /src/ruby-build && ./install.sh &&\ - cd / && rm -rf /src/ruby-build && ruby-build 2.0.0-p481 /usr/local &&\ - gem update --system &&\ - gem install bundler &&\ - cd / && git clone https://github.com/SamSaffron/pups.git &&\ + cd / &&\ mkdir /jemalloc && cd /jemalloc &&\ wget http://www.canonware.com/download/jemalloc/jemalloc-3.4.1.tar.bz2 &&\ tar -xvjf jemalloc-3.4.1.tar.bz2 && cd jemalloc-3.4.1 && ./configure && make &&\ @@ -49,7 +45,7 @@ RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections &&\ mkdir -p /etc/runit/1.d &&\ apt-get clean &&\ rm -f /etc/apt/apt.conf.d/40proxy &&\ - locale-gen en_US && + locale-gen en_US &&\ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2 &&\ tar -xjf phantomjs-1.9.7-linux-x86_64.tar.bz2 &&\ rm phantomjs-1.9.7-linux-x86_64.tar.bz2 &&\ @@ -61,7 +57,20 @@ RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections &&\ cp pngout-20130221-linux/x86_64/pngout /bin/pngout &&\ rm -rf pngout-20130221-linux +RUN echo 'gem: --no-document' >> /usr/local/etc/gemrc &&\ + mkdir /src && cd /src && git clone https://github.com/sstephenson/ruby-build.git &&\ + cd /src/ruby-build && ./install.sh &&\ + cd / && rm -rf /src/ruby-build && ruby-build 2.0.0-p481 /usr/local &&\ + gem update --system &&\ + gem install bundler + +RUN cd / && git clone https://github.com/SamSaffron/pups.git ADD runit-1 /etc/runit/1 ADD runit-1.d-cleanup-pids /etc/runit/1.d/cleanup-pids ADD runit-2 /etc/runit/2 + +ADD cron /etc/service/cron/run +ADD rsyslog /etc/service/rsyslog/run + +RUN sed -i.bak 's/$ModLoad imklog/#$ModLoad imklog/' /etc/rsyslog.conf diff --git a/image/base/cron b/image/base/cron new file mode 100755 index 0000000..4170299 --- /dev/null +++ b/image/base/cron @@ -0,0 +1,4 @@ +#!/bin/bash +exec 2>&1 +cd / +exec cron -f diff --git a/image/base/rsyslog b/image/base/rsyslog new file mode 100755 index 0000000..c0a083b --- /dev/null +++ b/image/base/rsyslog @@ -0,0 +1,4 @@ +#!/bin/bash +exec 2>&1 +cd / +exec rsyslogd -f diff --git a/image/discourse/Dockerfile b/image/discourse/Dockerfile index ef9d855..ba5043b 100644 --- a/image/discourse/Dockerfile +++ b/image/discourse/Dockerfile @@ -1,5 +1,5 @@ -# Current version 0.2.5 -FROM samsaffron/discourse_base:0.2.3 +# Current version 1.0.0 +FROM samsaffron/discourse_base:1.0.0 MAINTAINER Sam Saffron "https://twitter.com/samsaffron" @@ -15,23 +15,9 @@ RUN useradd discourse -s /bin/bash -m -U &&\ sudo -u discourse RAILS4=1 bundle install --deployment \ --without test --without development &&\ cd /var/www/discourse/vendor/bundle &&\ - find . -name tmp -type d | xargs rm -rf && cd / &&\ - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2 &&\ - tar -xjf phantomjs-1.9.7-linux-x86_64.tar.bz2 &&\ - rm phantomjs-1.9.7-linux-x86_64.tar.bz2 &&\ - cp phantomjs-1.9.7-linux-x86_64/bin/phantomjs /bin/phantomjs &&\ - rm -fr phantomjs-1.9.7-linux-x86_64 + find . -name tmp -type d | xargs rm -rf + # For a smaller but less flexible image: #RUN apt-get -y autoremove build-essential gcc gcc-4.7 .+-dev #RUN echo image size: $(du -hsx /) - -# RUN cd /var/www/discourse && bundle exec rake db:test:prepare && bundle exec rspec - -# mkdir -p /src/godeb && cd /src/godeb && curl -O https://godeb.s3.amazonaws.com/godeb-amd64.tar.gz &&\ -# cd /src/godeb && tar -xzvf godeb-amd64.tar.gz &&\ -# cd /src/godeb && ./godeb install &&\ -# cd /src && git clone https://github.com/coreos/etcd.git &&\ -# cd /src/etcd && ./build &&\ -# cp /src/etcd/etcd /usr/local/bin &&\ -# add-apt-repository ppa:chris-lea/node.js &&\ diff --git a/launcher b/launcher index bfd7992..3c89120 100755 --- a/launcher +++ b/launcher @@ -13,7 +13,7 @@ config_file=containers/"$config".yml cidfile=cids/"$config".cid cidbootstrap=cids/"$config"_boostrap.cid local_discourse=local_discourse -image=samsaffron/discourse:0.2.5 +image=samsaffron/discourse:1.0.0 docker_path=`which docker.io || which docker` docker_ip=`/sbin/ifconfig | \ diff --git a/samples/data.yml b/samples/data.yml index ddb6228..183a358 100644 --- a/samples/data.yml +++ b/samples/data.yml @@ -1,8 +1,6 @@ # A container for all things Data, be sure to set a secret password for discourse account, SOME_SECRET is just an example # templates: - - "templates/cron.template.yml" - - "templates/syslog.template.yml" - "templates/postgres.template.yml" - "templates/redis.template.yml" - "templates/sshd.template.yml" @@ -33,5 +31,8 @@ hooks: # be sure to set the host location somewhere sane volumes: - volume: - host: /var/docker/shared + host: /var/discourse/shared/data guest: /shared + - volume: + host: /var/discourse/shared/data/log/var-log + guest: /var/log diff --git a/samples/redis.yml b/samples/redis.yml index 84b006e..1cb83cc 100644 --- a/samples/redis.yml +++ b/samples/redis.yml @@ -11,5 +11,8 @@ expose: volumes: - volume: - host: /var/docker/shared + host: /var/discourse/shared/redis guest: /shared + - volume: + host: /var/discourse/shared/redis/log/var-log + guest: /var/log diff --git a/samples/standalone.yml b/samples/standalone.yml index 6b1aba0..09bd75e 100644 --- a/samples/standalone.yml +++ b/samples/standalone.yml @@ -1,18 +1,16 @@ ## ## After making changes to this file, you MUST rebuild for any changes ## to take effect in your live Discourse instance: -## +## ## ./var/docker/launcher rebuild app ## ## this is the all-in-one, standalone Discourse Docker container template templates: - - "templates/cron.template.yml" - - "templates/syslog.template.yml" - "templates/postgres.template.yml" - "templates/redis.template.yml" - - "templates/sshd.template.yml" - "templates/web.template.yml" + - "templates/sshd.template.yml" ## which TCP/IP ports should this container expose? expose: @@ -53,8 +51,12 @@ env: ## These containers are stateless, all data is stored in /shared volumes: - volume: - host: /var/docker/shared/standalone + host: /var/discourse/shared/standalone guest: /shared +volumes: + - volume: + host: /var/discourse/shared/standalone/log/var-log + guest: /var/log ## The docker manager plugin allows you to one-click upgrade Discouse ## http://discourse.example.com/admin/docker diff --git a/samples/web_only.yml b/samples/web_only.yml index bc093b2..de287e5 100644 --- a/samples/web_only.yml +++ b/samples/web_only.yml @@ -32,8 +32,12 @@ env: volumes: - volume: - host: /var/docker/shared - guest: /shared + host: /var/discourse/shared/web-only + guest: /shared +volumes: + - volume: + host: /var/discourse/shared/web-only/log/var-log + guest: /var/log # you may use the docker manager to upgrade and monitor your docker image # UI will be visible at http://yoursite.com/admin/docker diff --git a/templates/cron.template.yml b/templates/cron.template.yml index 259954a..9f34c23 100644 --- a/templates/cron.template.yml +++ b/templates/cron.template.yml @@ -1,12 +1,4 @@ run: - - file: - path: /etc/service/cron/run - chmod: "+x" - contents: | - #!/bin/bash - exec 2>&1 - cd / - exec cron -f - exec: hook: cron - cmd: echo cron installed + cmd: echo cron is now included in base image, remove from templates diff --git a/templates/postgres.9.2.template.yml b/templates/postgres.9.2.template.yml index 3138a6e..ed78691 100644 --- a/templates/postgres.9.2.template.yml +++ b/templates/postgres.9.2.template.yml @@ -1,23 +1,4 @@ hooks: - after_cron: - - file: - path: /var/lib/postgresql/take-database-backup - chown: postgres:postgres - chmod: "+x" - contents: | - #!/bin/bash - ID=db-$(date +%F_%T) - FILENAME=/shared/postgres_backup/$ID.tar.gz - pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME - echo $FILENAME - - - file: - path: /var/spool/cron/crontabs/postgres - contents: | - # m h dom mon dow command - #MAILTO=? - 0 */4 * * * /var/lib/postgresql/take-database-backup - before_code: - replace: filename: /etc/service/unicorn/run diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml index 8461a07..d5b9612 100644 --- a/templates/postgres.template.yml +++ b/templates/postgres.template.yml @@ -5,25 +5,6 @@ params: db_default_text_search_config: "pg_catalog.english" hooks: - after_cron: - - file: - path: /var/lib/postgresql/take-database-backup - chown: postgres:postgres - chmod: "+x" - contents: | - #!/bin/bash - ID=db-$(date +%F_%T) - FILENAME=/shared/postgres_backup/$ID.tar.gz - pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME - echo $FILENAME - - - file: - path: /var/spool/cron/crontabs/postgres - contents: | - # m h dom mon dow command - #MAILTO=? - 0 */4 * * * /var/lib/postgresql/take-database-backup - before_code: - replace: filename: /etc/service/unicorn/run @@ -206,6 +187,24 @@ run: - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"' - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"' + - file: + path: /var/lib/postgresql/take-database-backup + chown: postgres:postgres + chmod: "+x" + contents: | + #!/bin/bash + ID=db-$(date +%F_%T) + FILENAME=/shared/postgres_backup/$ID.tar.gz + pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME + echo $FILENAME + + - file: + path: /var/spool/cron/crontabs/postgres + contents: | + # m h dom mon dow command + #MAILTO=? + 0 */4 * * * /var/lib/postgresql/take-database-backup + - exec: hook: postgres cmd: "echo postgres installed!" diff --git a/templates/syslog.template.yml b/templates/syslog.template.yml index 72c3339..eae8275 100644 --- a/templates/syslog.template.yml +++ b/templates/syslog.template.yml @@ -1,16 +1,3 @@ run: - - file: - path: /etc/service/rsyslog/run - chmod: "+x" - contents: | - #!/bin/bash - exec 2>&1 - cd / - exec rsyslogd -n - - - exec: apt-get -y install rsyslog - - replace: - filename: "/etc/rsyslog.conf" - from: "$ModLoad imklog" - to: "#$ModLoad imklog" + - exec: echo rsyslog template is included in base image, remove diff --git a/templates/web.template.yml b/templates/web.template.yml index 6b0184e..7579b50 100644 --- a/templates/web.template.yml +++ b/templates/web.template.yml @@ -69,13 +69,20 @@ run: - mkdir -p /shared/uploads - mkdir -p /shared/backups - touch tmp/.gitkeep - - rm -r log - - ln -s /shared/log/rails $home/log + - touch /shared/log/rails/production.log + - touch /shared/log/rails/production_errors.log + - touch /shared/log/rails/unicorn.stdout.log + - touch /shared/log/rails/unicorn.stderr.log + - ln -s /shared/log/rails/production.log $home/log/production.log + - ln -s /shared/log/rails/production_errors.log $home/log/production_errors.log + - ln -s /shared/log/rails/unicorn.stdout.log $home/log/unicorn.stdout.log + - ln -s /shared/log/rails/unicorn.stderr.log $home/log/unicorn.stderr.log - ln -s /shared/uploads $home/public/uploads - ln -s /shared/backups $home/public/backups - chown -R discourse:www-data /shared/log/rails - chown -R discourse:www-data /shared/uploads - chown -R discourse:www-data /shared/backups + - chown -R discourse:www-data $home/log - exec: cmd: @@ -156,3 +163,19 @@ run: echo Use: rails, rake or discourse to execute commands in production echo + - file: + path: /etc/logrotate.d/rails + contents: | + /shared/log/rails/*.log + { + rotate 14 + dateext + daily + missingok + notifempty + delaycompress + compress + postrotate + sv 1 unicorn + endscript + }