more useful motd message, added shortcut for various tools
[discourse_docker.git] / templates / web.template.yml
index 53ee7eb1702af0220ba85e6a8903482f36d51ba2..ee53dde684a77da7d413b2f5ed0e693a0ae0b115 100644 (file)
@@ -7,9 +7,9 @@ env:
   # this ensures we have enough heap space to handle a big pile of small reqs
   RUBY_HEAP_MIN_SLOTS: 800000
 
-  POSTGRES_SOCKET: /var/run/postgresql
-  POSTGRES_URL: pg://discourse@localhost
-  POSTGRES_DB: discourse
+  DISCOURSE_DB_SOCKET: /var/run/postgresql
+  DISCOURSE_DB_HOST:
+  DISCOURSE_DB_PORT:
 
 
 params:
@@ -19,6 +19,23 @@ params:
   home: /var/www/discourse
 
 run:
+  - file:
+     path: /etc/service/copy_env/run
+     chmod: "+x"
+     contents: |
+        #!/bin/bash
+        env > ~/boot_env
+        conf=/var/www/discourse/config/discourse.conf
+        sudo -u discourse echo > $conf
+
+        for x in `env | /usr/bin/awk -F= '{if($1 ~ /DISCOURSE_/) print $1}'`
+          do
+             c=${x,,}
+             c=${c:10}
+             echo "$c"=${!x} >> $conf
+          done
+        # I dunno there may be a cleaner way to handle this
+        exec sleep 2147483647
 
   - file:
      path: /etc/service/unicorn/run
@@ -28,6 +45,7 @@ run:
         exec 2>&1
         # redis
         # postgres
+        sv start copy_env || exit 1
         cd $home
         exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
 
@@ -39,6 +57,7 @@ run:
         exec 2>&1
         # redis
         # postgres
+        sv start copy_env || exit 1
         cd $home
         exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec sidekiq
 
@@ -60,14 +79,18 @@ run:
         - git checkout $version
         - mkdir -p tmp/pids
         - mkdir -p tmp/sockets
-        - touch tmp/.gitkeep
         - mkdir -p /shared/log/rails
+        - mkdir -p /shared/uploads
+        - mkdir -p /shared/backups
+        - touch tmp/.gitkeep
         - rm -r log
         - ln -s /shared/log/rails $home/log
-        - mkdir -p /shared/uploads
         - ln -s /shared/uploads $home/public/uploads
-        - chown -R discourse:www-data /shared/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
+
   - exec:
       cmd:
         - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
@@ -97,8 +120,43 @@ run:
   - exec:
       cd: $home
       cmd:
+        # ensure we are on latest bundler
+        - gem update bundler
+        - mkdir -p /shared/vendor_bundle
+        - cp -fr /shared/vendor_bundle/* vendor/bundle || echo "can not copy"
         - chown -R discourse $home
         - sudo -E -u discourse bundle install --deployment --verbose --without test --without development
+        - cp -fr vendor/bundle/* /shared/vendor_bundle
         - sudo -E -u discourse bundle exec rake db:migrate
         - sudo -E -u discourse bundle exec rake assets:precompile
 
+  - file:
+     path: /usr/local/bin/discourse
+     chmod: +x
+     contents: |
+       #!/bin/bash
+       (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@")
+
+  - file:
+     path: /usr/local/bin/rails
+     chmod: +x
+     contents: |
+       #!/bin/bash
+       (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@")
+
+  - file:
+     path: /usr/local/bin/rake
+     chmod: +x
+     contents: |
+       #!/bin/bash
+       (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@")
+
+  - file:
+     path: /etc/update-motd.d/10-web
+     chmod: +x
+     contents: |
+       #!/bin/bash
+       echo
+       echo Use: rails, rake or discourse to execute commands in production
+       echo
+