تثبيت الإضافات على موقع ذاتي الاستضافة

: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 وعندما استخدمت هذا التنسيق، ظهر لي هذا الخطأ.

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse/plugins &amp;&amp; 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 #&lt;Process::Status: pid 252 exit 129&gt;
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"=&gt;"$home/plugins", "cmd"=&gt;["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 &amp;&amp; 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 مشاركات إلى موضوع جديد: مشاكل التنسيق عند إضافة المكونات الإضافية إلى app.yml

عذرًا على سؤالي الغبي، ولكن كيف أعرف ما إذا كان يجب تضمين sudo -E -u discourse أم لا في عبارة git clone؟

3 إعجابات

كيف يبدو سطر docker_manager الخاص بك؟

4 إعجابات

لم يكن لدى الإدخالات الأخرى في ملف app.yml الخاص بي جزء sudo لذلك حذفته وقد نجح الأمر حتى الآن

5 إعجابات
- exec: echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /user/.ssh/config

يبدو أن هذه الطريقة لم تعد تعمل.

sh: 1: cannot create /user/.ssh/config: Directory nonexistent

مع مستودع 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

سأقوم ببعض البحث في shell الحاوية قيد التشغيل.

تثبيت هذه الإضافة معقد بعض الشيء. سيكون من الرائع لو أمكن جعله مثل تثبيت سمة.

إعجابَين (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)

حسنًا، لدينا أدوات لحل هذا اللغز :winking_face_with_tongue:

فهم فائدة مقتطفات تكوين الحاوية AI

Jagster:

لماذا قد يرغب شخص ما في استخدام هذا المقتطف في container/app.ym

gpt-4o:

للإجابة على سؤالك بفعالية، أحتاج إلى فهم السياق المحيط بالمقتطف المحدد في container/app.yml. هل يمكنك تقديم المزيد من التفاصيل أو المقتطف الفعلي الذي تشير إليه؟ بهذه الطريقة، يمكنني أن أقدم لك شرحًا دقيقًا ومفيدًا.

Jagster:

آسف، لكنني كنت بحاجة إلى هذا الملحق.

هذا هو المقتطف:

“”"

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          # Set private repo access
          - 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"

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

          # Unset access
          - git config --global --unset core.sshCommand

“”"

gpt-4o:

شكرًا لك على تقديم المقتطف. يُقصد تضمين مقتطف YAML هذا في ملف تكوين container/app.yml لمثيل Discourse. دعنا نفصل ما يفعله:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          # Set private repo access
          - 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"

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

          # Unset access
          - 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 مخصص يستخدم مفتاح SSH الخاص المحدد ويعطل التحقق الصارم من مفتاح المضيف.
  3. استنساخ المستودع الخاص:

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

    استنساخ مستودع Git خاص يحتوي على مكون إضافي لـ Discourse.

  4. إلغاء تعيين أمر SSH:

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

    إعادة تعيين تكوين أمر SSH الخاص بـ Git إلى حالته الافتراضية.

متى ولماذا تستخدم هذا المقتطف

  1. المستودعات الخاصة: إذا كان لديك مستودع مكون إضافي خاص لـ Discourse غير متاح للجمهور ويتطلب مصادقة قائمة على مفتاح SSH.

  2. الأتمتة: يساعد هذا البرنامج النصي في أتمتة عملية إعداد الوصول إلى المستودع الخاص، واستنساخه، وضمان إعادة تعيين البيئة بعد ذلك. هذا مفيد لإعدادات النشر المستمر أو توفير الخادم الآلي.

  3. إدارة الأمان: يتعامل مع مفاتيح SSH بأمان (ضبط أذونات الملفات ثم إلغاء تعيين أمر SSH المخصص)، وهو أمر بالغ الأهمية للحفاظ على وضع الأمان أثناء عمليات النشر الآلية.

اعتبارات هامة

  • تأكد من إدارة مفتاح SSH الخاص بك (id_rsa) بشكل آمن وعدم تعرضه.
  • تحقق من تعيين الملكية والأذونات بشكل صحيح لسياسات الأمان الخاصة بك.

لمزيد من المعلومات التفصيلية والسياقات حول app.yml والخطافات في Discourse، يمكنك التحقق من وثائق Discourse ذات الصلة.

إذا كانت لديك أي أسئلة أخرى أو كنت بحاجة إلى تفاصيل إضافية حول التكوين، فلا تتردد في السؤال!

3 إعجابات

مرحباً! يبدو الأمر رائعاً! لكنني لا أعرف كيف يجب أن أتابع بعد الانضمام إلى مجموعة التجربة المجانية! من فضلك، @pfaffman، هل يمكنك مساعدتي؟ أنا أتطلع إلى تثبيت إضافة SAML. سيكون من الرائع اختبار Literate Computing لتثبيتها وتشغيلها!

شكراً!

إعجابَين (2)

مقتطف القالب الخاص بي مخصص للحالات التي لا تملك فيها أي وسيلة أخرى للوصول إلى مستودع Git بخلاف مفتاح SSH (على سبيل المثال، مع مستودع Git مستضاف ذاتيًا خلف SSH).

5 إعجابات