Install Discourse for development using Docker

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 ?

I think you need to rm -r the database. I’m not sure where it is, but it’s likely in the OP.

1 Like

Hi all,

Went fully clean slate again. All goes well, get a pristine development environment that I can log into.

Then I am getting a couple of plugins in to match my production environment and pull the most recent backup.

Upload it, try to restore it to the development environment and I get the Peer authentication error again. Have filed a bug, but so far there is no response. Can anyone try to reproduce? I’ve seen similar issues further op the comments to this post, so I figure I am not alone on this one?

[2021-11-29 19:43:39] 'koen' has started the restore!
[2021-11-29 19:43:39] Marking restore as running...
[2021-11-29 19:43:39] Making sure /src/tmp/restores/default/2021-11-29-194339 exists...
[2021-11-29 19:43:39] Copying archive to tmp directory...
[2021-11-29 19:43:39] Extracting dump file...
[2021-11-29 19:43:40] Validating metadata...
[2021-11-29 19:43:40]   Current version: 20211124161346
[2021-11-29 19:43:40]   Restored version: 20211123033311
[2021-11-29 19:43:40] Enabling readonly mode...
[2021-11-29 19:43:40] Pausing sidekiq...
[2021-11-29 19:43:40] Waiting up to 60 seconds for Sidekiq to finish running jobs...
[2021-11-29 19:43:46] Creating missing functions in the discourse_functions schema...
[2021-11-29 19:43:46] Restoring dump file... (this may take a while)
[2021-11-29 19:43:47] psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"
[2021-11-29 19:43:47] EXCEPTION: psql failed: psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"

[2021-11-29 19:43:47] /src/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/src/lib/backup_restore/database_restorer.rb:26:in `restore'
/src/lib/backup_restore/restorer.rb:51:in `run'
/src/script/spawn_backup_restore.rb:23:in `restore'
/src/script/spawn_backup_restore.rb:36:in `block in <main>'
/src/script/spawn_backup_restore.rb:4:in `fork'
/src/script/spawn_backup_restore.rb:4:in `<main>'
[2021-11-29 19:43:47] Trying to rollback...
[2021-11-29 19:43:47] There was no need to rollback
[2021-11-29 19:43:47] Cleaning stuff up...
[2021-11-29 19:43:47] Dropping functions from the discourse_functions schema...
[2021-11-29 19:43:47] Removing tmp '/src/tmp/restores/default/2021-11-29-194339' directory...
[2021-11-29 19:43:47] Unpausing sidekiq...
[2021-11-29 19:43:47] Marking restore as finished...
[2021-11-29 19:43:47] Notifying 'koen' of the end of the restore...
[2021-11-29 19:43:51] Finished!

Hello,

I am having an issue that seems to stem from the schism between ports 3000 and 4200. I am not entirely sure how they related to each other, but my understanding is that 3000 is the server and 4200 a proxy to it from ember CLI. Port 4200 works well, except that sometimes, and specifically when responding with a 302, response headers have URIs that use port 3000 instead of 4200. I was specifically trying to get OAuth2 working with a custom provider as described here, and the presence of port 3000 in some of the responses breaks the OAuth2 workflow. There is no port 3000 in any of my OAuth2 configuration, it must be coming internally from the server.

Has anybody encountered this kind of issue before? Do you know how to set up an environment that mimics the production release more closely?

For what it’s worth, I also tried setting up the production release locally, but that requires a full-blown domain and email registration and doesn’t seem very friendly of local environments.

Thank you.

1 Like

Update, tried again to take the clean-slate route and this time using another machine. Now I get stuck because I do not have the UID 1000 which has been mentioned further up this thread, post 100 by @dcook. I would agree that assuming the UID=1000 is wrong and would constitute bug. Did you report it as such?

On my main machine the Postgress user permission bug persists which I did raise here: Backup restore failing on clean dev docker env: FATAL: Peer authentication failed for user “postgres”.

@rishabh what is your view on both these items? I loved switching over to the docker based method, quick and clean. But now on two different machines it feels a bit like a dead-end street and I am wondering what else I can contribute to get it resolved. Also wondering a bit on the lifecycle of bugs. Do they get received, reviewed, rejected or accepted, parked, resolved etc.?

I’ll for now go and try to set up the native dev environment see if I can get that working.

2 Likes

hello. this is my first time installing discourse using docker in mac.

first, i am sorry about my english … :sob:

I have already run

d/boot_dev --init

then I got error that port:3000 is already used. so I change port 30030:3000 (file : bin/docker/boot_dev)

after that, I start this code


d/boot_dev --init

# In one terminal:
d/rails s

# And in a separate terminal
d/ember-cli

my question is

  1. when I running d/rails s code. I can open discourse starting page on ‘localhost:30030’ . If I just want to open discourse and using 30030port (port forwarding), then Can I finish the install process?? I don’t know what is d/rails s, d/ember-cli. …

  2. and d/rail s process is sooo long. I am worried about what is wrong… is it right? or d/rails s and d/ember-cli is backgroud process while hosing discourse?

thank you. :bowing_man:

Hi,

In dev environment, is it possible to edit config settings that should be placed in app.yml?

The question is mainly about editing DISCOURSE_ENABLE_CORS; simply adding cors origins in the admin interface did not help solve the cors error.

Thank you.

It seems that creating a discourse.conf file under /config solved the issue:
enable_cors = true

Info taken from the default config file: discourse/discourse_defaults.conf at main · discourse/discourse · GitHub

2 Likes

Hi guys, I got issue when init discourse development using docker.

My production discourse using v2.8.0 tag version. so I need to run local development using v2.8.0

I use docker that running on Mac OS for my development setup.
what I did in command is

git clone https://github.com/discourse/discourse.git
cd discourse
git checkout v2.8.0
d/boot_dev --init

I got this error after the init code reach migrating database section

Migrating database...
== 20220104053343 AddBookmarkPolymorphicColumns: migrating ====================
-- add_column(:bookmarks, :bookmarkable_id, :integer)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateColumn: ERROR:  column "bookmarkable_id" of relation "bookmarks" already exists
/src/lib/migration/safe_migrate.rb:92:in `async_exec'
/src/db/migrate/20220104053343_add_bookmark_polymorphic_columns.rb:5:in `change'
/src/lib/freedom_patches/schema_migration_details.rb:9:in `block in exec_migration'
/src/lib/freedom_patches/schema_migration_details.rb:8:in `exec_migration'
/src/lib/migration/safe_migrate.rb:28:in `migrate'
/src/lib/migration/safe_migrate.rb:55:in `migrate'
/src/lib/tasks/db.rake:218:in `block (2 levels) in <main>'
/src/lib/distributed_mutex.rb:33:in `block in synchronize'
/src/lib/distributed_mutex.rb:29:in `synchronize'
/src/lib/distributed_mutex.rb:29:in `synchronize'
/src/lib/distributed_mutex.rb:14:in `synchronize'
/src/lib/tasks/db.rake:210:in `block in <main>'

Caused by:
ActiveRecord::StatementInvalid: PG::DuplicateColumn: ERROR:  column "bookmarkable_id" of relation "bookmarks" already exists
/src/lib/migration/safe_migrate.rb:92:in `async_exec'
/src/db/migrate/20220104053343_add_bookmark_polymorphic_columns.rb:5:in `change'
/src/lib/freedom_patches/schema_migration_details.rb:9:in `block in exec_migration'
/src/lib/freedom_patches/schema_migration_details.rb:8:in `exec_migration'
/src/lib/migration/safe_migrate.rb:28:in `migrate'
/src/lib/migration/safe_migrate.rb:55:in `migrate'
/src/lib/tasks/db.rake:218:in `block (2 levels) in <main>'
/src/lib/distributed_mutex.rb:33:in `block in synchronize'
/src/lib/distributed_mutex.rb:29:in `synchronize'
/src/lib/distributed_mutex.rb:29:in `synchronize'
/src/lib/distributed_mutex.rb:14:in `synchronize'
/src/lib/tasks/db.rake:210:in `block in <main>'

2 months ago I ran development using version 2.8.0 and i got no issue, but couple days ago I was starting got this issue.

do you guys have same problem ?

If you migrated the database with a later version of Discourse then you’ll need to drop and create a new database to get the older migration.

1 Like

I did new fresh clone and init development using version 2.8.0. there should be no data yet.

1 Like

I messed up during the installation, can I know if there’s any possible way to uninstall everything and then redo it from the beginning?

Hello, I found this error weird. Is there anyone who had experience solving this issue? Thanks in advance!

It shows up when I was running d/boot_dev --init.

Migrating database...
rake aborted!
LoadError: cannot load such file -- /usr/local/lib/ruby/gems/2.7.0/gems/mail-2.8.0.rc1/lib/mail/indifferent_hash.rb
/src/lib/email.rb:3:in `<main>'
/src/app/jobs/scheduled/poll_mailbox.rb:10:in `<class:PollMailbox>'
/src/app/jobs/scheduled/poll_mailbox.rb:6:in `<module:Jobs>'
/src/app/jobs/scheduled/poll_mailbox.rb:5:in `<main>'
/src/config/initializers/100-sidekiq.rb:74:in `block (2 levels) in <main>'
/src/config/initializers/100-sidekiq.rb:73:in `glob'
/src/config/initializers/100-sidekiq.rb:73:in `block in <main>'
/src/config/environment.rb:7:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
1 Like

I have got the same error message while doing d/boot_dev --init, tried d/rake db:migrate RAILS_ENV=development, same error again:

rake aborted!
LoadError: cannot load such file -- /usr/local/lib/ruby/gems/2.7.0/gems/mail-2.8.0.rc1/lib/mail/indifferent_hash.rb
/src/lib/email.rb:3:in `<main>'
/src/app/jobs/scheduled/poll_mailbox.rb:10:in `<class:PollMailbox>'
/src/app/jobs/scheduled/poll_mailbox.rb:6:in `<module:Jobs>'
/src/app/jobs/scheduled/poll_mailbox.rb:5:in `<main>'
/src/config/initializers/100-sidekiq.rb:74:in `block (2 levels) in <main>'
/src/config/initializers/100-sidekiq.rb:73:in `glob'
/src/config/initializers/100-sidekiq.rb:73:in `block in <main>'
/src/config/environment.rb:7:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)

I met this problem too. And I fixed it by reverting this commit

2 Likes

Works perfectly for me. Thanks.