Postgres error when running import_scripts/mbox.rb in Docker


(Jacob Bandes-Storch) #1

I’m attempting to set up a minimal Discourse instance to test how well import_scripts/mbox.rb works for importing Mailman data.

I performed the following steps (the host machine is macOS 10.12):

  1. cloned the discourse_docker repo

  2. copied samples/standalone.yml to containers/my-test.yml and modified the volumes to point to the right places; changed the SMTP server to localhost to avoid errors, although emails won’t actually work.

  3. ran ./launcher bootstrap my-test and ./launcher start my-test.

  4. created my account via the web UI.

  5. ran ./launcher enter my-test. Now inside the container…

  6. ran rails c, and using User.find_by_username, called activate and save on the user object (since I didn’t have an email server configured to do the verification)

  7. put a .mbox file from mailman in shared/standalone/import/messages/foo.mbox.

  8. in order to make the mbox importer work, ran apt-get install libsqlite3-dev, modified Gemfile and Gemfile.lock to point at the sqlite3 gem, and ran bundle install to install it.

  9. Finally, per instructions from this thread, ran the following:

export LIST_NAME=my-list
export DEFAULT_TRUST_LEVEL=1
export DATA_DIR=/shared/import
export SPLIT_AT="^From " # or "^From (.*)"
bundle exec ruby script/import_scripts/mbox.rb
```


However, I get the following errors:

    URGENT: FATAL:  Peer authentication failed for user "discourse"
     Failed to initialize site default
    /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize': FATAL:  Peer authentication failed for user "discourse" (PG::ConnectionBad)
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
    	from /usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
    	from /usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_handling.rb:87:in `connection'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attributes.rb:93:in `columns'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attributes.rb:98:in `columns_hash'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/core.rb:173:in `block in find_by'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/core.rb:173:in `each'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/core.rb:173:in `all?'
    	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/core.rb:173:in `find_by'
    	from /var/www/discourse/lib/discourse.rb:302:in `system_user'
    	from /var/www/discourse/script/import_scripts/base.rb:492:in `<class:Base>'
    	from /var/www/discourse/script/import_scripts/base.rb:20:in `<top (required)>'
    	from script/import_scripts/mbox.rb:2:in `require'
    	from script/import_scripts/mbox.rb:2:in `<main>'

Am I doing something wrong? How can I resolve this and make the script work?

(Gerhard Schlager) #2

You need to run the ruby script and bundler as user discourse. Try this:

# install gems after editing the Gemfile (BTW: there's no need to edit the Gemfile.lock)
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'

# run the import script
su discourse -c 'bundle exec ruby script/import_scripts/mbox.rb'