My project structure looks like this
. └── rasa2/ ├── actions/ │ ├── __init__.py │ ├── action1.py │ ├── action2.py │ └── action3.py ├── data ├── models ├── __init__.py ├── actions.py ├── config.yml ├── domain.yml ├── endpoints.yml ├── intern_cred.yml └── load_credentials.py
Because I connect to several databases I have created a intern_cred.yml file where the credentials for the databases are stored. I have a helper script load_credentials.py
to load the yml file. I can start both rasa-server and rasa action server on the terminal but if I want to use docker-compose it fails.
Here are my files:
actions.py
from actions import action1
from actions import action2
from actions import action3
import load_credentials
action1
action2
action3
load_credentials
load_credentials.py
import yaml
try:
with open('./intern_cred.yml') as creds:
credentials = yaml.load(creds)
except:
print("some error occured")
action1.py
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
'''Necessary RASA imports'''
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
from rasa_sdk.events import AllSlotsReset
'''Necessary script imports'''
import requests
import json
from load_credentials import credentials
class MyExampleAction(Action):
'''
Example
'''
def name(self):
return 'action1'
def run(self, dispatcher, tracker, domain):
dispatcher.utter_message("Example")
Dockerfile
# Extend the official RASA SDK image
FROM rasa/rasa-sdk:2.2.0
# Use subdirectory as working directory
WORKDIR /app
# Copy any additional custom requirements, if necessary (uncomment next line)
COPY actions/requirements-actions.txt ./
# Change back to root user to install dependencies
USER root
# Install extra requirements for actions code, if necessary (uncomment next line)
RUN pip install -r requirements-actions.txt
# Copy actions folder to working directory
COPY ./actions /app/actions
# By best practices, don't run the code with root user
USER 1001
docker-compose
version: '3'
services:
rasa:
container_name: rasa-server
image: rasa/rasa:2.0.0-full
ports:
- 5005:5005
volumes:
- ./:/app
command:
- run
- --enable-api
app:
container_name: rasa-action-server
image: rasa-action-server:rasa-action-server-1
ports:
- 5055:5055
I followed the instructions in the docs and build my action server image. If i try to run the image i get following error:
2021-02-01 14:17:04 INFO rasa_sdk.endpoint - Starting action endpoint server...
2021-02-01 14:17:04 ERROR rasa_sdk.executor - Failed to register package 'actions'.
Traceback (most recent call last):
File "/app/rasa_sdk/executor.py", line 254, in register_package
self._import_submodules(package)
File "/app/rasa_sdk/executor.py", line 217, in _import_submodules
self._import_module(full_name)
File "/app/rasa_sdk/executor.py", line 231, in _import_module
module = importlib.import_module(name)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/actions/actions.py", line 4, in <module>
from actions import action1
File "/app/actions/action1.py", line 13, in <module>
from load_credentials import credentials
ModuleNotFoundError: No module named 'load_credentials'
As I said, if i start the action server from the terminal everything is ok, but not if i start the action-server image. So I asume I messed something up with the helper script where I load the credentials from the yml file.
Can somebody help me to get this working?
PS: intern_cred.yml
and load_credentials.py
should stay in the project root folder.