Sample 3 instance multisite


#1

Here is a tested multisite YAML file which might ease the confusion some have in regards to setup:

# this is the base templates used, you can cut it down to include less functionality per container
templates:
  - "templates/cron.template.yml"
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/sshd.template.yml"
  - "templates/web.template.yml"

# which ports to expose?
expose:
  - "80:80" 
  - "2222:22" 
params:
  # git revision to run
  version: tests-passed

env:
  UNICORN_WORKERS: 8
  db_shared_buffers: "1G"
  db_work_mem: "40MB"
  DISCOURSE_DEVELOPER_EMAILS: 'developer@gmail.com'
  DISCOURSE_HOSTNAME: 'first.site.com'
  DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: developer@mandrillapp.com
  DISCOURSE_SMTP_PASSWORD: yaRGJVKjLJ8YqwJVKj

# These containers are stateless, all the data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared

# you may use the docker manager to upgrade and monitor your docker image
# UI will be visible at http://yoursite.com/admin/docker
hooks:
  after_postgres:
     - exec: sudo -u postgres createdb discourse_dbase2 || exit 0
     - exec:
          stdin: |
            grant all privileges on database discourse_dbase2 to discourse;

          cmd: sudo -u postgres psql discourse_dbase2
          raise_on_fail: false

     - exec: sudo -u postgres createdb discourse_dbase3 || exit 0
     - exec:
          stdin: |
            grant all privileges on database discourse_dbase3 to discourse;

          cmd: sudo -u postgres psql discourse_dbase3
          raise_on_fail: false

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase2 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase2 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase2 <<< "create extension if not exists pg_trgm;"'

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase3 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase3 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase3 <<< "create extension if not exists pg_trgm;"'

  after_code:
    - exec:
        cd: /var/www/discourse/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-bbcode-color.git
          - git clone https://github.com/discourse/discourse-spoiler-alert.git
          - git clone https://github.com/discourse/discourse-tagging.git
          - git clone https://github.com/discourse/discourse-akismet.git
          - git clone https://github.com/discourse/discourse-solved.git

  before_bundle_exec:
    - file:
        path: /var/www/discourse/config/multisite.yml
        contents: |

         discourse_instance2:
           adapter: postgresql
           database: discourse_dbase2
           pool: 25
           timeout: 5000
           db_id: 2
           host_names:
             - box.site.com

         discourse_instance3:
           adapter: postgresql
           database: discourse_dbase3
           pool: 25
           timeout: 5000
           db_id: 3
           host_names:
             - rebox.site.com

  after_bundle_exec:
    - exec: cd /var/www/discourse && sudo -E -u discourse bundle exec rake multisite:migrate

# Remember, this is YAML syntax - you can only have one block with a name
run:
   - exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'
#  - exec: rails r "SiteSetting.notification_email='developer@gmail.com'"

The part to take note of is after the

hooks:

There are chunks for each additional instance, in this case two extras. You can adapt this as need be.

Each chunk to add would be

     - exec: sudo -u postgres createdb discourse_dbase4 || exit 0
     - exec:
          stdin: |
            grant all privileges on database discourse_dbase4 to discourse;

          cmd: sudo -u postgres psql discourse_dbase4
          raise_on_fail: false
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase4 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase4 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase4 <<< "create extension if not exists pg_trgm;"'
         discourse_instance4:
           adapter: postgresql
           database: discourse_dbase4
           pool: 25
           timeout: 5000
           db_id: 4
           host_names:
             - unbox.site.com

Adding those 3 chunks below their similar in the YAML would provision a 4th site.

:smile: :+1:


Help with multisite configuration
Connectivity/Configuration issue with separate data container
Multisite configuration with Docker
(Daniel Lynch) #2

Thank you @webeindustry! One question: In the official multi-site howto it recommends a separate container for data. Are you aware of the pros/cons of doing that? Myself I’ve run into problems with the separate data container – is this the better way of doing things?

Thank you!


#3

It’s definitely the superior way. Most of the rebuilding process involves the data portion. I don’t know there to be any downsides to it.


(Kloknibor) #4

@webeindustry I’m trying to set up a multisite like you suggested and I understand docker and the Readme.md from pups but there isn’t anything noted about File and contents like you use here :

before_bundle_exec:
- file:
path: /var/www/discourse/config/multisite.yml
contents: |

     discourse_instance2:
       adapter: postgresql
       database: discourse_dbase2
       pool: 25
       timeout: 5000
       db_id: 2
       host_names:
         - box.site.com

     discourse_instance3:
       adapter: postgresql
       database: discourse_dbase3
       pool: 25
       timeout: 5000
       db_id: 3
       host_names:
         - rebox.site.com

and I’m running an discourse docker installation on a debian server but it doesn’t seem to have an multisite.yml which is being used here. What should the contents of this file be? I found the multisite.yml in the normal discourse github but there was data formatted like this in there :

discourse_instance3:
           adapter: postgresql
           database: discourse_dbase3
           pool: 25
           timeout: 5000
           db_id: 3
           host_names:
             - rebox.site.com

Do you need to add your first website in that file too? Why does it seems you send the data to a file that already has the data? Probably I’m asking a very noobish question, sorry abut that but I would like to learn from this :)!

EDIT : it seems webeindustry is suspended so I hope someone else read this and otherwise I will ask under the tutorail section ;)!