Skip to content

Commit

Permalink
Add integration tests for gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
radovanZRasa committed Aug 6, 2024
1 parent b9cd651 commit e303e10
Show file tree
Hide file tree
Showing 33 changed files with 1,353 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ CHANGELOG.txt
.pre-commit-config.yaml
changelog/*
gha-creds-*.json
**/gha-creds-*.json
**/gha-creds-*.json
grpc-server-docker-integration-test-results.xml
30 changes: 30 additions & 0 deletions .github/actions/auth-aws-ecr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Authenticate to AWS ECR
description: Encapsulates steps for Authenticating to ECR

permissions:
id-token: write
contents: read

inputs:
AWS_REGION:
description: 'AWS Region'
required: true
AWS_ARN_ROLE_TO_ASSUME:
description: 'AWS role ARN'
required: true

runs:
using: 'composite'
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 # v3.0.1
with:
role-to-assume: ${{ inputs.AWS_ARN_ROLE_TO_ASSUME }}
aws-region: ${{ inputs.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
with:
mask-password: "true"

39 changes: 39 additions & 0 deletions .github/actions/debug-grpc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Debug custom actions integration test containers
description: Encapsulates steps for custom actions test debugging

inputs:
COMPOSE_FILE_PATH:
description: 'Custom action docker compose path'
required: true
RASA_SDK_REPOSITORY:
description: 'Rasa SDK repository path'
required: true
RASA_SDK_IMAGE_TAG:
description: 'Rasa SDK image tag'
required: true

runs:
using: 'composite'

steps:
- name: List containers
run: sudo docker ps -a
shell: bash

- name: Check logs for action server without TLS
env:
RASA_SDK_REPOSITORY: ${{ inputs.RASA_SDK_REPOSITORY }}
RASA_SDK_IMAGE_TAG: ${{ inputs.RASA_SDK_IMAGE_TAG }}
run: |
docker compose -f ${{ inputs.COMPOSE_FILE_PATH }} \
logs action-server-grpc-no-tls
shell: bash

- name: Check logs for action server with TLS
env:
RASA_SDK_REPOSITORY: ${{ inputs.RASA_SDK_REPOSITORY }}
RASA_SDK_IMAGE_TAG: ${{ inputs.RASA_SDK_IMAGE_TAG }}
run: |
docker compose -f ${{ inputs.COMPOSE_FILE_PATH }} \
logs action-server-grpc-tls
shell: bash
88 changes: 78 additions & 10 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
IS_TAG_BUILD: ${{ startsWith(github.event.ref, 'refs/tags') }}
DEV_REPOSITORY: 329710836760.dkr.ecr.us-east-1.amazonaws.com/rasa-sdk-dev
AWS_REGION: us-east-1
DEV_DEPS_IMAGE_TAG: pr${{ github.event.number }}-with-dev-deps

# SECRETS
# - PYPI_TOKEN: publishing token for amn41 account, needs to be maintainer of
Expand Down Expand Up @@ -143,17 +144,37 @@ jobs:
- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 # v3.0.1
- name: Authenticate to AWS ECR
uses: ./.github/actions/auth-aws-ecr
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE_SESSION_TOKEN }}
aws-region: ${{ env.AWS_REGION }}
AWS_REGION: ${{ env.AWS_REGION }}
AWS_ARN_ROLE_TO_ASSUME: ${{ secrets.AWS_ASSUME_ROLE_SESSION_TOKEN }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c # v3.1.0

- name: Build and push docker image to AWS
run: |
IMAGE_NAME=${{ env.DEV_REPOSITORY }} \
IMAGE_TAG=pr${{ github.event.number }} \
make build-and-push-multi-platform-docker
rasa-sdk-with-dev-deps-docker-image:
name: Build dev Docker image with dev dependencies
runs-on: ubuntu-22.04

steps:
- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Authenticate to AWS ECR
uses: ./.github/actions/auth-aws-ecr
with:
mask-password: "true"
AWS_REGION: ${{ env.AWS_REGION }}
AWS_ARN_ROLE_TO_ASSUME: ${{ secrets.AWS_ASSUME_ROLE_SESSION_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
Expand All @@ -164,5 +185,52 @@ jobs:
- name: Build and push docker image to AWS
run: |
IMAGE_NAME=${{ env.DEV_REPOSITORY }} \
IMAGE_TAG=pr${{ github.event.number }} \
make build-and-push-multi-platform-docker
IMAGE_TAG=${{ env.DEV_DEPS_IMAGE_TAG }} \
make build-and-push-multi-platform-docker-with-dev-deps
grpc_integration_tests:
name: Run gRPC integration tests using Docker containers
runs-on: ubuntu-22.04
needs: [rasa-sdk-dev-docker-image, rasa-sdk-with-dev-deps-docker-image]

steps:
- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Authenticate to AWS ECR
uses: ./.github/actions/auth-aws-ecr
with:
AWS_REGION: ${{ env.AWS_REGION }}
AWS_ARN_ROLE_TO_ASSUME: ${{ secrets.AWS_ASSUME_ROLE_SESSION_TOKEN }}

- name: Docker version
run: docker --version && docker compose version

- name: gRPC Server Integration Testing - Run env docker containers
run: |
make start-grpc-integration-test-env
env:
RASA_SDK_REPOSITORY: ${{ env.DEV_REPOSITORY }}
RASA_SDK_IMAGE_TAG: ${{ env.IMAGE_TAG }}

- name: gRPC Server Integration Testing - Run tests on gRPC server with and without TLS 🩺
run: |
make run-grpc-integration-tests
env:
IMAGE_WITH_DEV_DEPS: ${{ env.DEV_REPOSITORY }}
IMAGE_TAG: ${{ secrets.SEGMENT_WRITE_DEV_KEY }}

- name: gRPC Server Integration Testing - Stop env docker containers
run: |
make stop-grpc-integration-test-env
env:
RASA_SDK_REPOSITORY: ${{ env.DEV_REPOSITORY }}
RASA_SDK_IMAGE_TAG: ${{ env.IMAGE_TAG }}

- name: Show container logs
if: always()
uses: ./.github/actions/debug-grpc
with:
COMPOSE_FILE_PATH: tests/integration_tests/grpc_server/setup/docker-compose.yml
RASA_SDK_REPOSITORY: ${{ env.DEV_REPOSITORY }}
RASA_SDK_IMAGE_TAG: ${{ env.IMAGE_TAG }}
81 changes: 81 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
FROM ubuntu:22.04 AS base

# hadolint ignore=DL3005,DL3008
RUN apt-get update -qq \
# Make sure that all security updates are installed
&& apt-get dist-upgrade -y --no-install-recommends \
&& apt-get install -y --no-install-recommends \
python3 \
python3-venv \
python3-pip \
python3-dev \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 100 \
&& update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 100

FROM base AS python_builder

ARG POETRY_VERSION=1.8.2

# hadolint ignore=DL3008
RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends \
curl \
&& apt-get autoremove -y

# install poetry
# keep this in sync with the version in pyproject.toml and Dockerfile

Check warning on line 30 in Dockerfile.dev

View workflow job for this annotation

GitHub Actions / Typo CI

pyproject

"pyproject" is a typo. Did you mean "projector"?
ENV POETRY_VERSION=$POETRY_VERSION
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sSL https://install.python-poetry.org | python
ENV PATH="/root/.local/bin:/opt/venv/bin:${PATH}"

# install dependencies
COPY . /app/

WORKDIR /app

# hadolint ignore=SC1091,DL3013
# install dependencies and build wheels
RUN python -m venv /opt/venv && \
. /opt/venv/bin/activate && \
pip install --no-cache-dir -U pip && \
pip install --no-cache-dir wheel && \
poetry install --no-root --no-interaction

# build the Rasa SDK wheel and install it
# hadolint ignore=SC1091,DL3013
RUN poetry build -f wheel -n && \
pip install --no-deps dist/*.whl && \
rm -rf dist *.egg-info

RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm -rf /root/.cache/pip/*

EXPOSE 5055
ENTRYPOINT [""]
#CMD [""]
## final image
#FROM base
#
## copy needed files
#COPY ./entrypoint.sh /app/
#COPY --from=python_builder /opt/venv /opt/venv
#
#ENV PATH="/opt/venv/bin:$PATH"
#
## update permissions & change user
#RUN chgrp -R 0 /app && chmod -R g=u /app
#USER 1001
#
## change shell
#SHELL ["/bin/bash", "-o", "pipefail", "-c"]
#
## create a mount point for custom actions and the entry point
#WORKDIR /app
#EXPOSE 5055
#ENTRYPOINT [""]
#CMD [""]
63 changes: 59 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.PHONY: clean test lint init check-readme docs

TEST_PATH=./
INTEGRATION_TEST_FOLDER = integration_tests
GRPC_SERVER_INTEGRATION_TEST_FOLDER = $(INTEGRATION_TEST_FOLDER)/grpc_server

help: ## show help message
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -hE '^[A-Za-z0-9_ \-]*?:.*##.*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

install: ## install dependencies
poetry run python -m pip install -U pip
Expand Down Expand Up @@ -39,19 +41,29 @@ lint-docstrings: ## check docstrings
./scripts/lint_python_docstrings.sh $(BRANCH)

IMAGE_NAME ?= rasa/rasa-sdk
IMAGE_WITH_DEV_DEPS ?= rasa/rasa-sdk-with-dev-deps
IMAGE_TAG ?= latest
PLATFORM ?= linux/arm64
POETRY_VERSION ?= $(shell ./scripts/poetry-version.sh)

# Builds a docker image with runtime dependencies installed
build-docker: ## build docker image for one platform
docker build . \
--build-arg POETRY_VERSION=$(POETRY_VERSION) \
--platform=$(PLATFORM) \
-f Dockerfile \
-t $(IMAGE_NAME):$(IMAGE_TAG)

# Builds a docker image with runtime and dev dependencies installed
build-docker-with-dev-deps: ## build docker image with dev dependencies for one platform
docker build . \
--build-arg POETRY_VERSION=$(POETRY_VERSION) \
--platform=$(PLATFORM) \
-f Dockerfile.dev \
-t $(IMAGE_WITH_DEV_DEPS):$(IMAGE_TAG)

# To be able to build a multiplatform docker image
# make sure that builder with appropriate docker driver is enabled and set as current
# make sure that builder with appropriate docker driver is enabled and set as current builder
build-and-push-multi-platform-docker: PLATFORM = linux/amd64,linux/arm64
build-and-push-multi-platform-docker: ## build and push multi-platform docker image
docker buildx build . \
Expand All @@ -61,8 +73,23 @@ build-and-push-multi-platform-docker: ## build and push multi-platform docker i
-t $(IMAGE_NAME):$(IMAGE_TAG) \
--push

# To be able to build a multiplatform docker image with dev dependencies
# make sure that builder with appropriate docker driver is enabled and set as current builder
build-and-push-multi-platform-docker-with-dev-deps: PLATFORM = linux/amd64,linux/arm64
build-and-push-multi-platform-docker-with-dev-deps: ## build and push multi-platform docker image with dev dependencies
docker buildx build . \
--build-arg POETRY_VERSION=$(POETRY_VERSION) \
--platform=$(PLATFORM) \
-f Dockerfile \
-t $(IMAGE_WITH_DEV_DEPS):$(IMAGE_TAG) \
--push

test: clean ## run tests
poetry run py.test tests --cov rasa_sdk -v
poetry run \
pytest tests \
--cov rasa_sdk \
--ignore $(INTEGRATION_TEST_FOLDER) \
-v

generate-pending-changelog: ## generate a changelog for the next release
poetry run python -c "from scripts import release; release.generate_changelog('major.minor.patch')"
Expand All @@ -89,4 +116,32 @@ generate-grpc: ## generate grpc code
check-generate-grpc-code-in-sync: generate-grpc
check-generate-grpc-code-in-sync: ## check if the generated code is in sync with the proto files
# this is a helper to check if the generated code is in sync with the proto files
git diff --exit-code rasa_sdk/grpc_py | if [ "$$(wc -c)" -eq 0 ]; then echo "Generated code is in sync with proto files"; else echo "Generated code is not in sync with proto files"; exit 1; fi
git diff --exit-code rasa_sdk/grpc_py | if [ "$$(wc -c)" -eq 0 ]; then echo "Generated code is in sync with proto files"; else echo "Generated code is not in sync with proto files"; exit 1; fi

GRPC_SERVER_DOCKER_COMPOSE_FILE = $(GRPC_SERVER_INTEGRATION_TEST_FOLDER)/setup/docker_compose.yml

start-grpc-integration-test-env: ## run the rnv for the grpc integration tests
RASA_SDK_REPOSITORY=$(IMAGE_NAME) \
RASA_SDK_IMAGE_TAG=$(IMAGE_TAG) \
docker compose -f $(GRPC_SERVER_DOCKER_COMPOSE_FILE) up --wait

stop-grpc-integration-test-env: ## stop the env for the grpc integration tests
RASA_SDK_REPOSITORY=$(IMAGE_NAME) \
RASA_SDK_IMAGE_TAG=$(IMAGE_TAG) \
docker compose -f $(GRPC_SERVER_DOCKER_COMPOSE_FILE) down

GRPC_SERVER_INTEGRATION_TEST_RESULTS_FILE = grpc-server-docker-integration-test-results.xml

# Runs the gRPC integration tests in a docker container created from the image with dev dependencies
# Make sure to first start the environment with `make start-grpc-integration-test-env` before running this target
run-grpc-integration-tests: ## run the grpc integration tests
docker run --rm \
-v $(PWD):/app \
--network setup_rasa-pro-network \
-e GRPC_ACTION_SERVER_HOST="action-server-grpc-no-tls" \
-e GRPC_ACTION_SERVER_TLS_HOST="action-server-grpc-tls" \
$(IMAGE_WITH_DEV_DEPS):$(IMAGE_TAG) \
poetry run \
pytest $(GRPC_SERVER_INTEGRATION_TEST_FOLDER)/test_docker_grpc_server.py \
--junitxml=$(GRPC_SERVER_INTEGRATION_TEST_RESULTS_FILE) \
--verbose
9 changes: 9 additions & 0 deletions certs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ca-key.pem
ca.csr
ca.pem
client-key.pem
client.csr
client.pem
server-key.pem
server.csr
server.pem
Loading

0 comments on commit e303e10

Please sign in to comment.