So you want to install a plugin on your Discourse instance? Great, let’s get started!
The below advice to self install plugins only applies to self-hosted Discourse instances. If you are using a managed hosting service, the available plugins will be controlled by your hosting provider. For example, on our hosting these specific plugins are available by hosting tier.
In this tutorial, we’ll install Discourse Spoiler Alert plugin.
-
Copy the plugin’s GitHub or Bitbucket
git clone
url. -
Access your container’s
app.yml
file (present in/var/discourse/containers/
)cd /var/discourse nano containers/app.yml
-
Add the plugin’s repository URL to your container’s
app.yml
file:hooks: after_code: - exec: cd: $home/plugins cmd: - sudo -E -u discourse git clone https://github.com/discourse/docker_manager.git
(Add the plugin’s
git clone
url just belowsudo -E -u discourse git clone https://github.com/discourse/docker_manager.git
) -
Rebuild the container:
cd /var/discourse ./launcher rebuild app
That’s it, you’ve successfully installed the Discourse Spoiler Alert plugin on your Discourse instance!
Installing plugins hosted in a private repo
Use an OAuth token to install your plugin
This way you can install your plugin in the same space as any other and you don’t need to create an ssh key.
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- sudo -E -u discourse git clone https://<token>@github.com/owner/repo.git
An alternative method to install private plugins can be to use SSH keys. However, for most instances, OAuth tokens is the preferred method.
SSH Key Private Install Steps
-
Assuming that your private git repo is hosted on GitHub, you need to add your server’s user public SSH key to GitHub repo Deploy keys (https://github.com/SecretOrg/secret-plugin/settings/keys).
-
Modify
app.yml
file as shown in below example:
run:
- exec: echo "Beginning of custom commands"
- exec: cd /var/www/discourse && sudo -u discourse bundle install --deployment --without test --without development
- exec: echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /user/.ssh/config
- file:
path: /user/.ssh/id_rsa
chmod: 600
contents: |
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEArCQG213utzqE5YVjTVF5exGRCkE9OuM7LCp/FOuPdoHrFUXk
y2MQcwf29J3A4i8zxpES9RdSEU6iIEsow98wIi0x1/Lnfx6jG5Y0/iQsG1NRlNCC
aydGvGaC+PwwWiwYRc7PtBgV4KOAVXMZdMB5nFRaekQ1ksdH/360KCGgljPtzTNl
09e97QBwHFIZ3ea5Eih/HireTrRSnvF+ywmwuxX4ubDr0ZeSceuF2S5WLXH2+TV0
.... etc ....
-----END RSA PRIVATE KEY-----
- file:
path: /user/.ssh/id_rsa.pub
chmod: 600
contents: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tj .... etc .... user@discourse
- exec: cd $home/plugins && git clone git@github.com:SecretOrg/secret-plugin.git
- exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
- exec: cd $home && rm -fr tmp/cache
- exec: cd $home && sudo -E -u discourse bundle exec rake assets:precompile
- exec: rm /user/.ssh/id_rsa
- exec: rm /user/.ssh/id_rsa.pub
- exec: echo "End of custom commands"
- Rebuild the container:
cd /var/discourse
./launcher rebuild app
Your private plugin should be installed on your Discourse instance.