Install Discourse for development using Docker

Simon, that’s more than an excellent useable workaround, thanks!

Just tried that and it works, ie:

my-blah-machine:~/discourse$ d/shell
discourse@discourse:/src$ LOAD_PLUGINS=1 RAILS_ENV=test rspec plugins/discourse-follow/spec/lib/updater_spec.rb:37

Have added this and the whole plugin version to the Wiki

1 Like

Taking a closer look at d/exec, which both d/shell and d/rspec use, I think it can also be shortened like so:

RAILS_ENV=test d/exec LOAD_PLUGINS=1 rspec plugins/discourse-follow/spec/lib/updater_spec.rb:37

d/exec does pass in RAILS_ENV but not LOAD_PLUGINS, hence them being on either side of d/exec.

1 Like

That gives me an error:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "LOAD_PLUGINS=1": executable file not found in $PATH: unknown

Ah, I guess environment variables can’t be used with docker exec like that. Oh well, at least opening the shell first works.

1 Like

I’m having the exact same problem as Max. Whenever I try to make a backup or a restore on my local development docker install I get the same error: Peer authentication failed for user "postgres"

After some digging around I found that in the development environment the database configuration shows up like this:

BackupRestore.database_configuration
=> #<struct BackupRestore::DatabaseConfiguration host=nil, port=nil, username="postgres", password=nil, database="discourse_development">

Somehow the dev environment is not setting the username on the environment variables and then the BackupRestore module just defaults the username value to postgres

# lib/backup_restore.rb:122

    DatabaseConfiguration.new(
      config["backup_host"] || config["host"],
      config["backup_port"] || config["port"],
      config["username"] || username || ENV["USER"] || "postgres",
      config["password"] || password,
      config["database"]
    )

Where can we set the right database username?

1 Like

How do we use the Discourse Theme CLI (console app to help you build themes) here?

We’ve successfully installed the gem: d/exec sudo gem install discourse_theme … now the challenge is to symlink to local theme …

@Simon_Manning note use of sudo to get around permissions (thanks for reminder @fzngagan)

I’m trying to test a plugin using the docker setup. Randomly the app stops loading and I’m just presented with a blank page until I delete the data folder and rebuild everything. Any tips on how to debug the issue?

Have there been any findings on that one? Still seems to be an issue.

My “dirty” workaround was to replace the username from postgres to discourse on the following block of code:

# lib/backup_restore.rb:122

    DatabaseConfiguration.new(
      config["backup_host"] || config["host"],
      config["backup_port"] || config["port"],
      config["username"] || username || ENV["USER"] || "postgres",
      config["password"] || password,
      config["database"]
    )

I switched from my local Mac to a Ubuntu VM hoping this would make it easier to get this running but unfortunately so far it’s not.

Already fighting some weird permission problems in the early stages. d/bundle install reports it needs sudo rights to install some, d/rails s also comes back with permission problems

Traceback (most recent call last):
        8: from /src/bin/unicorn:70:in `<main>'
        7: from /src/bin/unicorn:38:in `ensure_cache_clean!'
        6: from /usr/local/lib/ruby/2.7.0/fileutils.rb:211:in `mkdir_p'
        5: from /usr/local/lib/ruby/2.7.0/fileutils.rb:211:in `each'
        4: from /usr/local/lib/ruby/2.7.0/fileutils.rb:226:in `block in mkdir_p'
        3: from /usr/local/lib/ruby/2.7.0/fileutils.rb:226:in `reverse_each'
        2: from /usr/local/lib/ruby/2.7.0/fileutils.rb:228:in `block (2 levels) in mkdir_p'
        1: from /usr/local/lib/ruby/2.7.0/fileutils.rb:250:in `fu_mkdir'
/usr/local/lib/ruby/2.7.0/fileutils.rb:250:in `mkdir': Permission denied @ dir_s_mkdir - /src/tmp (Errno::EACCES)

Any idea what’s going wrong? This machine previously ran a production discourse without issues. I just stopped and removed those containers and cloned the dev git repo into a different directory. Running it all through tmux to handle the differen shell instances.

I’m not on M1 yet, but I’m expecting to switch very soon, and I really prefer the convenience of the Docker setup.

That PR link links to https://github.com/docker/for-mac/issues/5321 where they say:

the only solution is to switch to arm64-capable multi-arch images. These will also be a lot faster and generally more reliable. I recommend investigating which base images you’re using and to switch to multi-arch ones where possible. You can see which architectures are supported by each image on Docker Hub: […]

To build a multi-arch image yourself, I recommend docker buildx , check out this blog post: https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/

Is the Discourse team open to supporting a multi-arch image? It looks like the Discourse base image is based on debian:buster-slim, which is multi-arch, so it seems like it shouldn’t be outrageously difficult to make the Discourse base image be multi-arch, but that might put y’all in the position of having to support ARM (in production!). Somebody (the Discourse team?) would need to run the Discourse tests on both x86_64 and ARM, fix issues when they fail, etc.

Would a PR even be welcome here?

(IMO, it seems like ARM is the architecture of the future, even on cloud-hosted environments.)

2 Likes

I’m trying to set this up on WSL2.

I’ve got down to starting ember_cli but Chrome give me the following error:

There are no errors visible in either terminal or the development log. Any suggestions welcome, please?

1 Like

this is really helpful

Hi all,

Running into the same issues so I thought I’d raise it as a bug. Please see below.

Backup restore failing on clean dev docker env: FATAL: Peer authentication failed for user “postgres”

Let me know if I can provide more info or be of any help.

Koen

Can’t get this to work openSUSE Leap 15. I suppose that’s not a supported OS, although since we’re using Docker it shouldn’t really matter…

Migrating database...
rake aborted!
Errno::EACCES: Permission denied @ dir_s_mkdir - /src/app/assets/javascripts/plugins
/src/lib/plugin/instance.rb:441:in `ensure_directory'
/src/lib/plugin/instance.rb:713:in `activate!'
lib/discourse.rb:283:in `block in activate_plugins!'
lib/discourse.rb:280:in `each'
lib/discourse.rb:280:in `activate_plugins!'
/src/config/application.rb:318:in `block in <class:Application>'
/src/lib/plugin_initialization_guard.rb:5:in `plugin_initialization_guard'
/src/config/application.rb:317:in `<class:Application>'
/src/config/application.rb:73:in `<module:Discourse>'
/src/config/application.rb:72:in `<main>'
/src/Rakefile:7:in `<main>'
(See full trace by running task with --trace)

Tried to just manually create “app/assets/javascripts/plugins” and that got me to

Migrating database...
rake aborted!
Errno::EACCES: Permission denied @ dir_s_mkdir - /src/tmp
lib/discourse.rb:94:in `atomic_write_file'
/src/lib/plugin/instance.rb:726:in `activate!'
lib/discourse.rb:283:in `block in activate_plugins!'
lib/discourse.rb:280:in `each'
lib/discourse.rb:280:in `activate_plugins!'
/src/config/application.rb:318:in `block in <class:Application>'
/src/lib/plugin_initialization_guard.rb:5:in `plugin_initialization_guard'
/src/config/application.rb:317:in `<class:Application>'
/src/config/application.rb:73:in `<module:Discourse>'
/src/config/application.rb:72:in `<main>'
/src/Rakefile:7:in `<main>'
(See full trace by running task with --trace)

So I’ll mkdir tmp in the source folder…

But then that gets me to here:

Migrating database...
rake aborted!
Errno::EACCES: Permission denied @ rb_sysopen - /src/tmp/5ad4443faf817dc922116f8df65ae5c3
lib/discourse.rb:97:in `initialize'
lib/discourse.rb:97:in `open'
lib/discourse.rb:97:in `atomic_write_file'
/src/lib/plugin/instance.rb:726:in `activate!'
lib/discourse.rb:283:in `block in activate_plugins!'
lib/discourse.rb:280:in `each'
lib/discourse.rb:280:in `activate_plugins!'
/src/config/application.rb:318:in `block in <class:Application>'
/src/lib/plugin_initialization_guard.rb:5:in `plugin_initialization_guard'
/src/config/application.rb:317:in `<class:Application>'
/src/config/application.rb:73:in `<module:Discourse>'
/src/config/application.rb:72:in `<main>'
/src/Rakefile:7:in `<main>'
(See full trace by running task with --trace)

It looks like boot_dev is running docker exec as the discourse user… but the directories are owned by a user 1016 (my host user’s uid).

I imagine a lot of devs don’t run into this problem on their personal laptops where their user has a uid of 1000 and it coincidentally lines up…

1 Like

Yikes d/cleanup is dangerous. That’s a good way to lose a lot of Docker work unrelated to Discourse at all…

I started doing some manual hacks like the following which were working but there kept being more and more permission issues, so I decided to stop trying to put out fires.

mkdir app/assets/javascripts/plugins
mkdir tmp
sudo chown 1000:1000 tmp
sudo chown 1000:1000 app/assets/javascripts/plugins

I’m going to use the host user with a uid of 1000 and I bet that it’s just going to work now, but this really exposes a shortcoming with how Discourse development is done it seems.

…and yep that did the trick.

In the case of that “tmp” that could be in a named or anonymous Docker volume. With the plugins, it could be useful to have that mounted volume but the host file system permissions would need to be altered to support writes.

I don’t think it’s safe to assume that every developer will be using a uid of 1000.

3 Likes

Hi guys, do you know how to run the development using old version discourse ? I know that in live discourse we can set version in app.yml. But I don’t know how to do it in development using docker. I want to run development on last stable version v2.7.10. Thanks for your help

Just checkout that branchor commit in git. (The way that I do it is to google

You’ll need to drop, create, and migrate the database after you downgrade.

Hi thanks @pfaffman ,

I did fresh git pull of discourse and checkout to “stable” version branch. (which is use discourse v2.7.10 tag)

I run dev init and set the admin user email and password

d/boot_dev --init

and run rails server it will listen on port 3000

d/rails s

then run ember-cli

cd app/assets/javascripts/discourse
yarn
yarn run ember serve --proxy "http://localhost:3000"

the discourse development can be open on “http://localhost:4200

however I got issue when login as admin user (the one that I created when run “d/boot_dev --init”)

“Unkown error” pop up showed on screen, with below error on /logs

ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR:  function max(boolean) does not exist
LINE 1: ..._rank, MAX(user_badges.created_at) AS created_at, MAX(user_b...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
)
lib/freedom_patches/ams_include_without_root.rb:49:in `include!'
app/controllers/application_controller.rb:495:in `serialize_data'
app/controllers/application_controller.rb:504:in `render_serialized'
app/controllers/session_controller.rb:611:in `login'
app/controllers/session_controller.rb:337:in `create'
app/controllers/application_controller.rb:395:in `block in with_resolved_locale'
app/controllers/application_controller.rb:395:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/missing_avatars.rb:23:in `call'
lib/middleware/turbo_dev.rb:34:in `call'

Do you have some experience with that error ? or maybe my step on running development on previous version was wrong ?