# 两个 Discourse 站点的一份 plugins.yml 文件

**URL:** <https://meta.discourse.org/t/one-plugins-yml-file-for-two-discourse-sites/160005>\
**Category:** Support\
**Created:** [2020年八月6日 09:52 UTC](https://meta.discourse.org/t/one-plugins-yml-file-for-two-discourse-sites/160005 "2020-08-06T09:52:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)\
**Post date:** [2020年八月6日 09:52 UTC](https://meta.discourse.org/t/one-plugins-yml-file-for-two-discourse-sites/160005/1 "2020-08-06T09:52:59Z")

</div>

大家好，

是否可以通过命令将远程位置的文件包含到 app.yml 中？

我有两个站点，希望它们使用相同的插件列表。与其每次都复制粘贴（有时还会忘记），我能否将插件列表放在\<位置 A\>，并在每次重建应用时自动拉取？

例如：  
`<include executable="wget --no-check-certificate -q -O - http://LocationA/plugins.yml" noexec="no">`

---

<div class="post-metadata">

**Author:** ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)\
**Post date:** [2020年八月6日 11:28 UTC](https://meta.discourse.org/t/one-plugins-yml-file-for-two-discourse-sites/160005/2 "2020-08-06T11:28:39Z")

</div>

嗨 @IAmGav

这可能不完全符合你的需求；我也还没有完全完善这个方案，但大致思路如下：

1. 创建一个目录 `/var/discourse/mytemplates`。
2. 在该目录中添加一个名为 `plugins.templates.yml` 的新模板文件，例如：

```plaintext
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-bbcode.git
          - git clone https://github.com/discourse/discourse-sitemap.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-whos-online.git
          - git clone https://github.com/discourse/discourse-checklist.git

```

1. 为该目录创建一个新的 Git 仓库，并将其推送到 GitHub。
2. 在你的 `yml` 文件中为这些插件添加模板条目，例如：

```plaintext
templates:
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/web.socketed.template.yml"
  - "mytemplates/plugins.template.yml"

```

我已经测试到这一步，可以按这种方式通过模板文件添加插件并构建容器，完全没有问题。

我尚未测试的部分是在 launcher 中添加一两行代码来拉取该仓库；说实话，我还没着手处理这部分。

```plaintext
git clone https://github.com/my_super_repo/mytemplates.git

```

虽然我还没处理这部分，但我相信这是可行的；因为我已经测试过从模板中在容器构建过程中拉取插件的功能，并且运行良好。因此，这个方案唯一剩下的步骤就是在 launcher 中添加代码，并测试从 GitHub 拉取 `mytemplates` 仓库。

不过，坦率地说，这种方法似乎做了很多不必要的工作：

- 编辑 `launcher` 以从仓库拉取模板
- 在 `yml` 文件中添加新的模板条目（用于插件）

直接把内容复制粘贴到 `yml` 文件中然后“搞定”要容易得多；但我也觉得这个想法很有趣。系统管理员的谜题对我来说总是很有趣，所以能为你思考这个问题我也很开心。

总之，对你问题 @IAmGav 的简短回答是：“是的，这是可行的”。当然，如果你想尝试，那就“放手去做吧”。

希望这能帮到你。
