Skip to content

Instantly share code, notes, and snippets.

@wout

wout/README.md

Forked from julienma/README.md
Created Sep 26, 2020
Embed
What would you like to do?
How to install Discourse 2.4+ on Dokku (2019)

Questions:


How to install Discourse 2.4+ on Dokku (2019)

Discourse is very clear that they do not support anything else than their official install instructions, which more or less requires a dedicated server.

However, being a docker image, it should be possible to install it on dokku.

These instructions are based on https://medium.com/batary/deploying-discourse-with-dokku-5eec28e2ad8b, and updated to work with current Discourse + Dokku.

Bootstrapping Discourse

Discourse has a repository dedicated to bootstrapping a docker image. We'll follow some of their instructions, but will adapt them to our needs.

On the server, clone the Official Discourse Docker Image:

git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse

Instead of using the setup tool, we'll do the configuration manually. Copy the default standalone configuration and edit it:

cp samples/standalone.yml containers/app.yml
nano containers/app.yml

You'll need to at least set the following (SMTP is mandatory for Discourse to work):

  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: 'discourse.example.com'

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'me@example.com,you@example.com'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: smtp.example.com
  #DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: user@example.com
  DISCOURSE_SMTP_PASSWORD: pa$$word
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)

Do not set the Let's Encrypt email, as we'll manage SSL through dokku.

Save the config file and bootstrap the image:

./launcher bootstrap app

If successful, you should see an image named local_discourse/app when you run the following command:

docker images

Configuring Dokku

Now you can setup and configure the app with Dokku.

dokku apps:create discourse
dokku domains:set discourse discourse.example.com

dokku proxy:ports-add discourse http:80:80
dokku proxy:ports-remove discourse http:80:5000

Docker run

The Discourse launcher actually runs a custom docker run command, with a whole lot of arguments. We'll replicate it using dokku features.

Get the command used to start the Discourse instance:

./launcher start-cmd app

Replace the values with your output of the prior command, splitting by type of arguments:

  • Discard the -p port:port arguments

  • Join all the -e ENV vars and set them like this:

    dokku config:set --no-restart discourse LANG=en_US.UTF-8 RAILS_ENV=production UNICORN_WORKERS=3 UNICORN_SIDEKIQS=1 RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 RUBY_GC_HEAP_INIT_SLOTS=400000 RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 DISCOURSE_DB_SOCKET=/var/run/postgresql DISCOURSE_DB_HOST= DISCOURSE_DB_PORT= DISCOURSE_HOSTNAME=discourse.example.com DISCOURSE_DEVELOPER_EMAILS=me@example.com DISCOURSE_SMTP_ADDRESS=smtp.example.com DISCOURSE_SMTP_USER_NAME=user@example.com DISCOURSE_SMTP_PASSWORD=pa$$word DOCKER_HOST_IP=172.17.0.1
  • Set both -v volumes:

    dokku storage:mount discourse /var/discourse/shared/standalone:/shared
    dokku storage:mount discourse /var/discourse/shared/standalone/log/var-log:/var/log
  • Set the following Docker options (--entrypoint is especially important):

    dokku docker-options:add discourse run,deploy "--entrypoint /sbin/boot"
    dokku docker-options:add discourse run,deploy "--hostname dokku-discourse"
    dokku docker-options:add discourse run,deploy "--shm-size=512m"
    dokku docker-options:add discourse run,deploy "--mac-address aa:bb:cc:dd:ee:ff"
  • Set the restart policy --restart (this is probably optional):

    dokku ps:set-restart-policy discourse always
  • You should ignore other options like -t

Deploy to dokku

To make it easier, we'll deploy using docker tags:

docker tag local_discourse/app:latest dokku/discourse:latest
dokku tags:deploy discourse latest

The app should deploy and then start.

Set up SSL

dokku config:set --no-restart discourse DOKKU_LETSENCRYPT_EMAIL=me@example.com
dokku letsencrypt discourse

Finish setup

First thing: skip wizard and enable force_https from admin dashboard (make sure to have setup letsencrypt and that https works fine). Then restart the wizard if you want.

Then follow the next steps to register an admin account.

You can also add plugins and more.

How to update Discourse

Based on default update instructions, with a twist because of dokku:

dokku ps:stop discourse
cd /var/discourse/
./launcher bootstrap app
# wait for it...
docker tag local_discourse/app:latest dokku/discourse:latest
dokku tags:deploy discourse latest

Backup

Make sure to backup contents in /shared, cf.

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared

Troubleshooting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.