Configuração Multisite com Docker

:warning: Embora a funcionalidade multisite seja suportada na aplicação Discourse, esta é uma configuração avançada de sysadmin. Se você não sabe o que está fazendo, não configure o multisite. A equipe do Discourse não pode fornecer suporte para configuração de multisite.

Se você deseja hospedar múltiplos domínios em uma única instalação Docker, você precisará de uma configuração multisite. Aqui estão os blocos de construção básicos para uma.

Entenda os hooks

Multisite é um tópico bastante avançado. Antes de tentar uma instalação multisite, dedique algum tempo para aprender sobre eles.

Os templates do Discourse usam pups; suas regras são simples e poderosas.

Cada regra que você executa pode definir um hook (gancho):

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

Mais tarde, em seu contêiner, você pode inserir regras antes ou depois de um hook:

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

Portanto, no exemplo acima, você verá uma saída como a seguinte:

I ran before
1
I ran after

Você pode ler os templates em /var/discourse/templates para ver quais hooks você tem disponíveis.

Modifique seu contêiner standalone para provisionar o segundo site tenant

Substitua a inteira seção de hooks por:

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
           host_names:
             - b.discourse.example.com

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

Existem 4 hooks em ação:

  1. after_postgres garante que, após o postgres ser instalado, um banco de dados adicional chamado b_discourse seja criado com as permissões apropriadas e extensões necessárias.

  2. after_code garante que o docker_manager seja clonado no diretório de plugins.

  3. before_bundle_exec garante que o arquivo multisite.yml esteja no lugar (o que define onde encontrar os bancos de dados).

  4. after_bundle_exec executa a tarefa de migração de banco de dados personalizada rake multisite:migrate — isso garante que todos os bancos de dados estejam atualizados.

Nota sobre configuração

O exemplo acima pode ser dividido em contêiner de dados / contêiner de aplicação, se necessário. Basta executar o hook after_postgres no contêiner de dados e o restante no contêiner web.

O exemplo acima pode ser estendido para provisionar ainda mais bancos de dados. Para fazer isso, provisione mais bancos de dados duplicando as chamadas de criação de banco de dados, etc., e certifique-se de adicionar sites adicionais em multisite.yml.

Certifique-se de alterar o nó host_names em multisite.yml para corresponder ao nome de host real que você deseja hospedar.

Além disso, se você planeja executar HTTPS, precisará de um proxy na frente do site para lidar com isso, pois a funcionalidade letsencrypt embutida não funcionará em um cenário multisite.

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