问题描述
我有一个在 Docker 中运行的现有 Rails 6.1 应用程序。我想通过 Docker-compose 将 Anycable 添加为作为服务运行的 anycable-go。我遵循了本指南: https://medium.com/@inklingviashruti/actioncable-anycable-with-angular-9-d1ecfa39f319
我必须使用以下内容才能使 grpc 正常工作: https://dustri.org/b/error-loading-shared-library-ld-linux-x86-64so2-on-alpine-linux.html
集成这些解决方案后,我能够让应用程序构建和启动应用程序。但是,只有 RPC 服务器正在启动。
Docker-compose.yml:
version: "3.7"
services:
redis:
image: redis:alpine
env_file:
.env
volumes:
- redis:/var/lib/redis/data
networks:
- app-network
db:
image: postgis/postgis:13-3.1-alpine
env_file:
.env
volumes:
- postgis:/var/lib/postgresql/data
networks:
- app-network
# anycable-go -—host=localhost -—port=3334
anycable:
image: anycable/anycable-go
env_file:
.env
networks:
- proxy
- app-network
api:
build: .
command: bash -c " rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
depends_on:
- db
- redis
env_file:
.env
networks:
- proxy
- app-network
networks:
app-network:
driver: bridge
proxy:
external:
name: Nginx-proxy
volumes:
redis:
postgis:
Dockerfile:
FROM ruby:2.7.2-alpine
ENV INSTALL_PATH /usr/src
RUN mkdir -p $INSTALL_PATH
RUN apk add --no-cache build-base bash git libpq postgresql libxml2-dev postgresql-dev postgresql-client redis
RUN gem install bundler
# for anycable
RUN apk add libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
RUN gem install grpc
RUN gem install grpc-tools
workdir /usr/src/app
copY Gemfile* ./
RUN bundle install
copY . .
# Add a script to be executed every time the container starts.
copY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT [ "entrypoint.sh" ]
EXPOSE 3000
# Start the main process.
CMD [ "rails","server","-b","0.0.0.0" ]
入口点.sh
#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /usr/src/app/tmp/pids/server.pid
#start AnyCable gRPC server
# anycable
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"
在上述代码中对 anycable 进行初始设置时,行 # anycable
未注释,但仅在启动 RPC 服务器时没有任何区别。
config/cable.yml:
development:
adapter: any_cable
test:
adapter: any_cable
production:
adapter: any_cable
config/anycable.yml:
development:
redis_url: <%= ENV.fetch("REdis_URL") { "redis://localhost:6379/1" } %>
production:
redis_url: <%= ENV.fetch("REdis_URL") { "redis://localhost:6379/1" } %>
config/application.rb:
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile,including any gems
# you've limited to :test,:development,or :production.
Bundler.require(*Rails.groups)
module HeadcountApi
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session,flash,cookies can be added back manually.
# Skip views,helpers and assets when generating a new resource.
config.api_only = true
end
end
如果您能帮助让原始 rails_api 接口在 Anycable 上工作,我们将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)