Skip to content

December 3rd, 2020

Using Rasa Github Action for building Custom Action Server images

  • portrait of Justina Petraitytė

    Justina Petraitytė

Implementing custom actions is a great way to enable your Rasa assistant to perform specific tasks - send an email, add items to your calendar, retrieve data from a database, and do pretty much anything else you can imagine. If you're using Rasa X you might be doing a lot of manual work when working with these actions. The Docker that contains the actions needs to be built, pushed and referenced. To simplify and automate this process we've built a Github Action which we hope will make it easier to build Docker images for custom actions. In this tutorial we would like to show you how you can use this Github Action to automate your Rasa custom action development workflow.

Github Action for custom action server

When it comes to Rasa custom actions, the usual workflow of adding them to the assistant deployed with Rasa X looks as follows:

  1. Write the custom action code inside the actions.py file
  2. Create a Dockerfile for your custom action (specifying the requirements and the process of building a docker image)
  3. Build a Docker image
  4. Push the image to the Docker registry (for example Docker Hub)
  5. Add the custom action server image to your assistant by configuring your Rasa X deployment

As you work on improving your assistant, you will find yourself constantly making changes to your custom actions code. This means that every time you make changes to your custom actions you will have to repeat steps 3 and 4 in order to be able to test those changes. These steps can be automated with Github Actions and we've created a custom action that should make this easy. The action handles the tasks of creating Dockerfile, building the docker image and pushing it to the docker registry for you. All you have to do is configure the necessary parameters to fit your use case.

Rasa Github Action can be found on Github Actions Marketplace alongside a number of examples of how to use and customize it.

Using the Rasa Github action for building action server images

High Level Overview

Here's a quickstart on how to add Rasa Github Action to your repository:

  1. Find the Rasa Github Action on Github Actions Marketplace and click on button "Use the Latest Version" (or select a different version of your preference):
  1. You will be prompted with a snippet that you can paste inside of your Github Action configuration .yml file:
  1. Pass the input parameters using the with statement inside the step which is using the Rasa Github action. For example:
YAML
jobs:
my_first_job:
steps:
- name: My first step
uses: RasaHQ/action-server-gha@master
with:
actions_directory: my_directory
requirements_file: my_file
docker_registry: my_registry
Setting up input parameters

We've now gotten started with the custom action. What we'll do next is show you how you can customise it.

Detailed example

Let's continue this example by applying it to one of the Rasa's starterpacks - Helpdesk Assistant. What we will do is we will add a Github Action to a forked repository of Helpdesk Assistant. It will automatically build and and push Docker images for custom action server every time there is a change introduced to any custom action.

Here are the directories and files of the repository that we will be using:

  • ./actions - a directory which contains the custom actions code
  • ./actions/requirements-actions.txt - a file containing the dependencies needed to run custom actions
  • Dockerfile - a Dockerfile which can be used to build Docker images for custom actions
  • ./github/workflows - a directory to store the .yml configuration files for Github Actions

To automate the process of building an image and pushing it to a Docker Registry every time someone makes changes to the custom action code we have to add a new workflow to the ./github/workflows directory. This can be done by creating a new .yml file inside directory, for example, custom_action_server.yml, and specifying the parameters of the workflow we want to automate:

  • the name of the action
  • the name and parameters of the Github event that should trigger the action
  • the jobs and the steps that should be executed when the actions is triggered

Here's how the configuration file for automating the process of building a Docker image and pushing it to a Docker Registry every time someone makes a change to the files inside of the ./actions directory could look like:

Note: you don't need a Dockerfile in place to use the Rasa Github Action - this step will be handled for you unless you want to add some custom steps or parameters.

To make sure that the Docker Hub login and password information is kept safe, we store those values as secrets. This can be done by adding secrets to the repository.

Once all of this is done, the Github Action for building Docker images for custom action server should run successfully. To check, you can head to the "Actions" tab of your repository and see the status and the logs of the process.

Summary

Our goal is to make it as easy as possible to build and improve your AI assistants with Rasa. Rasa Github Action should make it easier for developers to build Docker images for custom action servers. We would love to get your feedback on it - does it make your development workflow easier? Let us know about it by sharing your experience on Rasa Community Forum.