Integrated version control and custom actions

I currently have RASA X set up on server and I can run custom actions pasted into actions/actions.py.

However, how can I develop custom actions locally and push them to the server? Must I manually copy them over every time?

:wave:Hello there and thanks for asking!

The preferred way for this is to package your action server as a Docker image, as describe in this doc. Depending on how you deployed your Rasa X instance, you will need to configure it so that it pulls the right Docker image. For instance, if you used the one-line deployment script, you can use the ACTION_SERVER_IMAGE and ACTION_SERVER_TAG environment variables.

Does this answer your question?

Yeah makes sense thanks! I’m working on a solution and will post it soon so future lads will have a better idea of what to do.

Ok so the custom action server is seperate from the main rasa server.

In order to version control your custom actions appropriately, you need to build a docker image with the action.py code and the python requirements needed for the functions.

So you need to set up a separate repo with the requirments.txt file and the actions.py file. I’m using Bitbucket.

You then need to set up a repo at AWS ECR, where you are going to store the docker images with the built images for your updated actions and requirements.

Once you update the actions.py file, you build a new docker image and you push it to the AWS ECR repo

The following commands and stuff will be useful if you’re looking at doing it, it also assumes you’ve already installed RASA X on a virtual machine:

You can view the docker image by running the following command:

docker images --all

Since we’re going to use the AWS CLI, we need to install it first.

Run the following in the root directory:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

unzip awscliv2.zip

sudo ./aws/install

Note, you might need to install the unzip package (apt install unzip)

Configure the AWS CLI and add the credentials:

aws configure

Retrieve an authentication token and authenticate your Docker client to your registry.

aws ecr get-login-password --region <aws region> | docker login --username AWS --password-stdin <aws account id>.dkr.ecr.<aws region>.amazonaws.com

Note you might run into a few issues here (X11 error). Uninstall docker-compose and remove the golang-docker-credential-helper. Then run the above command again, it should work.

rm $(which docker-compose)

sudo apt-get remove golang-docker-credential-helpers

Now you need to reinstall docker-compose.

apt-get install docker-ce docker-ce-cli containerd.io docker-compose jq -y

Build your Docker image using the following command.

docker build -t <repository_name> .

You should see the following after running the docker images --all command:

After the build completes, tag your image so you can push the image to this repository

docker tag <repository_name>:latest <aws account id>dkr.ecr.<aws region>.amazonaws.com/<repository_name>:latest

The docker images --all should now display the following:

Run the following command to push this image to your newly created AWS repository

docker push <aws account id>.dkr.ecr.eu-central-1.amazonaws.com/<repository_name>:latest

Now what we want to test is the pulling of the docker image from ECR to Rasa so first delete the image after it successfully pushed to ECR.

docker image rm <aws account id>.dkr.ecr.eu-central-1.amazonaws.com/<repository_name>:latest

You should not be able to view the image anymore when viewing the docker images.

Now pull the docker image back from AWS

docker pull <aws_account_id>.dkr.ecr.<aws region>.amazonaws.com/<repository_name>:latest

The docker image should be back when viewing all the docker images.

Now create a docker-compose override file to let the docker compose know that in addition to Rasa X, there should be a custom action server spinned up

touch docker-compose.override.yml

pico docker-compose.override.yml

Paste the following:

version: '3.4'

services:

app:

image: '<aws_account_id>.dkr.ecr.<aws region>.amazonaws.com/<repository_name>:latest'

volumes:

- './actions:/app/actions'

expose:

- '5055'

depends_on:

- rasa-production