本指南假定您已具备自主托管的标准化安装环境。此处仅支持标准安装方式,故相关操作说明均基于标准安装前提。
本指南仅适用于自主托管的Discourse实例。若您使用托管服务,可用插件将由服务提供商控制。例如,在本平台托管服务中,这些特定插件按托管层级提供。
本教程将指导您安装Discourse Solved插件。
需预先掌握GitHub仓库的基本操作,特别是获取git克隆链接的方法,以及通过终端使用nano编辑YAML(*.yml)文件的技巧,重点掌握nano保存与退出的操作。YAML文件严格遵循缩进格式,请在复制粘贴及编辑实例所需*.yml文件时保持格式规范。
- 复制插件的GitHub
git clone链接 - 访问容器的
app.yml文件(位于/var/discourse/containers/目录)
cd /var/discourse
nano containers/app.yml
- 将插件仓库链接添加至容器
app.yml文件:
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- sudo -E -u discourse git clone https://github.com/discourse/docker_manager.git
- sudo -E -u discourse git clone https://github.com/discourse/discourse-solved.git
(将插件的git clone链接添加于含git clone https://github.com/discourse/docker_manager.git的行下方)遵循docker_manager.git行的既有格式;若该行未包含sudo -E -u discourse,则直接插入- git clone https://github.com/discourse/discourse-solved.git。
- 重建容器:
cd /var/discourse
./launcher rebuild app
至此,您已成功在Discourse实例上安装Discourse Solved插件!
私有仓库插件安装指南
需使用OAuth令牌:
凭借OAuth令牌,您可以按照公有仓库相同方式安装插件,且无需创建SSH密钥。
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- sudo -E -u discourse git clone https://<token>@github.com/owner/repo.git
强烈建议为私有仓库插件使用OAuth令牌。若不可行,请参阅以下方案。
SSH密钥私有安装步骤
- 若私有Git仓库托管于GitHub,需将服务器用户的公开SSH密钥添加至GitHub仓库的部署密钥(https://github.com/SecretOrg/secret-plugin/settings/keys)
- 按以下示例修改
app.yml文件:
run:
- exec: echo "自定义命令开始"
- 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
.... 此处省略 ....
-----END RSA PRIVATE KEY-----
- file:
path: /user/.ssh/id_rsa.pub
chmod: 600
contents: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tj .... 此处省略 .... 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 "自定义命令结束"
- 重建容器:
cd /var/discourse
./launcher rebuild app
私有插件应已成功安装至您的Discourse实例。
插件卸载方法
移除插件仅需从app.yml文件中删除- git clone https://github.com/...行,并通过以下命令重建站点:
cd /var/discourse
./launcher rebuild app
原贴地址:Install plugins on a self-hosted site - Self-Hosting - Discourse Meta
翻译模型:deepseek-ai/deepseek-v3.1