使用 Docker 为开发安装 Discourse

你好,

我在运行 d/boot_dev --init 时遇到了这个错误:

Errno::EACCES: Permission denied @ dir_s_mkdir - tmp
/src/config/boot.rb:23:in `\u003ctop (required)\u003e'
/src/config/application.rb:16:in `require'
/src/config/application.rb:16:in `\u003ctop (required)\u003e'
/src/Rakefile:7:in `require'
/src/Rakefile:7:in `\u003ctop (required)\u003e'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `\u003cmain\u003e'
(See full trace by running task with --trace)

有什么修复建议吗?我到处搜索过,但没找到解决方案。

编辑:通过执行 chmod -R 777 ~/discourse 解决了该问题,但现在又出现了这个错误:

gifsicle worker: gifsicle not found; please provide proper binary or disable this worker (--no-gifsicle argument or :gifsicle =\u003e false through options)

2 个赞

这不是一个问题,我们最近已经移除了相关使用,该警告无需担心。您是否在基于旧版 Discourse 代码进行操作?

4 个赞

不,是最近发布的版本。但我按照 DigitalOcean 的这篇教程 操作后,现在已经完全正常运行了。

2 个赞

如何在这种设置中使用插件?
我试图参考 https://meta.discourse.org/t/install-plugins-in-discourse/19157,但其中提到了 /var/discourse/containers/app.yml 文件,而我的 discourse 目录中并不存在该文件。

我已经成功搭建好了 Discourse 开发环境并能够测试我的补丁,但如何将补丁部署到我的生产实例呢?我尝试构建 base,然后运行 ./launcher rebuild app --run-image discourse/base:build,但这似乎并没有让 Discourse 实例正常运行。

通常我会遇到关于缺少 syslog 组的错误,但我已经注释掉了相关部分,结果仍然没有看到站点正常运行。而且 Docker 日志中也没有任何值得注意的信息。

我们通常不专门记录这类操作,但您可以先生成一个“diff”文件,然后在克隆仓库后,通过钩子(hook)使用 git apply 应用该 diff。app.yml 支持钩子。

对于自托管的单容器场景,一个快速简便的解决方案是直接修改代码,然后运行 sv restart unicorn

2 个赞

不确定这是否是提出该问题的最佳位置,但我一直无法在 Apple M1 电脑上使用 Docker 完成 Discourse 的安装。

运行 d/boot_dev --init 后,所有依赖项似乎都正常安装,但一旦进入“迁移数据库”步骤,进程就会卡住,占用其中一个核心的 100% 资源,且似乎没有任何进展。

我尝试登录到 Docker 容器,发现 bundle migrate 任务正在以 100% 的 CPU 使用率运行,但 PostgreSQL 进程似乎没有任何活动。

任何建议都将非常有帮助!

1 个赞

我认为虚拟化支持确实非常新,难怪会有些波折。

@pmusaraj / @david 在 M1 上让 docker-dev 运行起来有进展吗?

5 个赞

我还没试过。

2 个赞

如果有人在 M1 Mac 上能够使用 Docker 运行 Discourse,请告诉我。同时,我会尝试遵循其他指南!谢谢!

1 个赞

我今天试了一下,卡在了和你相同的步骤,但报错了:

Invalid gemspec in [/usr/local/lib/ruby/gems/2.7.0/specifications/default/zlib-1.1.0.gemspec]: Malformed version number string specification_version
bundler: failed to load command: rake (/usr/local/bin/rake)

好的,请照做。我们团队有多位成员(包括我)每天都在 M1 芯片的 Mac 上使用 Discourse,运行得非常顺畅!

如果遇到任何问题,请随时告诉我们。

2 个赞

非常感谢您的时间和帮助!至少我不是唯一一个被困住的人。

嗨,我想我们应该在这里添加一段关于 Ember-CLI 的描述,并为下方的命令提供一个快捷方式,这样就不需要进入 Docker 容器了。

而且,我在容器内执行上述命令时无法使其正常工作,似乎容器没有暴露 4200 端口。
Screenshot from 2021-05-02 15-48-51

通过编辑 d/boot_dev 手动暴露 4200 端口:

重启容器后,我访问 localhost:4200 却得到了这个结果:

discourse@discourse:/tmp$ cat error.dump.cab4cc444229d44fc0fce2deb8695880.log 
=================================================================================

ENV Summary:

  TIME: Sun May 02 2021 08:01:12 GMT+0000 (Coordinated Universal Time)
  TITLE: ember
  ARGV:
  - /usr/bin/node
  - /src/app/assets/javascripts/node_modules/.bin/ember
  - server
  - --proxy
  - http://localhost:3000
  EXEC_PATH: /usr/bin/node
  TMPDIR: /tmp
  SHELL: /bin/bash
  PATH:
  - /tmp/yarn--1619942449179-0.1910991449592403
  - /src/app/assets/javascripts/discourse/node_modules/.bin
  - /home/discourse/.config/yarn/link/node_modules/.bin
  - /src/app/assets/javascripts/node_modules/.bin
  - /home/discourse/.yarn/bin
  - /usr/libexec/lib/node_modules/npm/bin/node-gyp-bin
  - /usr/lib/node_modules/npm/bin/node-gyp-bin
  - /usr/bin/node_modules/npm/bin/node-gyp-bin
  - /usr/local/sbin
  - /usr/local/bin
  - /usr/sbin
  - /usr/bin
  - /sbin
  - /bin
  PLATFORM: linux x64
  FREEMEM: 8603062272
  TOTALMEM: 41962496000
  UPTIME: 612639
  LOADAVG: 3.32177734375,2.19580078125,1.47900390625
  CPUS:
  - Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz - 3301
  - Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz - 3300
  - Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz - 3300
  - Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz - 3301
  ENDIANNESS: LE
  VERSIONS:
  - ares: 1.15.0
  - brotli: 1.0.7
  - cldr: 35.1
  - http_parser: 2.9.3
  - icu: 64.2
  - modules: 64
  - napi: 7
  - nghttp2: 1.41.0
  - node: 10.23.0
  - openssl: 1.1.1g
  - tz: 2019c
  - unicode: 12.1
  - uv: 1.34.2
  - v8: 6.8.275.32-node.59
  - zlib: 1.2.11

ERROR Summary:

  - broccoliBuilderErrorStack: [undefined]
  - code: ECONNREFUSED
  - codeFrame: [undefined]
  - errorMessage: connect ECONNREFUSED 127.0.0.1:3000
  - errorType: [undefined]
  - location:
    - column: [undefined]
    - file: [undefined]
    - line: [undefined]
  - message: connect ECONNREFUSED 127.0.0.1:3000
  - name: Error
  - nodeAnnotation: [undefined]
  - nodeName: [undefined]
  - originalErrorMessage: [undefined]
  - stack: Error: connect ECONNREFUSED 127.0.0.1:3000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)

=================================================================================

bin/ember-cli 中的 PORT 从 3000 改为 9292 后,一切正常了。
Screenshot from 2021-05-02 17-55-24

看起来 ember-cli 的 bash 脚本无法与 ENV["UNICORN_PORT"] 协同工作。

1 个赞

Ember CLI 是一项全新(且来之不易)的进展;@eviltrout 应该很快就能对此发表评论。

3 个赞

是的,这需要更新。在此期间,您可以通过将 NO_EMBER_CLI 环境变量设置为 1 来禁用该功能。

5 个赞

这很明显,但能否请您澄清一下在哪里设置了环境变量 @eviltrout

我尝试在 d/unicorn 文件中这样设置:

docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" -e NO_EMBER_CLI=1

……但这没有生效(在 localhost:9292 仍然收到“开发模式下需要 Ember CLI"的提示)。

d/boot_dev -e NO_EMBER_CLI=1

我今天也尝试了,但遇到了问题。出现的错误是因为 Docker 的架构模拟不支持 inotify(我们在 Discourse 开发中大量使用它)。目前,我已在检测到非 x86_64 架构时,向 d/boot_dev 添加了警告:

❯ d/boot_dev 
WARNING: Docker architecture is not x86_64.
Discourse development is unlikely to work using Docker's architecture emulation.
Please try a native development installation.

我现在已添加了 d/ember-cli 辅助脚本,并默认转发了 4200 端口。本主题顶部的信息也已更新。更新后,请在一个终端中运行 d/rails s,在另一个终端中运行 d/ember-cli。我还将 NO_EMBER_CLI 设置为传递给 Docker 的变量之一,以便在需要时使用。

6 个赞

@david 可能无关紧要,但仅供参考:当我意外在未使用 Docker 的情况下运行时,boot_dev 脚本在 x86_64 检查中打印了一个错误的发现(但“Docker 守护进程是否正在运行”这部分是正确的)……

警告:Docker 架构不是 x86_64。
使用 Docker 的架构模拟进行 Discourse 开发可能无法正常工作。
请尝试原生开发安装。
  ...(省略)...\
无法连接到 unix:///var/run/docker.sock 处的 Docker 守护进程。Docker 守护进程是否正在运行?
1 个赞

感谢分享这张图片和超清晰的说明!

运行 d/boot_dev --init 时,我遇到了 psql: error: FATAL: Peer authentication failed for user "postgres" 错误。

虽然 data/postgres/ 目录下的 pg_hba.conf 已将所有认证方法设置为 “trust”,但在 /etc/postgresql/13/main/ 下还有一个文件使用了默认设置(“peer” / “md5”)。

我编辑了 /etc/postgresql/13/main/pg_hba.conf,将所有方法改为 trust,然后执行 d/shell 并运行 sv restart postgres 以应用更改——随后通过手动执行 d/bundle install; d/rake db:migrate RAILS_ENV=development; d/rake admin:create 成功继续。

留在这里,希望能对其他人有所帮助!

1 个赞