From 3694158822dbeae086c67b54157e131befcafaa9 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Sun, 3 Nov 2013 17:47:37 -0800 Subject: [PATCH] standalone sample --- launcher | 4 +- standalone.sample.yml | 208 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 standalone.sample.yml diff --git a/launcher b/launcher index 226547f..966c4df 100755 --- a/launcher +++ b/launcher @@ -104,8 +104,8 @@ case "$command" in if [ ! -e $cidfile ] then echo "No cid found, creating a new container" - ports=`cat $config_file | docker run -rm -i -a stdout -a stdin samsaffron/discourse ruby -e "require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| '-p ' << p.to_s << ' '}.join"` - echo $ports + ports=`cat $config_file | docker run -rm -i -a stdout -a stdin samsaffron/discourse ruby -e \ + "require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| '-p ' << p.to_s << ' '}.join"` docker run -cidfile $cidfile $ports -d -v `pwd`/shared:/shared samsaffron/discourse:$config /usr/bin/runsvdir -P /etc/service exit 0 else diff --git a/standalone.sample.yml b/standalone.sample.yml new file mode 100644 index 0000000..dc97da3 --- /dev/null +++ b/standalone.sample.yml @@ -0,0 +1,208 @@ +expose: + # expose public port 80 to map to private docker port 80 (web) + - "80:80" + # expose public port 2222 to map to private docker port 22 (ssh) + - "2222:22" + +# ENV is baked in to the image, any changes here require ./launcher bootstrap to run +env: + # Comma delimited list of emails, required if you want admin access for first account + DEVELOPER_EMAILS: 'YOUR_EMAIL@EMAIL.COM1' + # You can have redis on a different box + # REDIS_PROVIDER_URL: 'redis://l.discourse:6379' + RAILS_ENV: 'production' + RAILS4: 1 + UNICORN_WORKERS: 3 + +params: + # SSH key is required for remote access into the container + ssh_key: YOUR_SSH_KEY_HERE + version: HEAD + + home: /var/www/discourse + + # You can connect to any DB you wish to + database_yml: + production: + database: discourse + username: discourse + socket: /var/run/postgresql + password: + host: + host_names: + - YOUR_HOSTNAME_HERE + +run: + - file: + path: /etc/service/unicorn/run + chmod: "+x" + contents: | + #!/bin/bash + exec 2>&1 + $env + sv start redis || exit 1 + sv start postgres || exit 1 + cd $home + exec sudo -E -u discourse bundle exec unicorn -c config/unicorn.conf.rb + + - file: + path: /etc/service/sidekiq/run + chmod: "+x" + contents: | + #!/bin/bash + exec 2>&1 + $env + sv start redis || exit 1 + sv start postgres || exit 1 + cd $home + exec sudo -E -u discourse bundle exec sidekiq + + - file: + path: /etc/service/sshd/run + chmod: "+x" + contents: | + #!/bin/sh + exec 2>&1 + exec /usr/sbin/sshd -D -e + + - file: + path: /etc/service/redis/run + chmod: "+x" + contents: | + #!/bin/sh + exec 2>&1 + exec sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf + + - file: + path: /etc/service/nginx/run + chmod: "+x" + contents: | + #!/bin/sh + exec 2>&1 + exec /usr/sbin/nginx + + - file: + path: /etc/service/postgres/run + chmod: "+x" + contents: | + #!/bin/sh + exec 2>&1 + exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main + + + - exec: + cd: $home + cmd: + - git reset --hard + - git clean -f + - git pull + - git checkout $head + - cp config/database.yml.production-sample config/database.yml + - cp config/redis.yml.sample config/redis.yml + - cp config/environments/production.rb.sample config/environments/production.rb + - mkdir -p tmp/pids + - mkdir -p tmp/sockets + - mkdir -p log + - exec: + cmd: + - mkdir -p /var/run/sshd + - mkdir -p /root/.ssh + - echo $ssh_key >> /root/.ssh/authorized_keys + - exec: + cmd: + - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf" + - "rm /etc/nginx/sites-enabled/default" + + - replace: + filename: /etc/nginx/nginx.conf + from: pid /run/nginx.pid; + to: daemon off; + + - replace: + filename: "/etc/nginx/conf.d/discourse.conf" + from: /upstream[^\}]+\}/m + to: "upstream discourse { + server 127.0.0.1:3000; + }" + + - replace: + filename: "/etc/nginx/conf.d/discourse.conf" + from: /server_name.+$/ + to: server_name _ ; + + - replace: + filename: "/etc/redis/redis.conf" + from: "daemonize yes" + to: "" + - replace: + filename: "/etc/redis/redis.conf" + from: /^pidfile.*$/ + to: "" + + - exec: + cmd: + - mkdir -p /shared/redis_data + - chown -R redis /shared/redis_data + - chgrp -R redis /shared/redis_data + + - replace: + filename: "/etc/redis/redis.conf" + from: /^logfile.*$/ + to: "logfile stdout" + + - replace: + filename: "/etc/redis/redis.conf" + from: /^dir .*$/ + to: "dir /shared/redis_data" + + # we can not migrate without redis + - exec: + background: true + cmd: "sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf" + + - merge: $home/config/database.yml $database_yml + + - exec: + cmd: + - chown -R root /var/lib/postgresql/9.2/main + - "[ ! -e /shared/postgres_data ] && cp -r /var/lib/postgresql/9.2/main /shared/postgres_data || exit 0" + - chown -R postgres /shared/postgres_data + - chgrp -R postgres /shared/postgres_data + + - replace: + filename: "/etc/postgresql/9.2/main/postgresql.conf" + from: "data_directory = '/var/lib/postgresql/9.2/main'" + to: "data_directory = '/shared/postgres_data'" + + - exec: + background: true + cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main" + + # give db a few secs to start up + - exec: "sleep 5" + + - exec: sudo -u postgres createdb discourse || exit 0 + - exec: + stdin: | + create user discourse; + cmd: sudo -u postgres psql discourse + raise_on_fail: false + + - exec: + stdin: | + grant all privileges on database discourse to discourse; + cmd: sudo -u postgres psql discourse + raise_on_fail: false + + - 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;"' + + + - exec: + cd: $home + cmd: + - chown -R discourse $home + - sudo -E -u discourse bundle install --deployment + - sudo -E -u discourse bundle exec rake db:migrate + - sudo -E -u discourse bundle exec rake assets:precompile + -- 2.25.1