Custom Socket Channel in Docker-compose not working

Dear, I’m trying to deploy a chatbot using docker-compose, and the bot has a custom socket channel. it’s working fine on my local machine without docker-compose. but When I tried running the bot using Docker-compose I faced the following issue.

rasa-production_1  | Traceback (most recent call last):
rasa-production_1  |   File "/opt/venv/bin/rasa", line 8, in <module>
rasa-production_1  |     sys.exit(main())
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/__main__.py", line 92, in main
rasa-production_1  |     cmdline_arguments.func(cmdline_arguments)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/cli/x.py", line 324, in rasa_x
rasa-production_1  |     run_in_production(args)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/cli/x.py", line 382, in run_in_production
rasa-production_1  |     _rasa_service(args, endpoints, None, credentials_path)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/cli/x.py", line 86, in _rasa_service
rasa-production_1  |     ssl_password=args.ssl_password,
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/run.py", line 171, in serve_application
rasa-production_1  |     input_channels = create_http_input_channels(channel, credentials)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/run.py", line 50, in create_http_input_channels
rasa-production_1  |     return [_create_single_channel(c, k) for c, k in all_credentials.items()]
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/run.py", line 50, in <listcomp>
rasa-production_1  |     return [_create_single_channel(c, k) for c, k in all_credentials.items()]
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/core/run.py", line 69, in _create_single_channel
rasa-production_1  |     "is a proper name of a class in a module.".format(channel)
rasa-production_1  | Exception: Failed to find input channel class for 'channel.my_socket.SocketIOInput'. Unknown input channel. Check your credentials configuration to make sure the mentioned channel is not misspelled. If you are creating your own channel, make sure it is a proper name of a class in a module.

Docker-compose file content:

version: "3.4"

x-database-credentials: &database-credentials
  DB_HOST: "db"
  DB_PORT: "5432"
  DB_USER: "${DB_USER:-admin}"
  DB_PASSWORD: "${DB_PASSWORD}"
  DB_LOGIN_DB: "${DB_LOGIN_DB:-rasa}"

x-rabbitmq-credentials: &rabbitmq-credentials
  RABBITMQ_HOST: "rabbit"
  RABBITMQ_USERNAME: "user"
  RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}

x-redis-credentials: &redis-credentials
  REDIS_HOST: "redis"
  REDIS_PORT: "6379"
  REDIS_PASSWORD: ${REDIS_PASSWORD}
  REDIS_DB: "1"

x-duckling-credentials: &duckling-credentials
  RASA_DUCKLING_HTTP_URL: "http://duckling:8000"

x-rasax-credentials: &rasax-credentials
  RASA_X_HOST: "http://rasa-x:5002"
  RASA_X_USERNAME: ${RASA_X_USERNAME:-admin}
  RASA_X_PASSWORD: ${RASA_X_PASSWORD:-}
  RASA_X_TOKEN: ${RASA_X_TOKEN}
  JWT_SECRET: ${JWT_SECRET}
  RASA_USER_APP: "http://app:5055"
  RASA_PRODUCTION_HOST: "http://rasa-production:5005"
  RASA_WORKER_HOST: "http://rasa-worker:5005"
  RASA_TOKEN: ${RASA_TOKEN}

x-rasa-credentials: &rasa-credentials
  <<: *rabbitmq-credentials
  <<: *rasax-credentials
  <<: *database-credentials
  <<: *redis-credentials
  <<: *duckling-credentials
  RASA_TOKEN: ${RASA_TOKEN}
  RASA_MODEL_PULL_INTERVAL: 10
  RABBITMQ_QUEUE: "rasa_production_events"

x-rasa-services: &default-rasa-service
  restart: always
  image: "rasa/rasa:${RASA_VERSION}-full"
  expose:
    - "5005"
  command: >
    x
    --no-prompt
    --production
    --config-endpoint http://rasa-x:5002/api/config?token=${RASA_X_TOKEN}
    --port 5005
    --jwt-method HS256
    --jwt-secret ${JWT_SECRET}
    --auth-token '${RASA_TOKEN}'
    --cors "*"
  depends_on:
    - rasa-x
    - rabbit
    - redis

services:
  rasa-x:
    restart: always
    image: "rasa/rasa-x:${RASA_X_VERSION}"
    expose:
      - "5002"
    volumes:
      - ./models:/app/models
      - ./environments.yml:/app/environments.yml
      - ./credentials.yml:/app/credentials.yml
      - ./endpoints.yml:/app/endpoints.yml
      - ./logs:/logs
      - ./auth:/app/auth
      - ./channel:/app/channel
    environment:
      <<: *database-credentials
      <<: *rasa-credentials
      SELF_PORT: "5002"
      DB_DATABASE: "${DB_DATABASE:-rasa}"
      RASA_MODEL_DIR: "/app/models"
      PASSWORD_SALT: ${PASSWORD_SALT}
      RABBITMQ_QUEUE: "rasa_production_events"
      RASA_X_USER_ANALYTICS: "0"
      SANIC_RESPONSE_TIMEOUT: "3600"
    depends_on:
      - db

  rasa-production:
    <<: *default-rasa-service
    environment:
      <<: *rasa-credentials
      RASA_ENVIRONMENT: "production"
      DB_DATABASE: "tracker"
      RASA_MODEL_SERVER: "http://rasa-x:5002/api/projects/default/models/tags/production"

  rasa-worker:
    <<: *default-rasa-service
    environment:
      <<: *rasa-credentials
      RASA_ENVIRONMENT: "worker"
      DB_DATABASE: "worker_tracker"
      RASA_MODEL_SERVER: "http://rasa-x:5002/api/projects/default/models/tags/production"

  app:
    restart: always
    image: "rasa/rasa-sdk:latest"
    volumes:
      - ./actions:/app/actions
    expose:
      - "5055"
    depends_on:
      - rasa-production

  db:
    restart: always
    image: "bitnami/postgresql:11.7.0"
    expose:
      - "5432"
    environment:
      POSTGRESQL_USERNAME: "${DB_USER:-admin}"
      POSTGRESQL_PASSWORD: "${DB_PASSWORD}"
      POSTGRESQL_DATABASE: "${DB_DATABASE:-rasa}"
    volumes:
      - ./db:/bitnami/postgresql

  rabbit:
    restart: always
    image: "bitnami/rabbitmq:3.8.3"
    environment:
      RABBITMQ_HOST: "rabbit"
      RABBITMQ_USERNAME: "user"
      RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
      RABBITMQ_DISK_FREE_LIMIT: "{mem_relative, 0.1}"
    expose:
      - "5672"

  duckling:
    restart: always
    image: "rasa/duckling:0.1.6.3"
    expose:
      - "8000"
    command: ["duckling-example-exe", "--no-access-log", "--no-error-log"]

  nginx:
    restart: always
    image: "rasa/nginx:${RASA_X_VERSION}"
    ports:
      - "80:8080"
      - "443:8443"
    volumes:
      - ./certs:/opt/bitnami/certs
      - ./terms:/opt/bitnami/nginx/conf/bitnami/terms
    depends_on:
      - rasa-x
      - rasa-production
      - app

  redis:
    restart: always
    image: "bitnami/redis:5.0.8"
    environment:
      REDIS_PASSWORD: ${REDIS_PASSWORD}
    expose:
      - "6379"
      
  mongo:
    image: mongo:4.2.0
    ports:
      - 27017:27017

Credentials.yml file content

channel.my_socket.SocketIOInput:
 user_message_evt: user_uttered
 bot_message_evt: bot_uttered
 session_persistence: true

.env file content:

RASA_X_VERSION=0.31.0
RASA_VERSION=1.10.8

Hello @mohocp,

Thanks for reaching out. The first thing I want to double-check is that the module channel.my_socket is import-able. Is this the absolute module name or a relative module name? Asking because the underlying code is doing something like:

import channel.my_socket

getattr(channel.my_socket, "SocketIOInput")

Moreover, this module should be in the PYTHONPATH of the rasa-production container, otherwise it wouldn’t work :slight_smile:

Let me know if that helps!

Thanks for Replay @m-vdb

it’s relative module name.

Are there articles on how to add the module in PYTHONPATH of the rasa-production container?

When re-reading your configuration, I saw that you already mounted the channel directory inside the rasa-production container using:

volumes:
   - ./channel:/app/channel

So I think the next step would be to configure the PYTHONPATH env varibable of the container, so that the channel module is importable. Something like this might work:

environment:
  PYTHONPATH="/app"

Sorry @m-vdb, it’s still not working, I tried many solution and not working

@mohocp any chance you could share some of the code / setup here? It’ll help me debug your situation.

Dear @m-vdb, I solved the issue, the problem was mounting for the channel should be in x-rasa-services not in rasa-production. Thanks for your support

1 Like

OK makes sense – sorry for not catching that earlier!

Hello @mohocp, can you please tell me how you did solve that problem. Did you need to set the PYTHONPATH en variable or just mount the channel in x-rasa-services?

Thank you

I hit the same issue as the author did. The solution is that, on GCP server, cd /etc/rasa, update the docker-compose.yml file to mount the file path of your custom code under volumes. For example, my custom channel file sits in /etc/rasa/addons/xxx.py, in this case, we need to add the highlighted code:

image

After that, restart the docker-compose, and it would work. @DC1991Lau

1 Like