How to Deploy Discourse with Juju

Discourse is an open-source, next-generation discussion platform built for the next decade of the Internet. Juju is a service orchestration management tool developed by Canonical. This guide requires a configured and successfully bootstrapped Juju environment. Please walk through getting started with Juju guide if you are not familiar with the tool yet.
Configure Discourse
Firstly, you have to fork Discourse and prepare it for deployment with Juju. For this purpose, add config/redis.yml
like shown below.
1 | <span class="s"><%= ENV['RAILS_ENV'] %></span><span class="pi">:</span><br data-jekyll-commonmark-ghpages=""> <span class="na">uri</span><span class="pi">:</span> <span class="s"><%= uri = URI.parse(ENV['REDIS_URL']) %></span><br data-jekyll-commonmark-ghpages=""> <span class="na">host</span><span class="pi">:</span> <span class="s"><%= uri.host %></span><br data-jekyll-commonmark-ghpages=""> <span class="na">port</span><span class="pi">:</span> <span class="s"><%= uri.port %></span><br data-jekyll-commonmark-ghpages=""> <span class="na">password</span><span class="pi">:</span> <span class="s"><%= uri.password %></span> |
Copy config/environments/production.rb.sample
to config/environments/production.rb
.
1 | cp config/environments/production.rb.sample config/environments/production.rb |
Add new files to Git.
1 | git add <span class="nt">--force</span> config/environments/production.rb config/redis.yml |
Update your repository.
1 | git add <span class="nb">.</span><br data-jekyll-commonmark-ghpages="">git commit <span class="nt">-m</span> <span class="s1">'prepare to deploy with juju'</span><br data-jekyll-commonmark-ghpages="">git push origin master |
Now, Discourse is ready for the deployment with JuJu.
Configure Juju
Create Rack charm config using discourse.yml
as shown below.
1 | <span class="na">discourse</span><span class="pi">:</span><br data-jekyll-commonmark-ghpages=""> <span class="na">repo</span><span class="pi">:</span> <span class="s"><repo_url></span><br data-jekyll-commonmark-ghpages=""> <span class="na">env</span><span class="pi">:</span> <span class="s">SECRET_TOKEN=ssEnesNG3f3jAhgJgSlWDLUi0U3cUrUhrTBwwancUKL91hX7ClKAgKl0Ofpv</span> |
Important: Discourse requires SECRET_TOKEN
to be defined for sessions storage.

More configuration and deployment options are available on the Rack charm page.
Deployment
Deploy Discourse with Rack charm.
1 | juju deploy rack <span class="nt">--config</span> discourse.yml discourse |
Deploy and relate Redis.
1 | juju deploy redis-master<br data-jekyll-commonmark-ghpages="">juju add-relation redis-master:redis-master discourse |
Deploy and relate PostgreSQL.
1 | juju deploy postgresql<br data-jekyll-commonmark-ghpages="">juju add-relation postgresql:db-admin discourse |
Generally, you should use the db
relation for PostgreSQL, but Discourse creates the hstore
extension in migrations, that’s why you have to use db-admin
instead.
Finally, expose Discourse.
1 | juju expose discourse |
Use juju status
or juju debug-log
to watch for deployment progress.
When Discourse is deployed, create, migrate, and seed the database.
1 | juju ssh discourse/0 run rake db:create<br data-jekyll-commonmark-ghpages="">juju ssh discourse/0 run rake db:migrate<br data-jekyll-commonmark-ghpages="">juju ssh discourse/0 run rake db:seed_fu |
Compile assets.
1 | juju ssh discourse/0 run rake assets:precompile |
Restart Discourse.
1 | juju ssh discourse/0 <span class="nb">sudo </span>restart rack |
Navigate to Discourse and create your account. When you are done, promote your account to admin in the Rails console.
1 | juju ssh discourse/0 run rails c |
1 | <span class="n">me</span> <span class="o">=</span> <span class="no">User</span><span class="p">.</span><span class="nf">find_by_username_or_email</span><span class="p">(</span><span class="s1">'myemailaddress@me.com'</span><span class="p">)</span><br data-jekyll-commonmark-ghpages=""><span class="n">me</span><span class="p">.</span><span class="nf">activate</span><br data-jekyll-commonmark-ghpages=""><span class="n">me</span><span class="p">.</span><span class="nf">admin</span> <span class="o">=</span> <span class="kp">true</span><br data-jekyll-commonmark-ghpages=""><span class="n">me</span><span class="p">.</span><span class="nf">save</span> |
Now, you can configure Discourse from the /admin
console. To learn more details about getting started with Discourse, check out this guide.
Further reading
- Easy Deployment of Rack Applications with Juju
- How to Implement Integration Tests for Juju Charms
- Juju Charms for Cloud Foundry: How to Deploy, Customize, and Upgrade
About the author
Pavel Pachkovskij has experience in front- and back-end development of web applications. He is proficient in Ruby, Ruby on Rails, JavaScript, CSS, etc. Pavel also worked with relational databases, such as MySQL, MariaDB, PostgreSQL, as well as NoSQL solutions, such as MongoDB and Redis. Find him on GitHub.