本指南假设您已进行自托管标准安装。我们_仅_在此处支持标准的安装方法,因此这些说明假定您具有标准安装。
本指南仅适用于自托管的 Discourse 实例。如果您使用的是托管服务,可用插件由您的托管服务提供商控制。例如,在我们的托管服务上,这些特定插件根据托管级别提供。
在本教程中,我们将安装 Discourse Solved 插件。
本教程要求了解如何使用 GitHub 仓库,特别是如何获取或复制 git clone URL 以及如何使用 nano 通过终端编辑 YAML (*.yml) 文件,特别是如何在 nano 中保存和退出。YAML 文件非常依赖缩进,因此在复制、粘贴和编辑 Discourse 实例所需的 *.yml 文件时,请务必注意这一点。始终在 .yml 文件中使用空格进行缩进,不要使用制表符。
-
复制插件的 GitHub
git cloneurl。 -
访问容器的
app.yml文件(位于/var/discourse/containers/):cd /var/discourse nano containers/app.yml -
将插件的仓库 URL 添加到容器的
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 cloneurl 添加到包含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 "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
.... 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"
- 重新构建容器:
cd /var/discourse
./launcher rebuild app
您的私有插件应该已安装在您的 Discourse 实例上。
如何卸载插件
要删除插件,只需从 app.yml 文件中删除 - git clone https://github.com/... 行,然后通过以下命令重建您的站点:
cd /var/discourse
./launcher rebuild app