- Update base image
authorSam <sam.saffron@gmail.com>
Wed, 20 Aug 2014 03:17:08 +0000 (13:17 +1000)
committerSam <sam.saffron@gmail.com>
Wed, 20 Aug 2014 03:17:08 +0000 (13:17 +1000)
- 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

14 files changed:
image/base/Dockerfile
image/base/cron [new file with mode: 0755]
image/base/rsyslog [new file with mode: 0755]
image/discourse/Dockerfile
launcher
samples/data.yml
samples/redis.yml
samples/standalone.yml
samples/web_only.yml
templates/cron.template.yml
templates/postgres.9.2.template.yml
templates/postgres.template.yml
templates/syslog.template.yml
templates/web.template.yml

index f76927e327e8cd1e50a4078fd7a1922ae9797a58..ac1c1a76dc71124467b2f6d604f7bf938a49906f 100644 (file)
@@ -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 (executable)
index 0000000..4170299
--- /dev/null
@@ -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 (executable)
index 0000000..c0a083b
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+exec 2>&1
+cd /
+exec rsyslogd -f
index ef9d855d0e0706282b4aa1ab8458386477a411ff..ba5043ba87c045423b36a1c2e903159fb36c4954 100644 (file)
@@ -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 &&\
index bfd79921ddb451910005557e11cf0a7918a329b5..3c89120890246a001791851719b326efe34d1653 100755 (executable)
--- 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 | \
index ddb6228f069219e671a9d2b083ce46e6ff9cf101..183a358f15064121cf911a728b466b988f6e1aad 100644 (file)
@@ -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
index 84b006eb35841efecac87e334c264261a5534c7a..1cb83cc7faca5fa091063e22d2b151adc3f46233 100644 (file)
@@ -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
index 6b1aba09614c3adb702f6d189aa2644fdb8e40b5..09bd75e1c8ab07f5b6cc99b7c7c1f53011858f62 100644 (file)
@@ -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
index bc093b28d69b73928f78379556cf7fc471e3751c..de287e59b53b32304c2699482b8db189121d0784 100644 (file)
@@ -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
index 259954a9295359b229be2737f1b914ffa20baa59..9f34c231245e755715e510feb4746ea37947cfb3 100644 (file)
@@ -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
index 3138a6edc541abc0d80b803a8ed0df56c9788f2c..ed78691da2b59e83e88763af144bf8f7a1542ca0 100644 (file)
@@ -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
index 8461a07bfb9afe13bdde6f035077d7292f15a9d8..d5b9612c0c7c6c4a875e079b0dfd390c82387290 100644 (file)
@@ -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!"
index 72c33392417fd53121e85f9f220c5170963cb91e..eae82750d066577ff4a30c8aa07ffc5fc58b8705 100644 (file)
@@ -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
 
index 6b0184ecd3827f17bc6fe9099c56413529b02e34..7579b50647a28dd02166eb8df6bc26c51d62defb 100644 (file)
@@ -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
+        }