macOSにDiscourseをインストールして開発環境を構築する

:warning: このガイドはmacOS開発環境のインストール手順について説明しています。本番環境のガイドについては、こちらを参照してください: Install Discourse in production with the official supported instructions

macOSでDiscourseを設定して、ハッキングや開発を行いたいと考えていますか?

ここでは、MacにRuby/Rails/Postgres/Redisがインストールされていないものと仮定します。では、始めましょう :rocket: !

Discourseの依存関係のインストール

システムには以下のパッケージが必要です:

** 任意

ターミナルを再起動してください

Discourseの依存関係のインストールが完了したので、次はDiscourse本体のインストールに進みましょう。

ターミナルの再起動

シェルを終了して再起動することで、インストールされたパッケージへのパスがターミナルによって正しく認識されるようになります。

Discourseのクローン

~/discourse フォルダにDiscourseリポジトリをクローンします:

git clone https://github.com/discourse/discourse.git ~/discourse

~ はホームフォルダを示しており、Discourseのソースコードはホームフォルダ内で利用可能になります。

Discourseのブートストラップ

Discourseフォルダに移動します:

cd ~/discourse

必要なgemをインストールします

bundle install

JSの依存関係をインストールします

pnpm install

次に、ローカルのDiscourseインスタンスを設定するために、これらのコマンドを実行します:

bundle exec rake db:create
bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate

RailsサーバーとEmberサーバーを起動します。ここでは2つのオプションがあります。

オプション 1: 2つの別々のターミナルタブ/ウィンドウを使用し、Railsとフロントエンドバンドラーを以下のように個別に実行します

bundle exec rails server

および

bin/dev --only ember

オプション 2: 1つのターミナルタブ/ウィンドウのみを使用します:

bin/dev # Pitchforkとフロントエンドバンドラーを一緒に実行します

:tada: これで http://localhost:3000 にアクセスして、ローカルのDiscourseインストールを確認できるはずです。(初回の読み込みはサーバーのウォームアップにより最大1分かかる場合があります。)

また、スペックの実行を試すこともできます:

bundle exec rake autospec

すべてのテスト(またはほぼすべてのテスト)がパスするはずです。

新しい管理者の作成

新しい管理者を作成するには、以下のコマンドを実行します:

RAILS_ENV=development bundle exec rake admin:create

プロンプトに従って管理者アカウントを作成します。

メールの設定

MailHogを実行します:

mailhog

おめでとうございます! これで、あなた自身のDiscourseインストールの管理者になりました!

ハッキングを楽しんでください! 始めるために、Discourseプラグイン作成の入門ガイド をご覧ください。


このドキュメントはバージョン管理されています - 変更提案は github で行ってください。

「いいね!」 78
Setup discourse on Mac OS
Running Discourse on Docker for Mac
Localhost:3000/users gives no-results
How to install Discourse on windows
How to install Discourse locally?
Best dev installation method for running on macOS?
MacOS Installation Gem::FilePermissionError
Discourse standalone
Migrate a NodeBB forum with Redis to Discourse
UndefinedTable: ERROR: relation "web_hook_event_types" when trying to run rspec test
Error after cleaning tmp folder
Local installation internal use only
Starting discourse fails with bootstrap error
Help me setup my Discourse development environment
Please help, how do I install Discourse on macOS?
Migrate a phpBB3 forum to Discourse
Migrate a FluxBB forum to Discourse
Migrate a vBulletin 3 forum to Discourse via XenForo
Migrate a MyBB forum to Discourse
Migrate a NodeBB forum with MongoDB to Discourse
Migrate a Ning forum to Discourse
Migrate a Phorum forum to Discourse
Migrate from another forum to Discourse
Migrate a Kunena 3 forum to Discourse
Migrate a bbPress WordPress plugin forum to Discourse
Install Discourse for development using Docker
Use the Discourse API ruby gem
Regarding the installation - docker
Set Environmental Variables
Need help integrating code wrote on Edittext to the Discourse
Keyboard navigation messes up the search menu
WP-Discourse not connected and admin email not recognized
Contributing to Discourse development
How to install discussions on localhost in my mac?
How to install Discourse for Wordpress locally running on MAMP
Error when building: "Runtime Error: discourse does not support compiling scss/sass files via sprockets"
Migrate from GetSatisfaction to Discourse
Case study of an amateur plugin author
Upgrading Mathjax to version 4
Windows server publish method
Discourse as Your First Rails App
Topic List Previews (TLP)
Enable CORS on localhost for DiscourseConnect
Category option: max topics per user (2 use-case examples)
Can't deploy to heroku
[PAID] Import from Legacy Postgres DB
Vagrant based server failing on db:migrate
Change unicorn port from 3000 in development
I want to build a debug version of discourse
Moderation Tools
Rails server --daemon and plugins
Installing problem - bundle install
Nginx Performance Report plugin incompatible with development environment setup script
Rake aborted message is showing when installing vagrant development
Update PhantomJS to latest for Ubuntu dev guide?
Cannot Backup my Development Instance (Fails)
Install error : Protocol violation
Can't set up dev environment due to cppjieba_rb failing to install
How to edit the discourse files? A development box?
How to add a new language
How to relax Content Security Policy
Installing Discourse for macOS Development Using asdf and docker-compose
Override profile background via SSO
Can't set up dev environment due to cppjieba_rb failing to install
Stuck in infinite loop in Mac terminal after source ~/.bashrc
Install on macOS – Failure: Scheduler::Defer can pause and resume
Disabling SSO in development environment
Local development and deploying from same repo
Discourse Connect on Local instance is not working
Can't start localhost server -- file was built for x86_64 which is not the architecture being linked (i386)
Please help, how do I install Discourse on macOS?
How to connect to an external database running on localhost
How can I include discourse in my local dev stack?
Global messages on 94632 timed out, restarting process, 95535 successfully terminated by `TERM` signal
Cannot get embedding to work
/admin/config/emoji non responsive/locks up
App.yml file does not exist when installing Discourse locally
Ember-cli error on local MacOS development
Importing / migrating from Zendesk Community to Discourse
Redis version error when I run bundle exec db:create
Dev environment setup failed on bundle install
Set up a local Discourse Development Environment?
[Need help][MacOS M1 dev installation] ArgumentError unknown keywords
Migrate a PunBB forum to Discourse

If anyone is getting failing specs with most of them being .count errors, then try the following:

RAILS_ENV=test bundle exec rake db:reset

I had a problem where development data somehow got into my test database and was causing lots of failures.

「いいね!」 7

Is it possible to reset a discourse completely?

「いいね!」 2

Yes, do:

rake db:drop db:create db:migrate

Note that this will wipe everything and you will have to create your Admin user account again.

「いいね!」 11

Can someone assist me in how I can update my discourse?

/launcher rebuild app

returns an error.

「いいね!」 1

./launcher rebuild app is for discourse_docker based production setup. To update local/development Discourse instance you need:

cd ~/discourse
git pull origin master
「いいね!」 8

I get this error @techAPJ,

error: Your local changes to the following files would be overwritten by merge:
	.gitignore
Please commit your changes or stash them before you merge.
Aborting

The error message is pretty clear:

Please commit your changes or stash them before you merge.

If you want to ignore your local changes, do:

git fetch origin
git reset --hard origin/master
「いいね!」 7

Ruby on Rails フォーラムのガイドを使っていて、現在はステップ 7 でつまずいています。

これはおそらくとても「初心者」的な質問だと思いますが、そのトピックにリンクされている実験的なブランチをどのように「指し示す」のでしょうか?いくつか試してみたのですが、毎回 Unknown command mini_racer, というメッセージが表示されてしまいます。

「いいね!」 1

ここでは質問しても問題ありません。

このガイドでは、Ruby on Rails フォーラムで参照している、私たちが作成した特定の M1 向け手順 がいくつか含まれています。

後で自分の M1 Air を確認する必要がありますし、最近新しい Mac をセットアップした同僚の方が、これがまだ必要かどうかをよりよく知っているかもしれません。しかし、ブランチを指し示す方法の例はステップ 7 にあります。

gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'

したがって、ローカルの discourse/Gemfile のこの行を編集します。

その後、bundle install を実行してください。

「いいね!」 4

元の投稿の一番上にリンクがあります。

Ruby on Rails フォーラムのトピックは数ヶ月も前に活動が止まっています。OP は 2 月以来アクティブになっておらず、助けを求めて寄せられたコメントにも返信していません。

ここには私を助けてくれる人がもっといます。念のため言っておきますね。:wink:

それをターミナルにコピーして試しましたが、以前と同じ Unknown command mini_racer, エラーが表示されました。

正直なところ、Ruby on Rails フォーラムのガイドはその点において私が望むほど明確ではありません。

あらかじめお詫び申し上げます… :pray:

「いいね!」 2

それは実行するコマンドではありません。discourse ディレクトリ内にある「Gemfile」という実際のテキストファイルを編集する必要があります。

「いいね!」 1

ああ! :facepalm:

ありがとう!今すぐ試してみます。

個人的には、Ruby on Rails フォーラムのガイドを編集して、ステップ 7 についてさらに明確な説明を加えるべきだと思います。ただの個人的な意見ですが。

すぐ戻ります。少し待ってください…

「いいね!」 1

急いで行かないといけないので申し訳ありませんが、m1 Mac向けのmini_racerの修正はマージされたと思います。私のm1 MacのGemfileを確認したところ、編集されていないので、ステップ7はスキップできると思います。

「いいね!」 3

ステップ 8 を実行したところ、「Could not locate Gemfile」というエラーが表示されました。

ステップ 7 は(おそらく)解決できたのですが、ステップ 8 でまだ問題が発生しており、上記のエラーが出力されます。

bundle install を実行する際は、必ず discourse ディレクトリ内にいる必要があります。

@merefield さん、こんにちは。リモート環境についてもう少し詳しく説明していただけますか?

テーマの開発では、ライブサイトに変更を加えることができますが、プラグインの開発においては、Discourse のコードベース全体(その上にプラグインを配置した状態)をローカルマシンに用意して行う以外に方法がないように思われます。

その結果、プラグインをコーディングする際に CSS 以外の何らかの変更を加えると、リロードするたびに 1) コンピューターのファンが回り出し、2) リロードに確実な 30 秒を要します。さらにサーバーを再起動する必要がある場合は、数分かかってしまいます。

これらの遅延は積み重なります。通常のコーディングフロー(ホットリロードがあるか、変更ごとにせいぜい 2〜3 秒かかる環境)であれば 15 分で済むものが、実際には1 時間もかかってしまうこともあります。

そのため、処理を高速化するためのご提案をいただければ幸いです。

「いいね!」 1

これはおそらく Ubuntu のトピック の方が適切でしょう。私はクラウドサーバー上でそのインストールを実行しており、nginx と完全な DNS(Docker は使用せず)でフロントエンドを構築しているため、実際にドメインを指しています。すべてをターミナルから実行しています。その環境でも Ember CLI がうまく動作するようになりました。

それほど高速ではありませんが、十分な速度です。フル HTTPS コールバックサービスを実行してテストできるという利点があります。

私が知る限り、最も高速なプラグイン開発環境はローカルの WSL2 上の Docker Dev で、爆速です。また、メンテナンスも非常に簡単です。残念ながら、私の知る限り discourse_theme はその環境ではまだ動作しないため、その作業については再びクラウドサーバーに戻っています。

なぜ Apple がここで出遅れているのか、少し不思議に思います。Microsoft のエンジニアたちは非常に機転が利くことを証明しました。

「いいね!」 3

Ruby 2.7.3 のインストールでエラーが発生した場合に備えて、Xcode 12 以降で何かが変更され、rbenv でのインストールプロセスが壊れるようです。

最新バージョンの psych と libyaml がインストールされているにもかかわらず、次のようなエラーが 계속 발생しました。

It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

ガイドで提案されている回避策を試しましたが、同じエラーが 계속発生し、最終的には rvm を使用する必要がありました。

rvm install 2.7.3
「いいね!」 1

プラグイン開発をより速く行う方法について、最近アプローチを変更しました。そして、それは素晴らしい結果をもたらしています。基本的に、フロントエンドの作業はすべてテーマコンポーネントに移動し、プラグイン自体ではバックエンドの作業のみをコーディングします。他の人も以前にそれに気づいていたことは知っています。しかし、今私がそれをやっていると、プログラミングははるかに速く、より快適になりました。詳細はこちらをご覧ください。

「いいね!」 3