Developing Discourse on GitHub Codespaces

GitHub Codespaces is a very fast way to get started with Discourse development. Their free tier is good for 30 hours per month of a 4-core machine.

Getting Started

  1. Navigate to the github repository

  2. Press the , (comma) key on your keyboard, to open GitHub codespaces

  3. Use ‘change options’ to customize the machine. Technically, the 2-core machine will work, but we recommend using at least 4-core for a better experience.

  4. Click “Create Codespace”

  5. Wait for the container to download and start. When it’s done, the README will appear, and you’ll see the Discourse filesystem in the sidebar.

  6. Run the default build task using Ctrl + Shift + B (Cmd + Shift + B on mac).

    This will install dependencies, migrate the database, and start the server. It’ll take a few minutes, especially on the lower-end machines. You’ll see “Build successful” in the terminal when it’s done.

  7. Visit the “Ports” tab, and click the :globe_with_meridians: button for port 4200. This will open a new tab showing your development copy of Discourse

  8. All done! You can now make changes in the codespace and see them reflected in the preview.

The VSCode environment will automatically be configured with our recommended settings and extensions, including automatic linting and formatting.

To minimize usage, make sure to run “Codespaces: Stop Current Codespace” from the command palette (Ctrl + Shift + P or Cmd + Shift + P) when you’re finished. If you forget to do this, the Codespace should be shut down automatically after your account’s configured idle time (default 30 mins). But, there are some situations where the codespace will not be detected as idle, so it’s best to stop it deliberately.

Tips

  • You can launch a codespace from specific branches/PRs - just visit it, and press ,

  • You can manage all your codespaces at Sign in to GitHub · GitHub

  • Discourse’s sample vscode .vscode/settings.json and .vscode/tasks.json will be copied when you first boot the codespace. From that point forward, if you want to use the latest sample config, you’ll need to manually copy .vscode/settings.json.sample to .vscode/settings.json.


This document is version controlled - suggest changes on github.

12 个赞

我发现了一个问题:启动时会创建以下类别:
General、Staff、Staff67d17c71d8026b365c4c6657a9a9b5eb 和 General(后跟随机字符串和数字)。
那些带有随机字符串和数字的类别可以不要创建吗?我可以删除 General 的克隆,但不能删除 Staff 的克隆,因为它有 FAQ 主题(这个也在常规的 Staff 类别中,所以没有意义)。

编辑:Site Feedbackee4d95d3ac0267109c01ed5438943e6c 也会被创建,尽管已经有一个 Site feedback 了。Uncategorized 也有一个克隆。

1 个赞

这让我想起了 Random string in category name

2 个赞

备份数据库时,我收到此错误:

[2024-12-12 10:31:26] [STARTED]
[2024-12-12 10:31:26] 'system' has started the backup!
[2024-12-12 10:31:26] Marking backup as running...
[2024-12-12 10:31:26] Making sure '/workspace/discourse/tmp/backups/default/2024-12-12-103126' exists...
[2024-12-12 10:31:26] Making sure '/workspace/discourse/public/backups/default' exists...
[2024-12-12 10:31:26] Updating metadata...
[2024-12-12 10:31:27] Dumping the public schema of the database...
[2024-12-12 10:31:28] pg_dump: error: connection to database "discourse_development" failed: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"
[2024-12-12 10:31:28] EXCEPTION: pg_dump failed
[2024-12-12 10:31:28] /workspace/discourse/lib/backup_restore/backuper.rb:173:in `dump_public_schema'
/workspace/discourse/lib/backup_restore/backuper.rb:36:in `run'
/workspace/discourse/lib/backup_restore.rb:13:in `backup!'
/workspace/discourse/app/jobs/regular/create_backup.rb:10:in `execute'
/workspace/discourse/app/jobs/base.rb:322:in `block (2 levels) in perform'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/rails_multisite-6.1.0/lib/rails_multisite/connection_management/null_instance.rb:49:in `with_connection'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/rails_multisite-6.1.0/lib/rails_multisite/connection_management.rb:21:in `with_connection'
/workspace/discourse/app/jobs/base.rb:309:in `block in perform'
/workspace/discourse/app/jobs/base.rb:305:in `each'
/workspace/discourse/app/jobs/base.rb:305:in `perform'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:202:in `execute_job'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:170:in `block (2 levels) in process'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/middleware/chain.rb:177:in `block in invoke'
/workspace/discourse/lib/sidekiq/pausable.rb:132:in `call'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/middleware/chain.rb:179:in `block in invoke'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/middleware/chain.rb:182:in `invoke'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:169:in `block in process'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:136:in `block (6 levels) in dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_retry.rb:113:in `local'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:135:in `block (5 levels) in dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq.rb:44:in `block in <module:Sidekiq>'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:131:in `block (4 levels) in dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:263:in `stats'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:126:in `block (3 levels) in dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_logger.rb:13:in `call'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:125:in `block (2 levels) in dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_retry.rb:80:in `global'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:124:in `block in dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/job_logger.rb:39:in `prepare'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:123:in `dispatch'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:168:in `process'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:78:in `process_one'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/processor.rb:68:in `run'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/component.rb:8:in `watchdog'
/home/discourse/.bundle/gems/ruby/3.3.0/gems/sidekiq-6.5.12/lib/sidekiq/component.rb:17:in `block in safe_thread'
[2024-12-12 10:31:28] Cleaning stuff up...
[2024-12-12 10:31:28] Removing '.tar' leftovers...
[2024-12-12 10:31:28] Marking backup as finished...
[2024-12-12 10:31:28] Notifying 'system' of the end of the backup...

每次我使用 bin/ember-cli-u 启动论坛时都会发生这种情况。

点击管理面板中的 Backup 时,我收到:

[2024-12-12 10:34:57] [STARTED]
[2024-12-12 10:34:57] 'NateDhaliwal' has started the backup!
[2024-12-12 10:34:57] Marking backup as running...
[2024-12-12 10:34:57] Making sure '/workspace/discourse/tmp/backups/default/2024-12-12-103457' exists...
[2024-12-12 10:34:57] Making sure '/workspace/discourse/public/backups/default' exists...
[2024-12-12 10:34:57] Updating metadata...
[2024-12-12 10:34:57] Dumping the public schema of the database...
[2024-12-12 10:34:57] pg_dump: error: connection to database "discourse_development" failed: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"
[2024-12-12 10:34:57] EXCEPTION: pg_dump failed
[2024-12-12 10:34:57] /workspace/discourse/lib/backup_restore/backuper.rb:173:in `dump_public_schema'
/workspace/discourse/lib/backup_restore/backuper.rb:36:in `run'
/workspace/discourse/script/spawn_backup_restore.rb:9:in `backup'
/workspace/discourse/script/spawn_backup_restore.rb:31:in `block in <main>'
/workspace/discourse/script/spawn_backup_restore.rb:4:in `fork'
/workspace/discourse/script/spawn_backup_restore.rb:4:in `<main>'
[2024-12-12 10:34:57] Cleaning stuff up...
[2024-12-12 10:34:57] Removing '.tar' leftovers...
[2024-12-12 10:34:57] Marking backup as finished...
[2024-12-12 10:34:57] Notifying 'NateDhaliwal' of the end of the backup...

当我尝试像图像所示那样将其从主分支更改为 devcontainer 时,我什么也得不到,它说没有结果。

如果您指的是第二张图片页脚中显示的“devcontainer”分支,那么您应该忽略它。这些屏幕截图是在 main 分支上提供 devcontainer 配置之前拍摄的。

谢谢你,大卫

但在按下它之前,您需要在代码中创建一个管理员帐户。有人能给我发一些图片展示如何操作吗?因为我终于有办法访问我自己的 Discourse 了,但如果不知道如何设置就无法完成。所以有人能提供图片让我看看如何操作吗?

您可以使用其他非 Docker 安装中描述的步骤,例如 Install Discourse on Ubuntu or Debian for Development

创建管理员帐户的命令是 bin/rails admin:create,然后按照提示操作。

3 个赞

太好了,谢谢!我现在有了自己的论坛。

@david 有什么想法吗?我仍然收到此错误。

这个系统是否与discourse插件兼容?它可以吗?

是的,我试过了,插件确实可以正常工作。
安装方法如下:

我已经安装了帖子投票、主题投票和游戏化插件,到目前为止它们都可以正常工作。

3 个赞

是的,它只是运行我们在云中的标准 Docker 容器,所以你可以 cd 到插件目录并克隆你喜欢的任何内容。

有一天,如果我们可以在每个插件仓库中设置配置,代码空间环境就可以直接从它们的仓库中启动,那就太好了。

6 个赞

不确定这是否与 Codespaces 或只是 Linux 环境有关,但当我模拟用户并切换用户时登录和注销,bin/ember-cli -u 就会终止,没有任何日志指向可能导致此问题的错误。并且 codespace 已与 Discourse 存储库同步。