Dockerでのマルチサイト設定

:warning: マルチサイトはDiscourseアプリケーションでサポートされていますが、これは高度なシステム管理者向けの設定です。何をしているか分からない場合は、マルチサイトを設定しないでください。Discourseチームはマルチサイトの設定サポートを提供できません。

1つのDockerセットアップで複数のドメインをホストしたい場合は、マルチサイト設定が必要になります。以下にその基本的な構成要素を示します。

フックを理解する

マルチサイトはかなり高度なトピックです。マルチサイトの構築を試みる前に、それらについて学ぶ時間を取ってください。

Discourseテンプレートはpupsを使用しており、そのルールはシンプルかつ強力です。

実行する各ルールはフックを定義できます。

run:
  exec:
    cd: some/path
    hook: my_hook
    cmd:
      - echo 1

後でコンテナ内で、フックの前後ルールを挿入できます。

hooks:
  before_my_hook:
    - exec: echo "I ran before"
  after_my_hook:
     - exec: echo "I ran after"

したがって、上記の例では、次のような出力が表示されます。

I ran before
1
I ran after

/var/discourse/templates 内のテンプレートを読み込むと、利用可能なフックを確認できます。

スタンドアロンコンテナを変更して2番目のサイトテナントをプロビジョニングする

hooksセクション全体を以下に置き換えます。

hooks:
  after_postgres:
     - exec: sudo -u postgres createdb b_discourse || exit 0
     - exec:
          stdin: |
            grant all privileges on database b_discourse to discourse;
          cmd: sudo -u postgres psql b_discourse
          raise_on_fail: false

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

  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
  before_bundle_exec:
    - file:
        path: $home/config/multisite.yml
        contents: |
         secondsite:
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           db_id: 2
           host_names:
             - b.discourse.example.com

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

3つのフックが使用されています。

  1. after_postgres は、postgresがインストールされた後、適切な権限を持つ追加のDB b_discourse が作成されることを保証します。

  2. before_bundle_exec は、docker_manager が存在し、multisite.yml ファイル(データベースの場所を定義)が存在することを保証します。

  3. after_bundle_exec は、カスタムDBマイグレーションタスク rake multisite:migrate を実行します。これにより、すべてのDBが最新の状態になります。

設定に関する注意

上記のサンプルは、必要に応じてデータコンテナ/アプリコンテナに分割できます。after_postgres フックをデータコンテナで実行し、残りをWebコンテナで実行するだけです。

上記のサンプルを拡張して、さらに多くのDBをプロビジョニングすることもできます。これを行うには、DB作成などの呼び出しを複製してさらにDBをプロビジョニングし、multisite.yml に追加のサイトを追加するようにしてください。

multisite.ymlhost_names ノードをホストしたい実際のホスト名と一致するように必ず変更してください。

また、HTTPSを実行する予定がある場合は、組み込みのletsencrypt機能はマルチサイトシナリオでは機能しないため、サイトの前面にプロキシを配置して処理する必要があります。

「いいね!」 69
How does multisite.yml look?
Multiple Forums in a Single Installation
How to create 1000 subcategories in a scalable way?
Multiple Discourses, multiple containers, one server
Pros and cons of multiple standalone containers vs one for multiple Discourse installs?
Success - New Multisite Install on Dedicated server using ServerPilot, Nginx and Apache
Multisite Installation
Will I need to start over with multisite configuration from standalone version?
Starting a second Discourse forum on the same VPS
Multiple Discourse Installs - Single Server
Pros and cons of a multisite installation
Installation wizard not appearing in multisite installs
How do you set up multiple discourse forums on the same server?
Disabling/restricting user search
Multisite installation with seperated smtp emails
Sandbox and test discourse on host?
Second discourse instance on the same server
Micro Forums: how many could I create?
Discourse for 3 different Countrys
Need proper documentation for multisite discourse with docker
Discourse multisite installation help with digitalocean
Help me setup many websites on one VPS
Remove sites from multisite config with Docker
Totally Walled-Off Groups
Multitenat Dockerize Discourse
Not receiving activation email for admin on multisite installation
Need help with multisite configuration
Install Discourse on Plesk / Ubuntu 14 without Docker
How could I install another discourse on same server (docker)?
Multisite viability - 2 read-only and 1 active
Can I log into multiple instances of discourse simultaneously?
Is it possible to totally hide members
I want to host hundreds of instances of Discourse
Adding an instance to multisite without rebuilding the container
How to setup host mapping on a multi-site discourse instance
Publishing multisite
Multiple communities on discourse?
Multisite Config
Three sites in one setup
Recover to one site from multisite
Use CloudPanel to manage multiple sites with Discourse
Does discourse hosting use docker for all customer instances?
Tips for setting up a multi-subdomain Discourse instance with shared SSO?
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
Guidance on multi-site setup
Running multiple things on the same sever as my Pi (where Discourse is hosted)?
How extensible can I make my installation in terms of sub domains and restricting membership to them?
Discourse instance stops running in every midnight
One server for 2 Discourse communities?
One server for 2 Discourse communities?
Multiple discourse installation on single droplet
Feature proposal: Customizations based on primary group membership, a.k.a. tenancy 'lite'
Stable branch assets won't compile
[mutlisite installation] pnpm permission error during rebuild
Stable branch assets won't compile
Pull request for Wikis?
PAID Require Discourse expert for extreme customization
Add path to cookie
App.yml shared volumes for a two website setup
Contabo experience with Plesk, Webmin or other server-admin setup?
Move from standalone container to separate web and data containers
Using a launcher built docker image in docker-compose
Two standalone instances on one server?
Best approach for test and production instance of discourse
Are there other workarounds to not having category moderation such as multiple instances of the board?
WP SSO + Discourse Multisite
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column categories.search_priority does not exist
Multisite installation ... in subdirectories?
Multiple discourse instances in a single server
Integration with .NET MVC application for a SaaS platform
Multisite for small collection of sites for a family?
Hosting Plan Suggestion for 500 Concurrent Online Users
Avatar, Site Logos, and Cert Errors
Database access issues after upgrade v3.5.2 -> v3.6.0.beta2
Move from standalone container to separate web and data containers
Can I have two domains pointing towards the same IP address without redirect?
Move from standalone container to separate web and data containers
Multiple container setup problems
Installing on Kubernetes
How might we better structure #howto?
How to set redis DB ID in Docker container?
How can I host more than 1 Discourse forum on 1 VPS?
How can Admin login while Read-only mode is enabled on multisite?
Setup Multisite Configuration with Let's Encrypt and no Reverse Proxy
Docker image update: Redis 6 and 25% smaller image size
Setup Multisite Configuration with Let's Encrypt and no Reverse Proxy
Pups::ExecError
Web-only - do I need a separate image for each container?
All users are visible in @mentions autocomplete list
Migrate from VPS to a Dedicated
Discourse Multisite – Nginx (Inside Docker) Only Serving Default Site
Two Discourse communities on the same VPS
How can I use different setting value for subdomain?
Will This Configuration Successfully Create a Second Discourse Instance (with Proxy)?
Pups::ExecError