This repository provides a way to host Discourse on a server.
UPDATE: I found it too hard to maintain this setup especially accross discourse updates. I have since switched to the standard discourse hosting setup, locally on a machine in my basement. That is much more stable and I have had no issues upgrading things. I would highly reccomend someone trying to approach to have a second thought about it, unless you have a very high amount of time investment available. I spent months on getting this working. I think long term for this kind of setup to work, it would have to be upstreamed into discourse and offically supported so that it stays working.
When I set out to setup a forum for a local group I am a part of, I quickly settled on Discourse, since it was open source, had a nice UX, was actively updated, and had a large community. However, I couldn't find an existing hosting solution that met these goals:
The online supported hosting would easily be $100+ per month for a forum with some plugins, which was a no-go for our organization to start.
Alternatively, the supported way of hosting Discourse uses a custom installer script. There is a long standing issue about having a more standard way of deploying Discourse.
So I decided to:
Before you get started with your forum, you will need a few things:
:)
configs/daemon.json
for your docker daemon config. This changes logging to be more performant.configs/sshd_config
as a secure SSH configStart up services:
docker compose up -d db redis minio
docker compose run --rm --no-deps glitchtip-migrate
docker compose run --rm --no-deps migrate
docker compose run --rm --no-deps upload_assets
docker compose up -d --no-deps glitchtip-web glitchtip-worker web mail-reciever ddclient email-relay
docker compose up -d --no-deps nginx
Open glitchtip, sign up for an account, copy DSN to .env
.
Rebuild web with DSN and re-copy assets:
docker compose run --rm --no-deps --build upload_assets
docker compose up -d --no-deps web
docker compose run --rm --no-deps web ./script/discourse enable_restore
# Must preserve file name
docker cp /path/to/<name>.sql.gz discourse-hosting-web-1:/var/www/discourse/public/backups/default/
docker exec -it discourse-hosting-web-1 env DISCOURSE_BACKUP_LOCATION=local ./script/discourse restore ./<name>.sql.gz
docker compose run --rm --no-deps web ./script/discourse disable_restore
docker compose run --rm --no-deps web bundle exec rake posts:rebake
local Computer
Remote computer
Sendgrid
Software setup
locally: set env variables tilt up
use docker context
First populate the .env file with the following:
SEND_GRID_API_KEY=...
HOSTNAME=forum.mydomain.com
EMAIL=my-email@gmail.com
# Run openssl rand -hex 32 to generate a new secret key
SECRET_KEY=...
# Generated by the glitchtip server after creating an account
DSN=http://...@glitchtip.${HOSTNAME}/1
Then make modify your /etc/hosts
file to alias your domain to localhost:
127.0.0.1 forum.mydomain.com
127.0.0.1 assets.forum.mydomain.com
127.0.0.1 glitchtip.forum.mydomain.com
Then run the following commands:
docker compose run --rm glitchtip-migrate
docker compose run --rm migrate
docker compose run --rm upload_assets
docker compose run --rm install_themes
docker compose up web glitchtip-worker
Now open your browser to http://forum.mydomain.com and you should see the Discourse setup page.
You can also visit /logs
to see the logs and /sidekiq
to see the sidekiq dashboard.
You can also visit http://localhost:8001 to see the redis GUI, use the password password
.
The Minio GUI is available at http://localhost:9001. The default username and pw is minioadmin
.
To import emails:
mkdir -p data/import/emails
cp some-mailbox.mbox data/import/emails
# Copy the default settings to the `data/import/` setting.
docker-compose run -v $PWD/data/import:/shared/import/data --rm web bundle exec ruby script/import_scripts/mbox.rb /shared/import/data/settings.yml
To remove all the data, run:
docker compose down -v
rm -rf data/*/**
If you want to see the network traffic from one of the containers, for debugging purposes, you can use tcpdump and wireshark:
dc run --rm --name tmp web bash -i
docker run --net=container:tmp maintained/tcpdump -i any -w - | wireshark -k -i -
# create network traffic in initial container
# bundle exec rake s3:upload_assets
If we want to check how something works on the ruby side, we can do that with rails console. Here is an example of how to do that
to see how the preload_script
helper works:
docker compose run --rm web bundle exec rails c
require 'mock_redis'
require 'rspec-html-matchers'
require "ostruct"
require_relative './spec/rails_helper'
helper.request = OpenStruct.new(:env => {'HTTP_ACCEPT_ENCODING' => 'gzip, deflate'})
helper.preload_script("vendor")
ActionController::Base.helpers.asset_path("vendor.js")
We also include the debug
gem, which you can invoke to start a bundle command with debugging:
docker compose run --rm upload_assets rdbg -c -- bundle exec rake s3:upload_assets