IT/Community/WG/Discourse/Setup: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(add infra setup)
(Update redirect)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Infrastructure set-up ==
#REDIRECT [[ParticipationSystems/Discourse/Setup]]
=== Create Cloudformation Stack ===
* Go to the AWS Console and click the Cloudformation service
* Create a new stack using the full name of the discourse instance (csa-discourse-<app>-<env>) and [https://github.com/Mozilla-cIT/cloudformation/blob/master/discourse.template this] template. Click Next.
* Enter the name and env of this discourse instance. The name should be below 4 characters, otherwise it may fail (Elasticache has a 20 character limit). Click Next.
* Do not add any tags, these are done automatically. Click create stack.
* Wait a bit. The Elasticache server takes a while to set up.
* If Cloudformation shows the status as CREATE_COMPLETE, most of the infrastructure has been set up.
* Go to the Outputs tab to see the Load balancer's DNS name and the Postgres DB instance you should be using.
 
=== Add DNS record for the Elasticache node ===
* Go the Elasticache service in the AWS Console.
* Find the Elasticache node that Cloudformation spun up and click on '1 Node'. Copy the endpoint for this node.
* Go to the Route 53 and go to the correct hosting zone. For production instances, use mofoprod.net and for staging instances, use mofostaging.net. Create a new CNAME record pointing to the Elasticache endpoint, and the TTL as 60.
* The domain that users will access Discourse from should be an A alias record pointing to the Load Balancer that Cloudformation created.
 
=== Create Database ===
  psql -h pgshared-db.mofostaging.net --user=root template1
  CREATE USER csa<app> WITH PASSWORD 'aStrongPasswordHere';
  CREATE DATABASE csa<app>db;
  GRANT ALL PRIVILEGES ON DATABASE csa<app>db to csa<app>;
  CREATE EXTENSION IF NOT EXISTS hstore;
  CREATE EXTENSION IF NOT EXISTS pg_trgm;
 
== Discourse set-up ==
=== Install Discourse ===
  # Update Ubuntu
  sudo apt-get update && sudo apt-get dist-upgrade   
 
  # Install Docker and git
  wget -qO- https://get.docker.io/ | sh
 
  # Create the directory for Discourse and clone the repo into it
  mkdir /var/discourse
  git clone https://github.com/discourse/discourse_docker.git /var/discourse
  cd /var/discourse
 
  # Copy the web example config
  cp samples/web_only.yml containers/app.yml
 
=== Edit app.yml ===
Open containers/app.yml in your favourite text editor and add/edit the following lines. Note that this is not the full file and YML is sensitive to indentation.
 
  params:
    version: tests-passed
  env:
    DISCOURSE_DEVELOPER_EMAILS: '' # For new instances, add an email address that you will use to sign up to discourse
    DISCOURSE_DB_PASSWORD: PASSWORD # Change this to the password for the database
    DISCOURSE_DB_POOL: 15
    DISCOURSE_DB_HOST: 'pgshared-db.mofoprod.net' # You will most likely be using this server
    DISCOURSE_DB_USERNAME: 'USERNAME' # Change this to the username that can access your database
    DISCOURSE_DB_NAME: 'DBNAME' # Change this to the name of the database for this instance
    DISCOURSE_HOSTNAME: 'HOSTNAME' # Change this to the domain that Discourse will run under
    DISCOURSE_REDIS_HOST: REDIS_HOST # Change this to the URL of the redis server
    # don't forget to set mail
    DISCOURSE_SMTP_ADDRESS: ADDRESS # Change this to the SES
    DISCOURSE_SMTP_PORT: 587
    DISCOURSE_SMTP_USER_NAME: USERNAME # Change this to the Amazon SES username
    DISCOURSE_SMTP_PASSWORD: PASSWORD # Change this to the Amazon SES password
    # New Relic
    NEW_RELIC_LICENSE_KEY: 123456789abcdef # Add a NR key
    NEW_RELIC_APP_NAME: communityit-NAME # Change NAME to something that can identify this Discourse instance
    # disable the annoying mini profiler
    DISCOURSE_ENABLE_MINI_PROFILER: false
 
In the same file, find the line
            - git clone https://github.com/discourse/docker_manager.git
 
Add the following two lines right after the line
 
            - git clone https://github.com/vikhyat/discourse-persona.git
            - git clone https://github.com/davidcelis/new_relic-discourse.git
 
=== Edit web.template.yml ===
Open templates/web.template.yml in your favourite text editor and add/edit the following lines. Note that this is not the full file and YML is sensitive to indentation.
 
Find the exec block with the command <pre>echo "done configuring web"</pre>
Before this block, add the following block. Remember to change HOSTNAME to the hostname of the Discourse instance.
 
    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: "server {"
        to: |+
          server {
          #Messy hack to force SSL on only the hostname, not IPs so ELB and Icinga work.
          set $use_https NO;
          if ($host ~* 'HOSTNAME') {
              set $use_https A;
          }
          if ($http_x_forwarded_proto != 'https') {
              set $use_https "${use_https}B";
          }
          if ($use_https = AB) {
              rewrite ^ https://$host$request_uri? permanent;
          }
 
After the edit it should look similar to this:
 
    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: "server {"
        to: |+
          server {
          #Messy hack to force SSL on only the hostname, not IPs so ELB and Icinga work.
          set $use_https NO;
          if ($host ~* 'discourse.mozilla-community.org') {
              set $use_https A;
          }
          if ($http_x_forwarded_proto != 'https') {
              set $use_https "${use_https}B";
          }
          if ($use_https = AB) {
              rewrite ^ https://$host$request_uri? permanent;
          }
 
 
    - exec:
        cmd: echo "done configuring web"
        hook: web_config
 
=== Bootstrap Discourse ===
To bootstrap Discourse, enter the /var/discourse directory, and then run
 
  ./launcher bootstrap app
 
This will take a few minutes. If all goes well, you can start Discourse.
 
  ./launcher start app

Latest revision as of 15:27, 10 January 2017