These docs are for version 1.x of Rasa Open Source.

# Setting up CI/CD

Even though developing a contextual assistant is different from developing traditional software, you should still follow software development best practices. Setting up a Continuous Integration (CI) and Continuous Deployment (CD) pipeline ensures that incremental updates to your bot are improving it, not harming it.

## Overview

Continuous Integration (CI) is the practice of merging in code changes frequently and automatically testing changes as they are committed. Continuous Deployment (CD) means automatically deploying integrated changes to a staging or production environment. Together, they allow you to make more frequent improvements to your assistant and efficiently test and deploy those changes.

This guide will cover **what** should go in a CI/CD pipeline, specific to a Rasa project. **How** you implement that pipeline is up to you.

## Continuous Integration (CI)

The best way to improve an assistant is with frequent [incremental updates](/content/docs/rasa-x/user-guide/fix-problems/index.html). No matter how small a change is, you want to be sure that it doesn’t introduce new problems or negatively impact the performance of your assistant.

- [Validate Data and Stories](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/setting-up-ci-cd/#validate-data-and-stories)
- [Train a Model](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/setting-up-ci-cd/#train-a-model)
- [Test the Assistant](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/setting-up-ci-cd/#test-the-assistant)
- [Compare NLU Performance](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/setting-up-ci-cd/#compare-nlu-performance)
- [Test Action Code](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/setting-up-ci-cd/#test-action-code)

### Validate Data and Stories

[Data validation](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/validate-files/#validate-files) verifies that there are no mistakes or major inconsistencies in your domain file, NLU data, or story data.

```bash
rasa data validate --fail-on-warnings --max-history <max_history>
```

### Train a Model

```bash
rasa train
```

### Test the Assistant

Testing your trained model on [test conversations](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/testing-your-assistant/#end-to-end-testing) is the best way to have confidence in how your assistant will act in certain situations.

```bash
rasa test --stories tests/conversation_tests.md --fail-on-prediction-errors
```

### Compare NLU Performance

If you’ve made significant changes to your NLU training data, you should run a [full NLU evaluation](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/testing-your-assistant/#nlu-evaluation).

```bash
rasa test nlu --cross-validation
```

### Test Action Code

The approach used to test your action code will depend on how it is implemented.

## Continuous Deployment (CD)

To get improvements out to your users frequently, you will want to automate as much of the deployment process as possible.

### Deploy your Rasa Model

If you ran [end-to-end tests](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/setting-up-ci-cd/#test-the-assistant) in your CI pipeline, you’ll already have a trained model. You can set up your CD pipeline to upload the trained model to your Rasa server if the CI results are satisfactory.

```bash
curl -k -F "model=@models/my_model.tar.gz" "https://example.rasa.com/api/projects/default/models?api_token={your_api_token}"
```

### Deploy your Action Server

You can automate [building and uploading a new image for your action server](https://legacy-docs-v1.rasa.com/1.10.16/user-guide/how-to-deploy/#building-an-action-server-image), to an image repository for each update to your action code.

## Example CI/CD pipelines

As examples, see the CI/CD pipelines for [Sara](https://github.com/RasaHQ/rasa-demo/blob/master/.github/workflows/build_and_deploy.yml) and [Carbon Bot](https://github.com/RasaHQ/carbon-assistant/blob/master/.github/workflows/model_ci.yml). Both use [Github Actions](https://github.com/features/actions) as a CI/CD tool.

👋 I can help you get started with Rasa and answer your technical questions.
