Install Discourse for development using Docker

Anyone here using Fedora? This adds some more complexity, because Podman and SELinux are used for enhanced security. Podman is not really an issue I hope, it’s OCI compliant and having podman-docker installed, all Docker commands are translated to Podman commands. For SELinux I think I’ve found the proper fix as well, but still I run into an issue.

So while in the discourse directory, I run this command mkdir -vp data/postgres; sudo semanage fcontext -a -t svirt_sandbox_file_t "/home/user/discourse/data(/.*)?" && restorecon -rv . to apply an SELinux context label that I think is sufficient for this (at least, the SELinux errors are gone)

But I then still run into this error:

[user@fedora discourse]$ d/boot_dev --init
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: template: info:1:2: executing "info" at <.Architecture>: can't evaluate field Architecture in type *define.Info
WARNING: Docker architecture is not x86_64.
Discourse development is unlikely to work using Docker's architecture emulation.
Please try a native development installation.
Using source in: /home/user/discourse
Using data in:   /home/user/discourse/data/postgres
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
✔ docker.io/discourse/discourse_dev:release
Trying to pull docker.io/discourse/discourse_dev:release...
Getting image source signatures
Copying blob b42e9bacf67a done  
Copying blob 3257b89dc3e0 done  
Copying blob 8f87c7014fb0 done  
Copying blob bf00c24d0f5b done  
Copying blob 10e0cd28eb63 done  
Copying blob 1efc276f4ff9 done  
Copying blob 6d9350d0e59c done  
Copying blob 84ee3423e706 done  
Copying blob ee2701209d47 done  
Copying blob ce48a2c1c5d3 done  
Copying blob 2f702c3c2f9f done  
Copying blob 27762615d0fc done  
Copying blob 7056a5796a1a done  
Copying blob c8a22dd30e4c done  
Copying blob 1a93cd2f0c23 done  
Copying config 6365e737b9 done  
Writing manifest to image destination
Storing signatures
6365e737b90aea36af1fd9ed029db43a0a620f1c285416546f5e6ee728aca4c5
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7
Installing gems...
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Could not locate Gemfile

The systemd journal reports this:

Aug 09 18:47:45 fedora podman[19380]: 2022-08-09 18:47:45.841001786 +0200 CEST m=+0.137712533 image pull  discourse/discourse_dev:release
Aug 09 18:47:45 fedora podman[19380]: 
Aug 09 18:47:46 fedora podman[19380]: 2022-08-09 18:47:46.043506861 +0200 CEST m=+0.340217585 container create 5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7 (image=docker.io/discourse/discourse_dev:release, name=discourse_dev)
Aug 09 18:47:46 fedora kernel: tun: Universal TUN/TAP device driver, 1.6
Aug 09 18:47:46 fedora systemd[1684]: selinux: avc:  op=load_policy lsm=selinux seqno=7 res=1
Aug 09 18:47:46 fedora systemd[1684]: selinux: Regex version mismatch, expected: 10.39 2021-10-29 actual: 10.40 2022-04-14
Aug 09 18:47:46 fedora systemd[1684]: selinux: Regex version mismatch, expected: 10.39 2021-10-29 actual: 10.40 2022-04-14
Aug 09 18:47:46 fedora systemd[1684]: selinux: Regex version mismatch, expected: 10.39 2021-10-29 actual: 10.40 2022-04-14
Aug 09 18:47:46 fedora systemd[1684]: Started libpod-conmon-5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7.scope.
Aug 09 18:47:46 fedora systemd[1684]: Started libpod-5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7.scope - libcrun container.
Aug 09 18:47:46 fedora chronyd[792]: Selected source 158.101.221.122 (2.fedora.pool.ntp.org)
Aug 09 18:47:46 fedora podman[19380]: 2022-08-09 18:47:46.370028125 +0200 CEST m=+0.666738859 container init 5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7 (image=docker.io/discourse/discourse_dev:release, name=discourse_dev)
Aug 09 18:47:46 fedora podman[19380]: 2022-08-09 18:47:46.433863112 +0200 CEST m=+0.730573845 container start 5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7 (image=docker.io/discourse/discourse_dev:release, name=discourse_dev)
Aug 09 18:47:46 fedora discourse_dev[19420]: run-parts: executing /etc/runit/1.d/00-fix-var-logs
Aug 09 18:47:46 fedora discourse_dev[19420]: run-parts: executing /etc/runit/1.d/anacron
Aug 09 18:47:46 fedora discourse_dev[19420]: run-parts: executing /etc/runit/1.d/cleanup-pids
Aug 09 18:47:46 fedora discourse_dev[19420]: Cleaning stale PID files
Aug 09 18:47:46 fedora discourse_dev[19420]: run-parts: executing /etc/runit/1.d/ensure-database
Aug 09 18:47:47 fedora podman[19425]: 2022-08-09 18:47:47.698175757 +0200 CEST m=+1.211177315 container exec 5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7 (image=docker.io/discourse/discourse_dev:release, name=discourse_dev)
Aug 09 18:47:48 fedora discourse_dev[19420]: Started runsvdir, PID is 29
Aug 09 18:47:48 fedora podman[19425]: 2022-08-09 18:47:48.535303673 +0200 CEST m=+2.048305123 container exec_died 5282393e248e33800e235b4405c9a7197d10a3fc1d405450f1c99d2a5c7c85c7 (image=docker.io/discourse/discourse_dev:release, name=discourse_dev, execID=166d86f7ca8739899bd59801c2f8bb3d9b940329d8e6bb29d0f45ad82e9d60b0)

The log dir in the discourse directory is empty, how could I troubleshoot this better?

The paths seem to set correctly to find the Gem file.

[user@fedora discourse]$ SCRIPTPATH=$(cd "$(dirname "$0")" > /dev/null; pwd -P)
[user@fedora discourse]$ echo $SCRIPTPATH 
/home/user/discourse

I had some success ages ago with a virtual Fedora Dev environment from scratch but couldn’t get a production setup to work. I also asked the Podman Q which someone kindly responded to say it was possible but lots of stuff to change which he didn’t have time to do . .

I would love to get Dev and Prod Fedora versions going . .

1 Like

I don’t get this question. It aborts with this:

rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /src/app/assets/javascripts/node_modules/xss/dist/xss.min.js
/src/lib/pretty_text.rb:613:in `block in ctx_load'
/src/lib/pretty_text.rb:612:in `each'
/src/lib/pretty_text.rb:612:in `ctx_load'
/src/lib/pretty_text.rb:108:in `create_es6_context'
/src/lib/pretty_text.rb:153:in `block in v8'
/src/lib/pretty_text.rb:151:in `synchronize'
/src/lib/pretty_text.rb:151:in `v8'
/src/lib/pretty_text.rb:190:in `block in markdown'
/src/lib/pretty_text.rb:606:in `block in protect'
/src/lib/pretty_text.rb:605:in `synchronize'
/src/lib/pretty_text.rb:605:in `protect'
/src/lib/pretty_text.rb:189:in `markdown'
/src/lib/pretty_text.rb:318:in `cook'
/src/app/models/user_profile.rb:149:in `cooked'
/src/app/models/user_profile.rb:158:in `cook'
(eval):51:in `block (2 levels) in run_file'
/src/lib/tasks/db.rake:234:in `block (2 levels) in <main>'
/src/lib/distributed_mutex.rb:57:in `block in synchronize'
/src/lib/distributed_mutex.rb:53:in `synchronize'
/src/lib/distributed_mutex.rb:53:in `synchronize'
/src/lib/distributed_mutex.rb:38:in `synchronize'
/src/lib/tasks/db.rake:214:in `block in <main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I would like to use Ubuntu, but for some reason it doesn’t work well with the spice-vdagent, many graphic errors when running the VM. Fedora works smooth as butter… I thought containers fixed portability :stuck_out_tongue: I guess I’ll just setup a headless Ubuntu system and login via SSH.


I get the same error in Ubuntu Server 22.04

I have this issue too. Followed and double checked the suggestions from @tarek. The issue keeps returning. Also cleaned up the entire discourse directory and started from scratch. Using Ubuntu 22.04.01 in a VM and using the latest Docker available for Ubuntu.

1 Like

As of the current git master, this will not complete successfully. I believe it’s a bug in core. To get a dev environment up and running, do the following after the error:

d/rake db:migrate
d/rake admin:create
d/rails s

plus in the next two terminals, d/ember-cli and d/mailhog.

2 Likes

Any idea about how I can stop d/rails s from showing all of the query output? It makes it much harder to use byebug and such to figure out where bugs are for me.

1 Like

Try: DISCOURSE_DEV_LOG_LEVEL=info bin/rails s

More tips here: Debugging Ruby with Byebug - Development - Discourse Plugin Manager

6 Likes

Hello,

I’m trying to run this on Ubuntu on stable (v2.8.8), and I’m getting the following errors:

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>'

Caused by:
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>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I’ve tried to do:

d/rake db:migrate RAILS_ENV=development

But I end up with the same error. Has anyone gone through this as well?

Got a suspicion you are using the same database as you did before, so it’s already migrated?

Actually @hyphalos I take that back, I can repro this with the following shell commands inside the container:

discourse@discourse:/src$ sudo su postgres -c 'psql discourse -c "drop database discourse_test"'
DROP DATABASE
discourse@discourse:/src$ sudo su postgres -c 'psql discourse -c "create database discourse_test"'
CREATE DATABASE
discourse@discourse:/src$ sudo su postgres -c 'psql -c "grant all privileges on database discourse_test to discourse;"'
GRANT
discourse@discourse:/src$ RAILS_ENV=test rake db:migrate

Something not right here?

Seems like this migration can be problematic?:

== 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 exist

which is weird (?) because:

discourse_test=> \d bookmarks
                                                Table "public.bookmarks"
         Column         |              Type              | Collation | Nullable |                Default
------------------------+--------------------------------+-----------+----------+---------------------------------------
 id                     | bigint                         |           | not null | nextval('bookmarks_id_seq'::regclass)
 user_id                | bigint                         |           | not null |
 post_id                | bigint                         |           | not null |
 name                   | character varying(100)         |           |          |
 reminder_at            | timestamp without time zone    |           |          |
 created_at             | timestamp(6) without time zone |           | not null |
 updated_at             | timestamp(6) without time zone |           | not null |
 reminder_last_sent_at  | timestamp without time zone    |           |          |
 reminder_set_at        | timestamp without time zone    |           |          |
 auto_delete_preference | integer                        |           | not null | 0
 pinned                 | boolean                        |           |          | false
 for_topic              | boolean                        |           | not null | false
Indexes:
    "bookmarks_pkey" PRIMARY KEY, btree (id)
    "index_bookmarks_on_post_id" btree (post_id)
    "index_bookmarks_on_reminder_at" btree (reminder_at)
    "index_bookmarks_on_reminder_set_at" btree (reminder_set_at)
    "index_bookmarks_on_user_id" btree (user_id)
    "index_bookmarks_on_user_id_and_post_id_and_for_topic" UNIQUE, btree (user_id, post_id, for_topic)

This doesn’t afflict tests-passed it seems, only stable branch?

thanks to @RGJ this might shed some light:

cc: @pfaffman

1 Like

Hey @Robert,

I thought I was going crazy, I thought I was the only one experiencing this. I’ve struggled to find a work around for this. I have an earlier post here where I found a workaround for the bookmark issue, but ran into another issue:

Can someone point me in the right direction to fix this?
This occurs when I try to run d/boot_dev --init

rake aborted!
ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
connection to server at "::1", port 5432 failed: Cannot assign requested address
        Is the server running on that host and accepting TCP/IP connections?
/src/config/initializers/006-ensure_login_hint.rb:8:in `block in <main>'
/src/config/environment.rb:7:in `<main>'

Caused by:
PG::ConnectionBad: connection to server at "127.0.0.1", port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
connection to server at "::1", port 5432 failed: Cannot assign requested address
        Is the server running on that host and accepting TCP/IP connections?
/src/config/initializers/006-ensure_login_hint.rb:8: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)

Thanks for any/all help in advance :smile:

1 Like

I am getting the following error when running d/boot_dev --init

...
...
...
== 20221219082223 AddIndexToChatMessages: migrated (0.0138s) ==================

rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /src/app/assets/javascripts//node_modules/loader.js/dist/loader/loader.js
/src/lib/pretty_text.rb:637:in `block in ctx_load'
/src/lib/pretty_text.rb:636:in `each'
/src/lib/pretty_text.rb:636:in `ctx_load'
/src/lib/pretty_text.rb:97:in `create_es6_context'
/src/lib/pretty_text.rb:144:in `block in v8'
/src/lib/pretty_text.rb:142:in `synchronize'
/src/lib/pretty_text.rb:142:in `v8'
/src/lib/pretty_text.rb:184:in `block in markdown'
/src/lib/pretty_text.rb:630:in `block in protect'
/src/lib/pretty_text.rb:629:in `synchronize'
/src/lib/pretty_text.rb:629:in `protect'
/src/lib/pretty_text.rb:183:in `markdown'
/src/lib/pretty_text.rb:328:in `cook'
/src/app/models/user_profile.rb:149:in `cooked'
/src/app/models/user_profile.rb:158:in `cook'
(eval):51:in `block (2 levels) in run_file'
/src/lib/tasks/db.rake:234:in `block (2 levels) in <main>'
/src/lib/distributed_mutex.rb:57:in `block in synchronize'
/src/lib/distributed_mutex.rb:53:in `synchronize'
/src/lib/distributed_mutex.rb:53:in `synchronize'
/src/lib/distributed_mutex.rb:38:in `synchronize'
/src/lib/tasks/db.rake:214:in `block in <main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I’ve tried this on two machines now and both are failing with a permissions error.

pfaffman@shinytim:~/src/discourse-repos/discourse$ d/bundle install
Bundler 2.4.2 is running, but your lockfile was generated with 2.4.1. Installing Bundler 2.4.1 and restarting using that version.
Fetching gem metadata from https://rubygems.org/.
Fetching bundler 2.4.1

Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.1.0/cache/bundler-2.4.1.gem`. It is likely that you need to grant write permissions for that path.

Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.1.0/cache/bundler-2.4.1.gem`. It is likely that you need to grant write permissions for that path.

Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.1.0/cache/bundler-2.4.1.gem`. It is likely that you need to grant write permissions for that path.

There was an error installing the locked bundler version (2.4.1), rerun with the `--verbose` flag for more details. Going on using bundler 2.4.2.
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/discourse/mail.git
There was an error while trying to write to `/usr/local/lib/ruby/gems/3.1.0/cache/bundler/git`.
It is likely that you need to grant write permissions for that path.
1 Like

I met this problem too.

1 Like

Any updates on this?

Hello there,

I’m total new and noob. I try configure Discourse on dev Ubuntu 22.04 before ploy into GitHub and than server (no idea how but now it doesn’t matter)

I tried to install Dicourse locally using docker (using this tutorial).

I think i correctly intalled docker, but when i type:

sudo d/rails s

I get “GitHub - discourse/mail: A Really Ruby Mail Library is not yet checked out. Run bundle install first.”

and when i run

sudo d/bundle install

I get:
“Fetching GitHub - discourse/mail: A Really Ruby Mail Library
There was an error while trying to write to
/usr/local/lib/ruby/gems/3.1.0/cache/bundler/git. It is likely that you need
to grant write permissions for that path.”

Please advice :slight_smile:

Created a pull request to fix this - Setting bundler version to 2.4.1 which is same as version that generated lockfile to avoid failing script by nkirit · Pull Request #665 · discourse/discourse_docker · GitHub

1 Like

Thanks for the reports - this should be fixed by this commit

The build is running and so a new discourse_dev:release image should be pushed within the next hour. After that you’ll need to d/shutdown_dev and d/boot_dev to pick up the changes.

4 Likes

How do you set/give this container a specific static ip address?