外部数据库环境变量未文档化(外部 PostgreSQL 端口、外部 Redis 环境变量)

Greetings,

I can’t post in the Sysadmin category.

I can configure an external DB using:

DISCOURSE_DB_USERNAME
DISCOURSE_DB_PASSWORD
DISCOURSE_DB_HOST
DISCOURSE_DB_NAME

But I couldn’t find:

DISCOURSE_DB_PORT (External PostgreSQL Port)
DISCOURSE_REDIS_HOST
DISCOURSE_REDIS_USERNAME
DISCOURSE_REDIS_PASSWORD
DISCOURSE_REDIS_NAME (which database, 0,1,2,3, etc)

I’m an engineer at Compose/IBM and I’m attempting to setup Discourse using our production-ready, replicated databases. I’d like to run a web_only instance with external Redis & PostgreSQL

I also couldn’t find configuration parameters for failover support:

We supply two URIs “portals” for connection failover. I don’t have a ton of time to dig through the Discourse codebase and see which client driver you are using.

Lastly, we use SSL (using valid LE certs) for both Redis and PostgreSQL. Is your app configured for SSL support?

Thanks!

P.S. I’m reaching out personally, not officially from IBM/Compose. I enjoy Discourse and have been considering writing an article on how to configure Discourse using our services:

You can see all of the possible global vars documented at:

You can pass in config from your environment, all the settings below are available.
Append DISCOURSE_ and upper case the setting in ENV. For example:
to pass in db_timeout of 200 you would use DISCOURSE_DB_TIMEOUT=200

我正在为 docker-compose 应用进行此操作,尽管已导出 DISCOURSE_REDIS_HOST 环境变量(设置为 redis),但它并未生效:

name, 'name', name),\n  updated_at,\n  created_at,\n  updated_at\nFROM facebook_user_infos\n")
discourse_1_9cc0cea436ca | rake aborted!
discourse_1_9cc0cea436ca | Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)
discourse_1_9cc0cea436ca | /usr/local/bundle/gems/redis-4.0.1/lib/redis/client.rb:344:in `rescue in establish_connection'

我的完整代码在这里,如果您想查看。不知何故,这些本应生效的变量并未被识别。作为背景,我真的很想帮助开发一个插件,但入门门槛(在不将一切安装到主机上的情况下搭建基本开发环境)非常高。我唯一一次成功运行 Discourse 是使用 bitnami 镜像,但有人(在其他地方)告诉我那不是正确的方法。请帮帮我——这不该这么难,尤其是当我愿意贡献免费时间来帮助社区时:frowning:

我不太确定您为何会遇到该问题,但如果按照以下推荐方式操作,您会轻松许多:Install Discourse for development using Docker

另请参阅:Can Discourse ship frequent Docker images that do not need to be bootstrapped? - #6 by fbender

也许我读错了代码,但 bin/docker/boot_dev --init 脚本仍然在与数据库交互,并且依赖主机上的依赖项。

对于第二个线程,你具体是指让我看哪一部分?它有 151 条回复。谢谢!

在生产环境中,该变量可以正常生效。

在开发环境中,默认会查找本地实例,如果您遵循支持的任一开发环境配置,这将正常工作。

我使用 production 作为环境变量运行它,但该设置未被生效。作为临时解决方案,我使用 sed 修改了配置文件,问题得以解决。目前我仍在处理其他诸多问题。

例如,我一开始就明确指定不要守护进程化(以保持容器运行):

bundle exec rails s --port 3000 --no-daemon --environment=production --binding 0.0.0.0

但系统似乎仍然决定这样做!随后容器便退出了。

discourse_1_f60e0e3f1186 | [358] Puma starting in cluster mode...
discourse_1_f60e0e3f1186 | [358] * Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
discourse_1_f60e0e3f1186 | [358] * Min threads: 8, max threads: 32
discourse_1_f60e0e3f1186 | [358] * Environment: production
discourse_1_f60e0e3f1186 | [358] * Process workers: 4
discourse_1_f60e0e3f1186 | [358] * Preloading application
discourse_1_f60e0e3f1186 | [358] * Listening on tcp://0.0.0.0:3000
discourse_1_f60e0e3f1186 | [358] * Daemonizing...
docker-compose-discourse_discourse_1_f60e0e3f1186 exited with code 0

奇怪的是,明明提供了各种参数、指令和环境变量,但它们却并未被真正遵循。让人很难判断究竟该相信什么。

你想要生产环境还是开发环境?

为什么不能在生产环境中运行并用于开发?Sidekiq 是做什么的?是否应该单独运行它来启动应用程序?例如,我有另一个容器(基于相同的镜像),其启动命令为:

bundle exec sidekiq

它依赖于主 Discourse 容器(进行数据库迁移、预编译静态资源等)。一切似乎都正常工作,但没有 Web 应用程序。

我很乐意花更多时间在这上面,前提是我还没开始做任何事情,但我需要一个无需在主机上安装数据库的解决方案。使用容器,我们本就不必这样做。再说一次,这里的 compose 应用 GitHub - vsoch/discourse-compose: docker-compose with discourse · GitHub 似乎运行正常(所有日志中均无错误),但却没有应用程序。

因为它会缓存和预编译大量内容,这基本上使得开发工作无法进行。

我上面链接的 Install Discourse for development using Docker 正是这样做的。

Sidekiq 用于队列化和处理后续作业。

我遗漏了什么?–init 命令是在主机上运行的:

说得有道理,但假设我已经在进行预编译了(这确实需要一些时间!),并且我想启动服务器。为什么它无法工作?

好的,我最终运行了 --init 命令。我可以确认容器正在运行:

CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS              PORTS                                                                                            NAMES
d2254e1374f5        discourse/discourse_dev:release   "/sbin/boot"        24 minutes ago      Up 24 minutes       0.0.0.0:1080->1080/tcp, 0.0.0.0:3000->3000/tcp, 0.0.0.0:9292->9292/tcp, 0.0.0.0:9405->9405/tcp   discourse_dev

但在任何端口上都看不到任何记录。我尝试了两个浏览器、localhost、127.0.0.1 和 0.0.0.0,但都没有网页应用。错误是 ERR_CONNECTION_RESET。我在 iptables 中没有看到任何会阻止此连接的规则:

Chain DOCKER (3 references)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:9405
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:9292
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:3000
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:socks

2019 年 7 月 10 日更新

感谢大家的帮助——问题在于需要执行那个 “unicorn” 命令,现在一切正常了。我还必须在启动命令中运行 rake admin:create,否则系统会要求邮件确认(完整仓库见此处)。discourse_dev 也能正常工作。