如何设置任何电缆与码头(ruby-on-rails)?

s3fp2yjn  于 2023-02-26  发布在  Ruby
关注(0)|答案(2)|浏览(133)

我如何在Docker上设置任意电缆(动作电缆)端口?
这是我的Dockerfile为anycable
来自ruby:2.6.3-alpine3.10
工作目录/主页/应用程序
副本/主页/应用程序/
暴露50051
CMD [“任何电缆”]
这是我的 composer

version: "3"
services:
  app:
    build:
      context: .
      dockerfile: ./dockers/app/Dockerfile
    container_name: out_app
    restart: unless-stopped
    volumes:
      - .:/app
      - /app/node_modules
      - /app/public/assets
      - /app/public/packs
    ports:
      - 3000:3000
  db:
    build:
      context: .
      dockerfile: ./dockers/postgis/Dockerfile
    container_name: out_db
    environment:
      POSTGRES_USER: ${DOCKER_DB_USER}
      POSTGRES_PASSWORD: ${DOCKER_DB_PASSWORD}
      POSTGRES_DB: ${DOCKER_DB_NAME}
    volumes:
      - /docker_data/giggle/postgres:/var/lib/postgresql/data
    ports:
      - 5435:5432
  nginx:
    build:
      context: .
      dockerfile: ./dockers/web/Dockerfile
    container_name: out_web
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
    depends_on:
      - app
    volumes:
      - ./dockers/web/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
  certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
  redis:
    image: redis
    volumes:
      - ../../tmp/db:/var/lib/redis/data
  delayed_job:
    build:
      context: .
      dockerfile: ./dockers/delayed_job/Dockerfile
    container_name: out_delayed_job
    command: bundle exec rails jobs:work
    depends_on:
      - db
    volumes:
      - .:/app
  # anycable:
  #   image: 'anycable/anycable-go:edge-mrb'
  #   ports:
  #     - "3334"
  #   environment:
  #     ANYCABLE_HOST: 0.0.0.0
  #     REDIS_URL: redis://redis:6379/1
  #     ANYCABLE_RPC_HOST: 0.0.0.0:3334
  #     ANYCABLE_DEBUG: 1
  #   command: bundle exec anycable
  anycable:
    build:
      context: .
      dockerfile: ./dockers/anycable/Dockerfile
    container_name: anycable
    command: bundle exec anycable
    depends_on:
      - redis
wn9m85ua

wn9m85ua1#

您提供了任何cable-go配置。若要为任何cable-go服务器设置自定义端口,请将ANYCABLE_PORT: <your port>添加到任何cable-go映像环境中,或显示类似ports: ['<your_port>:8080']的映像端口。
检查任何电缆配置页面(包含env变量信息):https://docs.anycable.io/#/anycable-go/configuration

xyhw6mcr

xyhw6mcr2#

您需要通过将anycable-rails gem添加到您的gem文件来设置anycable-rails:

gem "anycable-rails", "~> 1.1"

使用Redis广播适配器时

gem "redis", ">= 4.0"

(and不要忘记运行捆绑安装)。
然后,通过Rails生成器运行交互式配置向导:

bundle exec rails g anycable:setup

配置接下来,更新Action Cable配置:

# config/cable.yml
production:
  # Set adapter to any_cable to activate AnyCable
  adapter: any_cable

安装WebSocket服务器并在配置中指定其URL:

对于开发,可能是本地主机

# config/environments/development.rb
config.action_cable.url = "ws://localhost:8080/cable"

对于生产环境,它可能有一个子域和安全连接

# config/environments/production.rb
config.action_cable.url = "wss://ws.example.com/cable"

现在您可以为您的应用程序启动AnyCable RPC服务器:

$ bundle exec anycable
#> Starting AnyCable gRPC server (pid: 48111)
#> Serving Rails application from ./config/environment.rb

不要忘记在生产环境中提供Rails env

$ RAILS_ENV=production bundle exec anycable

注意:你不需要指定'-r选项(参见CLI文档),你的应用程序将从config/environment. rb加载。
最后,运行AnyCable WebSocket服务器,例如anycable-go:

$ anycable-go --host=localhost --port=8080

信息2019-08- 07 T16:37:46.387Z上下文=主启动任意电缆v0.6.2-13-gd 421927(带有mruby 1.2.0(2015年11月17日))(pid:1362)信息2019-08- 07 T16:37:46.387Z上下文=main在/cable处理WebSocket连接信息2019-08- 07 T16:37:46.388Z上下文=http在本地主机启动HTTP服务器:8080
您可以将AnyCable特定的配置存储在YAML文件中(类似于Action Cable one):

# config/anycable.yml
development:
  redis_url: redis://localhost:6379/1
production:
  redis_url: redis://my.redis.io:6379/1

相关问题