セルフホストされたサイトにプラグインをインストールする

:warning: This guide assumes that you have a self-hosted standard installation. We only support the standard method of install here, so these instructions assume you have a standard install.

:warning: This guide only applies to self-hosted Discourse instances. If you are using a managed hosting service, the available plugins are controlled by your hosting provider. For example, on our hosting these specific plugins are available by hosting tier.

In this tutorial, we’ll install the Discourse Solved plugin.

This tutorial requires an understanding of how to use GitHub repos, specifically, how to get or copy the git clone URL and how to edit YAML (*.yml) files via the terminal using nano, specifically how to save and exit on nano. YAML files strongly follow indentations, so be sure to respect these as you copy and paste and edit the necessary *.yml for your Discourse instance.

  • Copy the plugin’s GitHub 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
              - sudo -E -u discourse git clone https://github.com/discourse/discourse-solved.git
    

    Add the plugin’s git clone url just below the line containing git clone https://github.com/discourse/docker_manager.git)

    Follow the existing format of the docker_manager.git line; if it does not contain sudo -E -u discourse then insert - git clone https://github.com/discourse/discourse-solved.git.

  • Rebuild the container:

    cd /var/discourse
    ./launcher rebuild app
    

    That’s it, you’ve successfully installed the Discourse Solved plugin on your Discourse instance!


If your plugin is hosted in a private repository

You must use an OAuth token:

With the OAuth token, you can install your plugin in the same way as a public repo, and you don’t need to create a SSH key.

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
              - sudo -E -u discourse git clone https://<token>@github.com/owner/repo.git

We strongly advise you to use OAuth tokens for plugins in private repositories. However, if you cannot, see below.

SSH Key Private Install Steps
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"
  • Rebuild the container:
cd /var/discourse
./launcher rebuild app

Your private plugin should be installed on your Discourse instance.

How to uninstall a plugin

To remove a plugin, simply remove the - git clone https://github.com/... line from your app.yml file and rebuild your site via

cd /var/discourse
./launcher rebuild app
「いいね!」 173

ガイドを更新し、Discourse Spoiler Alert の代わりに別のプラグインを使用するようにしました。これはコアにバンドルされています。

Discourse Solved を使用しましたが、別のものが良い場合はお知らせください。

「いいね!」 9

Digital OceanでDiscourseをホストしていましたが、そのフォーマットを使用した際にこのエラーが表示されました。

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse/plugins && 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 failed with return #<Process::Status: pid 252 exit 129>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"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"]}
bootstrap failed with exit code 129
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
2a49220a4ff35feac3c1a9a4a9c1cad1094bde4c9ba321975ebc9ae7ead2bbee

その後、このフォーマットを使用しました。

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

代わりに

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
「いいね!」 4

8件の投稿が新しいトピックに分割されました:Formatting issues adding plugins to app.yml

くだらない質問ですみませんが、git clone ステートメントに sudo -E -u discourse を含める必要があるかどうかは、どのように判断すればよいですか?

「いいね!」 3

docker_manager の行はどのようになっていますか?

「いいね!」 4

私のアプリの app.yml の他のエントリには sudo の部分はなかったので、それを省略しました。今のところうまくいっています。

「いいね!」 5
- exec: echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /user/.ssh/config

この方法はもう機能していないようです。

sh: 1: /user/.ssh/config: ディレクトリが存在しません

セルフホストされたGITリポジトリで、SSHキーを本当に使用したいです。

「いいね!」 3

コンテナ内にsshキーは必要ありません。これを削除してください。

「いいね!」 1

すみません、よく理解できませんでした。

私のリポジトリはSSH経由でアクセスできます。SSHキーなしでプラグインをクローンするにはどうすればよいですか?

「いいね!」 1

ああ。もしかしたら私が間違っているのかもしれません。それなら、適切な権限でそのディレクトリを作成する必要があるのかもしれません。

「いいね!」 1

紛らわしいのは、例の中のコマンドの一部は root として実行され、一部はユーザー 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

実行中のコンテナのシェルで調べてみます。

このプラグインのインストールは少し複雑です。テーマのインストールと同じようにできれば素晴らしいのですが。

「いいね!」 2

Dashboard.literatecomputing.com は数回のクリックでプラグインをインストールできます。無料トライアルグループに参加することで、無料で利用できます。

「いいね!」 4

@Discourse, ガイドを更新したい場合は、こちらが動作するコードです。

プライベートリポジトリにアクセスするために独自のSSHキーを使用するには、次の手順に従ってください。

  1. プライベートSSHキーを/var/discourse/shared/standalone/identity/id_rsa(またはコンテナからアクセス可能な別の場所)に配置します(別の場所を選択した場合は、以下のテンプレートのパスを適宜更新することを忘れないでください)。

  2. 次のテンプレートを使用してプラグインを追加します。

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          # プライベートリポジトリへのアクセスを設定
          - chown $(whoami) /shared/identity/id_rsa && chmod 600 /shared/identity/id_rsa
          - git config --global core.sshCommand "ssh -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i /shared/identity/id_rsa"

          # プライベートプラグイン
          - git clone git@example.com:repo/private-discourse-plugin.git

          # アクセスを解除
          - git config --global --unset core.sshCommand
「いいね!」 5

必要ないものに感謝します。しかし、私はシンプルなオリジナルで暮らしています。

なぜ私たちの例を使用すべきなのか説明していただけますか?それはこれのせいですか?

プライベートリポジトリにアクセスするために、独自のSSHキーを使用する

「いいね!」 1

URLにトークンを使用するのはなぜですか?

「いいね!」 1

さて、この謎を解くためのツールがあります😜

コンテナ設定スニペットの有用性を理解する AI

Jagster:

container/app.yml でこのスニペットを使用したいと思うのはなぜでしょうか?

gpt-4o:

ご質問に効果的に回答するには、container/app.yml の特定のスニペットのコンテキストを理解する必要があります。具体的なスニペットを提供していただけますか?そうすれば、正確で役立つ説明をすることができます。

Jagster:

すみません、このコンポーザーが必要でした。

これがスニペットです:

”””

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          # プライベートリポジトリへのアクセスを設定する
          - chown $(whoami) /shared/identity/id_rsa && chmod 600 /shared/identity/id_rsa
          - git config --global core.sshCommand "ssh -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i /shared/identity/id_rsa"

          # 私のプライベートプラグイン
          - git clone git@example.com:repo/private-discourse-plugin.git

          # アクセスを解除する
          - git config --global --unset core.sshCommand

”””

gpt-4o:

スニペットをご提供いただきありがとうございます。この YAML スニペットは、Discourse インスタンスの container/app.yml 設定ファイルに含まれることを意図しています。その内容を以下に示します。

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          # プライベートリポジトリへのアクセスを設定する
          - chown $(whoami) /shared/identity/id_rsa && chmod 600 /shared/identity/id_rsa
          - git config --global core.sshCommand "ssh -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i /shared/identity/id_rsa"

          # 私のプライベートプラグイン
          - git clone git@example.com:repo/private-discourse-plugin.git

          # アクセスを解除する
          - git config --global --unset core.sshCommand

説明

  1. ディレクトリの設定:

    cd: $home/plugins
    

    これは、プラグインが配置されているディレクトリ ($home/plugins) に作業ディレクトリを変更します。

  2. プライベートリポジトリへのアクセス設定:

    - chown $(whoami) /shared/identity/id_rsa && chmod 600 /shared/identity/id_rsa
    - git config --global core.sshCommand "ssh -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i /shared/identity/id_rsa"
    
    • SSH 秘密鍵 (id_rsa) の所有権を現在のユーザーに変更し、その権限を 600 に設定します。
    • Git がカスタム SSH コマンドを使用するように設定します。このコマンドは、指定された秘密鍵を使用し、厳格なホストキーチェックを無効にします。
  3. プライベートリポジトリのクローン:

    - git clone git@example.com:repo/private-discourse-plugin.git
    

    Discourse プラグインを含むプライベート Git リポジトリをクローンします。

  4. SSH コマンドの解除:

    - git config --global --unset core.sshCommand
    

    Git SSH コマンドの設定をデフォルトの状態にリセットします。

このスニペットを使用する時期と理由

  1. プライベートリポジトリ: 公開アクセスできず、SSH キーベースの認証が必要なプライベート Discourse プラグインリポジトリがある場合。

  2. 自動化: このスクリプトは、プライベートリポジトリへのアクセスを設定し、クローンし、その後環境がリセットされるようにするプロセスを自動化するのに役立ちます。これは、継続的デプロイメントのセットアップや自動サーバープロビジョニングに便利です。

  3. セキュリティ管理: 自動化されたデプロイメント中のセキュリティ体制を維持するために不可欠な、SSH キーを安全に処理します(ファイル権限の設定、その後カスタム SSH コマンドの解除)。

重要な考慮事項

  • プライベート SSH キー (id_rsa) が安全に管理され、公開されていないことを確認してください。
  • セキュリティポリシーに対して、所有権と権限が正しく設定されていることを確認してください。

Discourse の app.yml およびフックに関する詳細情報やコンテキストについては、関連する Discourse ドキュメント を参照してください。

設定に関するさらなる質問や追加の詳細が必要な場合は、お気軽にお尋ねください!

「いいね!」 3

こんにちは!素晴らしいですね!しかし、無料トライアルグループに参加した後、どのように進めばよいかわかりません!@pfaffmanさん、助けていただけますか?SAMLプラグインをインストールしたいのですが。Literate Computingをテストしてインストールし、実行できると素晴らしいです!

ありがとうございます!

「いいね!」 2

私のテンプレートスニペットは、SSHキー以外にGitリポジトリにアクセスする手段がない場合(たとえば、SSH経由でセルフホストされたGitリポジトリの場合)に使用します。

「いいね!」 5