Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose setup gives: No community record matching Host='localhost:3000' #759

Closed
RobertFloor opened this issue Jan 14, 2022 · 13 comments · Fixed by #762
Closed

Docker compose setup gives: No community record matching Host='localhost:3000' #759

RobertFloor opened this issue Jan 14, 2022 · 13 comments · Fixed by #762
Labels
area: deployment Issues in setting up qpixel, containers, etc. complexity: unassessed Needs further developer investigation before complexity/feasibility can be determined. priority: medium type: bug Something isn't working

Comments

@RobertFloor
Copy link

Describe the bug
First congratulations on this nice project. I wanted to run it locally so I followed using docker-compose procedure in the docker/README.md file to get qpixel running locally. However, I end up with this in the browser: No community record matching Host='localhost:3000'. Probably I am missing a setting but I cannot find the correct place to fix the communities in the docker or variables file.

To Reproduce
Steps to reproduce the behavior:
1 Start with the develop branch and run these commands

$ chmod +x docker/local-setup.sh
$ docker/local-setup.sh
$ docker compose build
$ docker compose up 
  1. In either safari or chrome go to http://localhost:3000 the website it now says
No community record matching Host='localhost:3000'

Expected behavior
I expect the webserver to start and show the webpage as described after step 4 in the readme.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac OS 12.1
  • Browser Safari 15.2

Logs

qpixel-uwsgi-1  | => Booting Puma
qpixel-uwsgi-1  | => Rails 5.2.6 application starting in development
qpixel-uwsgi-1  | => Run `rails server -h` for more startup options
qpixel-uwsgi-1  | Puma starting in single mode...
qpixel-uwsgi-1  | * Version 4.3.10 (ruby 2.6.6-p146), codename: Mysterious Traveller
qpixel-uwsgi-1  | * Min threads: 0, max threads: 16
qpixel-uwsgi-1  | * Environment: development
qpixel-uwsgi-1  | * Listening on tcp://0.0.0.0:3000
qpixel-uwsgi-1  | Use Ctrl-C to stop
qpixel-uwsgi-1  | Started GET "/" for 172.18.0.1 at 2022-01-14 15:26:23 +0000
qpixel-uwsgi-1  |    (1.1ms)  SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
qpixel-db-1     | mbind: Operation not permitted
qpixel-uwsgi-1  |    (1.1ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
qpixel-uwsgi-1  | Processing by CategoriesController#homepage as HTML
qpixel-uwsgi-1  |   Community Load (2.4ms)  SELECT  `communities`.* FROM `communities` WHERE `communities`.`host` = 'localhost:3000' LIMIT 1
qpixel-uwsgi-1  |   Host localhost:3000, community # ()
qpixel-uwsgi-1  |   Rendering text template
qpixel-uwsgi-1  |   Rendered text template (0.1ms)
qpixel-uwsgi-1  | Filter chain halted as :set_globals rendered or redirected
qpixel-uwsgi-1  | Completed 422 Unprocessable Entity in 169ms (Views: 42.5ms | ActiveRecord: 5.3ms)

I do see this error for the database container:

qpixel-db-1     | mbind: Operation not permitted
qpixel-db-1     | mbind: Operation not permitted
qpixel-db-1     | mbind: Operation not permitted

Related issues
I did find this issue with the same problem at the end of the issue but have not found a solution in it: #70

@cellio cellio added area: deployment Issues in setting up qpixel, containers, etc. complexity: unassessed Needs further developer investigation before complexity/feasibility can be determined. priority: medium type: bug Something isn't working labels Jan 14, 2022
@RobertFloor
Copy link
Author

RobertFloor commented Jan 15, 2022

I understand it comes from this part of the application_controller.rb

  def setup_request_context
    RequestContext.clear!

    host_name = request.raw_host_with_port # include port to support multiple localhost instances
    RequestContext.community = @community = Rails.cache.fetch("#{host_name}/community", expires_in: 1.hour) do
      Community.unscoped.find_by(host: host_name)
    end

    Rails.logger.info "  Host #{host_name}, community ##{RequestContext.community_id} " \
                      "(#{RequestContext.community&.name})"
    if RequestContext.community.blank?
      render status: :unprocessable_entity, plain: "No community record matching Host='#{host_name}'"
      return false
    end

    true
  end

I did find a partial solution

# Go into the uwsgi container
$ docker exec -it qpixel-uwsgi-1 bash 
# And start a rails console
$ rails c
# in the rails console run:
Community.create(name: 'Dev Community', host: 'localhost:3000')
Rails.cache.clear

@RobertFloor
Copy link
Author

RobertFloor commented Jan 15, 2022

So this worked I nearly have it working locally, it was indeed the clearing of the cache. The only thing left is making a post, and that step is not yet working for me.... (step 7 of the docker readme) But I am stuck at this screen when I want to create post. I have created a category Q&A with tag set Main and Meta with a tag set Meta.

I tested the VM based approach in the main readme (with vagrant and Ansible ) and became stuck at the same point, I have the site running but cannot create posts.

Schermafbeelding 2022-01-15 om 21 29 17

post_types.html.erb

h1>What kind of post?</h1>
<p class="has-font-size-larger has-color-tertiary-500">
  This category has more than one type of post available. Pick a post type to get started.
</p>

<% @post_types.each do |pt| %>
  <h3><%= link_to pt.name.underscore.humanize, new_category_post_path(post_type: pt, category: @category) %></h3>
  <p class="has-color-tertiary-500"><%= pt.description %></p>
  <hr/>
<% end %>

Related:
https://collab.codidact.org/posts/285521
https://collab.codidact.org/posts/285516
#638 (comment)

@luap42
Copy link
Member

luap42 commented Jan 16, 2022

@RobertFloor just to make sure. Could you show a screenshot of the category config for that category with all settings expanded?

@RobertFloor
Copy link
Author

Thanks for your response
Here you go:

Q&A
Part 1
Schermafbeelding 2022-01-16 om 14 05 07

part 2
Schermafbeelding 2022-01-16 om 14 05 24

Meta
part 1
Schermafbeelding 2022-01-16 om 14 04 29
Part 2
Schermafbeelding 2022-01-16 om 14 04 44

@luap42
Copy link
Member

luap42 commented Jan 16, 2022

Ah I think you'll need to click on the "Edit allowed post types" link and choose which post types you want to allow in that category. (Yes, I know, that's very much not obvious and we should update the instructions accordingly 😬)

@RobertFloor
Copy link
Author

Schermafbeelding 2022-01-16 om 16 08 59

@RobertFloor
Copy link
Author

RobertFloor commented Jan 16, 2022

I think I also found the root cause of the failure of the docker compose error. I believe it is in the file https://github.com/codidact/qpixel/blob/develop/docker/create_admin_and_community.rb. This function needs the variable LOCAL_DEV_PORT but this is not defined in the context of the container, only in the context of the host operating system .

The code in question is

# 1. Create the community
community_name = ENV['COMMUNITY_NAME'] || 'Dinosaur Community'
Community.create(name: community_name, host: "localhost:#{ENV['LOCAL_DEV_PORT']}")
docker exec -it qpixel-uwsgi-1 bash
root@bd4a122c2f6a:/code# rails c
irb(main):001:0> community_name = ENV['COMMUNITY_NAME'] || 'Dinosaur Community'
=> "Dev Community"
irb(main):002:0> Community.create(name: community_name, host: "localhost:#{ENV['LOCAL_DEV_PORT']}")
   (0.3ms)  SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (0.2ms)  BEGIN
  Community Exists (0.4ms)  SELECT  1 AS one FROM `communities` WHERE `communities`.`host` = BINARY 'localhost:' LIMIT 1
   (0.2ms)  ROLLBACK
=> #<Community id: nil, name: "Dev Community", host: "localhost:", created_at: nil, updated_at: nil, is_fake: false, hidden: false>
irb(main):003:0> ENV['LOCAL_DEV_PORT']
=> nil

The variables in the container

root@bd4a122c2f6a:/code# env
HOSTNAME=bd4a122c2f6a
COMMUNITY_ADMIN_PASSWORD=password
RUBY_DOWNLOAD_SHA256=5db187882b7ac34016cd48d7032e197f07e4968f406b0690e20193b9b424841f
RUBY_VERSION=2.6.6
PWD=/code
NODEJS_HOME=/opt/node-v12.18.3-linux-x64/bin
MYSQL_ROOT_PASSWORD=qpixel
BUNDLE_APP_CONFIG=/usr/local/bundle
RUBY_MAJOR=2.6
COMMUNITY_ADMIN_USERNAME=admin
MYSQL_PASSWORD=qpixel
MYSQL_USER=qpixel
HOME=/root
LANG=C.UTF-8
CONFIRMABLE_ALLOWED_ACCESS_DAYS=2
BUNDLE_SILENCE_ROOT_WARNING=1
COMMUNITY_NAME=Dev Community
GEM_HOME=/usr/local/bundle
TERM=xterm
SHLVL=1
MYSQL_DATABASE=qpixel
COMMUNITY_ADMIN_EMAIL=admin@noreply.com
PATH=/opt/node-v12.18.3-linux-x64/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RAILS_ENV=development
RUBYOPT=-KU -E utf-8:utf-8
_=/usr/bin/env

@RobertFloor
Copy link
Author

RobertFloor commented Jan 16, 2022

So it can be fixed by the following 2 fixes
1 Add this to https://github.com/codidact/qpixel/blob/develop/docker/create_admin_and_community.rb
after the community is created
Rails.cache.clear

2 Add LOCAL_DEV_PORT=${LOCAL_DEV_PORT} to docker compsoe
docker-compose file

version: "3.8"
services:
  db:
    build:
      context: "."
      dockerfile: docker/Dockerfile.db
    volumes:
      - ./docker/mysql:/var/lib/mysql
    env_file:
      - ${ENV_FILE_LOCATION}
    command: mysqld --default-authentication-plugin=mysql_native_password --skip-mysqlx

  uwsgi:
    restart: always
    build:
      context: "."
      dockerfile: docker/Dockerfile
    depends_on:
      - db
    environment:
      - COMMUNITY_NAME=${COMMUNITY_NAME}
      - RAILS_ENV=${RAILS_ENV}
      - CONFIRMABLE_ALLOWED_ACCESS_DAYS=${CONFIRMABLE_ALLOWED_ACCESS_DAYS}
      - LOCAL_DEV_PORT=${LOCAL_DEV_PORT}
    env_file:
      - ${ENV_FILE_LOCATION}
    ports:
      - "${LOCAL_DEV_PORT}:3000"
    volumes:
      - .:/code
      - ./static:/var/www/static
      - ./images:/var/www/images
    links:
      - redis
      - db

  redis:
    restart: always
    image: redis:latest
    depends_on:
      - db

@RobertFloor
Copy link
Author

Created a pull request to fix this issue

@RobertFloor
Copy link
Author

Thanks for the help so far. It goes much better now. There remains one problem. I can start the site, create categories, log in as admin user and make posts. However when I create a post it does not show up on the home page

Example post
Schermafbeelding 2022-01-20 om 11 33 20

I can see the post under my name
Schermafbeelding 2022-01-20 om 11 35 52

But no posts here: Categories

Schermafbeelding 2022-01-20 om 11 35 35

@luap42
Copy link
Member

luap42 commented Jan 20, 2022

@RobertFloor when you click on "Edit Category", which post types are selected under "Posting" > "Listed post types"? (for expected results, there should probably be Question and Article selected)

@RobertFloor
Copy link
Author

Thanks that made a change :) This posts are visible now

So the only problem is I only have these categories, no questions

Blank
Answer
PolicyDoc
HelpDo
Article

@Trilarion
Copy link
Contributor

Definitely related to #638 and https://collab.codidact.org/posts/285521

I saw the same behavior. The question post type does not seem to be seeded correctly in the database and the seed script silently continues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: deployment Issues in setting up qpixel, containers, etc. complexity: unassessed Needs further developer investigation before complexity/feasibility can be determined. priority: medium type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants