Using environment variables in rasa-production and rasa-worker Docker

Currently, there are custom commands set in the docker-compose.yml for the rasa-production and rasa-worker container:

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 "*"

Does anyone know how to set these parameters as environment variables and skip them in the command? I’ve rewritten the setup to a ECS task definition (which is working), but I have to pass the variables hardcoded as plain text in the command, since I cannot refer to environment variables in the ECS task definition container command. This looks like the following:

    {
        "essential": true,
        "image": "registry.hub.docker.com/rasa/rasa:1.10.12-full",
        "command": ["x", "--production", "--no-prompt", "--config-endpoint", "http://127.0.0.1:5002/api/config?token=1234", "--port", "5005", "--jwt-method", "HS256", "--jwt-secret", "1234", "--auth-token", "1234", "--cors", "\"*\"", "--debug"],
        "name": "rasa-production",
        "portMappings": [
            {
                "containerPort": 5005,
                "hostPort": 5005
            }
        ],
        ...
    }
    ...

I already tried creating an own Dockerfile with the following content, without succes.

FROM rasa/rasa:1.10.12-full

ENV RASA_X_HOST="http://127.0.0.1:5002"
ENV RASA_X_TOKEN=""
ENV JWT_SECRET=""
ENV RASA_TOKEN=""
ENV PORT=5005
 
ENTRYPOINT rasa x --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors \"*\" --debug

@koaning @b-quachtran is this anything you can help with?

I also tried using a entrypoint.sh. This seems to work partially, but when logging into the Rasa x console (and uploading a model), the conversation tab on rasa x stays white and I cannot interact with the model.

Dockerfile

FROM rasa/rasa:1.10.12-full

COPY entrypoint.sh entrypoint.sh
 
ENTRYPOINT ["bash"]
CMD ["entrypoint.sh"]

entrypoint.sh

rasa x --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors \"*\" --debug

Hi @sschrijver, the env vars are set in .env usually in /etc/rasa . I’m not sure I’m understanding your question right though; are you saying you can’t use these env vars?

Hi @mloubser,

Thank you for your anwser. I am having questions about the x-rasa-services in the docker-compose.yml. This service has a command override (please see the snippet below). Are you saying all the flags can be set through environment variables? Unfortunately, in the documentation you referred to in your answer, I do not see CONFIG_ENDPOINT, CORS, PORT and JWT_METHOD. I have to be able to set all the values with environment variables instead of a command override. Do you know if this is possible or how to work around this?

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

I gotcha now - you can override any of those using docker-compose.override.yml, and if you want, you can then refer to custom environmental variables in that file. They won’t be used by default, but if you define your startup command to refer to them, then they will. So, you will need to do a command override, but not every time you change the env vars values. Does that make sense?

Hi @mloubser, thanks for your response. We are not using the docker-compose anymore, it was just to give an example of how the service looked like in the docker-compose Rasa shares in their documentation.

I have rewritten the docker-compose into a terraform script, we’re using ECS Fargate. Environment variables are injected from AWS Parameter Store. I cannot 1:1 translate the docker-compose to a ECS task definition, since I get errors.

I want to state, we have a working setup now but it is not that nice now since the auth tokens et cetera are hardcoded in the task definition right now (see the JSON example in the initial post). I want to clean this up by injecting the environment variables in the docker container. so I can skip the following part in the task definition.

...
        "command": ["x", "--production", "--no-prompt", "--config-endpoint", "http://127.0.0.1:5002/api/config?token=1234", "--port", "5005", "--jwt-method", "HS256", "--jwt-secret", "1234", "--auth-token", "1234", "--cors", "\"*\"", "--debug"],
...

I tried overwriting your docker containers, but without any success, some variaties I have tried:

Dockerfile

FROM rasa/rasa:1.10.12-full
 
CMD x --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors '*' --debug

Throws the following error: rasa: error: invalid choice: '/bin/bash' (choose from 'init', 'run', 'shell', 'train', 'interactive', 'test', 'visualize', 'data', 'export', 'x') in the rasa-production container.

Dockerfile

FROM FROM rasa/rasa:1.10.12-full
  
CMD ["x", "--no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors '*' --debug"]

Throws the following error: rasa: error: unrecognized arguments: --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors "*" --debug in the rasa-production container.

Dockerfile

FROM FROM rasa/rasa:1.10.12-full

+CMD ["x", "--no-prompt", "--production", "--config-endpoint", "${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN}", "--port", ${PORT}, "--jwt-method", "HS256", "--jwt-secret", ${JWT_SECRET}, "--auth-token", "'${RASA_TOKEN}'", "--cors", "\"*\"", "--debug"]

Throws the following error: rasa: error: unrecognized arguments: --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors "*" --debug

The example in the initial post isn’t working either, throwing similar errors.

Hi,

There are several mistakes.

  1. Here is important to understand what Docker does. You can use docker inspect to see a command that is going to be executed.

For your image, we’ll have something like this.

            "Cmd": [
                "/bin/bash",
                "-o",
                "pipefail",
                "-c",
                "[\"x\", \"--no-prompt\", \"--production\", \"--config-endpoint\", \"${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN}\", \"--port\", ${PORT}, \"--jwt-method\", \"HS256\", \"--jwt-secret\", ${JWT_SECRET}, \"--auth-token\", \"'${RASA_TOKEN}'\", \"--cors\", \"\\\"*\\\"\", \"--debug\"]"
            ],

It means that the full command that is going to be executed is rasa /bin/bash ... (ENTRYPOINT - from rasa/rasa:1.10.12-full + CMD)

  1. When you pass environment variables in CMD, they are seeing as a string.

For example:

rasa x: error: argument -p/--port: invalid int value: '${PORT}'

Summarizing, you have to be sure that the command runs by Docker is correct and the environment variables are evaluated.

It should help:

Dockerfile

FROM rasa/rasa:1.10.12-full

ENTRYPOINT [ "/bin/bash" ]
CMD ["-c", "rasa x --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token '${RASA_TOKEN}' --cors \"*\" --debug"]

Hi @tczekajlo

Thanks for your reply! Your solution did work :smiley:, which is awesome! I only had to the remove the single quotes around --auth-token '${RASA_TOKEN'. Now I am finally able to inject these values from AWS Parameter Store, thanks again!

The final docker file looks somewhat like this (we use our own rasa full base image instead).

FROM rasa/rasa:1.10.12-full

ENTRYPOINT [ "/bin/bash" ]
CMD ["-c", "rasa x --no-prompt --production --config-endpoint ${RASA_X_HOST}/api/config?token=${RASA_X_TOKEN} --port ${PORT} --jwt-method HS256 --jwt-secret ${JWT_SECRET} --auth-token ${RASA_TOKEN} --cors \"*\" --debug"]