развернуть производственное приложение Rails с ActionCable на puma и nginx от docker - PullRequest
0 голосов
/ 22 сентября 2019

Я новичок в использовании ActionCable.

Я пытался собрать приложение rails с помощью docker с помощью actioncable, и websocket не работал.

журнал от redis:

redis_1  | 1:C 22 Sep 2019 09:13:09.229 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 22 Sep 2019 09:13:09.230 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 22 Sep 2019 09:13:09.230 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 22 Sep 2019 09:13:09.243 * Running mode=standalone, port=6379.
redis_1  | 1:M 22 Sep 2019 09:13:09.243 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 22 Sep 2019 09:13:09.243 # Server initialized
redis_1  | 1:M 22 Sep 2019 09:13:09.244 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1  | 1:M 22 Sep 2019 09:13:09.263 * DB loaded from disk: 0.019 seconds
redis_1  | 1:M 22 Sep 2019 09:13:09.263 * Ready to accept connections

журнал от пумы:

app_1    | [17630110-7b5b-43c6-b47a-076f8e4f1357] Started GET "/cable" for 127.0.0.1 at 2019-09-22 09:13:55 +0000
app_1    | [17630110-7b5b-43c6-b47a-076f8e4f1357] Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-09-22 09:13:55 +0000
app_1    | [17630110-7b5b-43c6-b47a-076f8e4f1357] Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
app_1    | #<Thread:0x0000558743086bf8@/usr/local/bundle/gems/actioncable-5.0.6/lib/action_cable/subscription_adapter/redis.rb:142 run> terminated with exception (report_on_exception is true):
app_1    | /usr/local/lib/ruby/2.6.0/socket.rb:1213:in `__connect_nonblock': Cannot assign requested address - connect(2) for [::1]:6379 (Errno::EADDRNOTAVAIL)

docker-compose.yml:

version: '3'

services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data

  redis:
    image: redis:alpine

    volumes:
      - ./data/redis:/data

  app:
    image: myDockerHub/harem_backend
    build:
      context: .
      dockerfile: ./docker/app/Dockerfile
    volumes:
      - ./tmp/sockets:/app/tmp/sockets
    depends_on:
      - db
      - redis

  nginx:
    image: myDockerHub/harem_backend_nginx
    build:
      context: .
      dockerfile: ./docker/nginx/Dockerfile
    ports:
      - "80:80"
    volumes:
      - ./tmp/sockets:/app/tmp/sockets
    depends_on:
      - app

config / cable.yml:

development:
  adapter: async

test:
  adapter: async

production:
  adapter: redis
  url: redis://localhost:6379/1

config / environment / production.rb:

config.eager_load = true
config.action_cable.mount_path = '/cable'
config.action_cable.url = "ws://localhost/cable"

nginx.default.conf:

server {
  listen       80;
  server_name  localhost;

  location / {
    proxy_pass http://unix:/app/tmp/sockets/puma.sock;
    proxy_set_header X-Forwarded-Host localhost;
  }

  location /cable {
   proxy_pass http://unix:/app/tmp/sockets/puma.sock;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
  }
}

puma.rb

bind "unix:///app/tmp/sockets/puma.sock"

при использовании docker-compose up --build все в порядке, но когда я перезагружаю страницу, журнал, приведенный выше, позволит контейнеру app_1 сломаться, как

myapp_app_1 exited with code 1

Как я могу это исправить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...