Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from rauldpm/10_add-gha_2.0.2
Browse files Browse the repository at this point in the history
Add gha workflows
  • Loading branch information
Raul Del Pozo Moreno authored Aug 9, 2022
2 parents 2d771bf + eb629b8 commit 63655e2
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/build-model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Rasa model

# Run only when the branch is merged into main branch and
# the changes affects the model data
on:
push:
branches:
- "main"
paths:
- "data/**"
- "config.yml"
- "domain.yml"
- "endpoints.yml"
- "credentials.yml"

jobs:
build:
name: Train model
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Docker buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Train

- name: Run container (train)
run: docker run -v "$(pwd)/models:/app/models" rauldpm/tfg-rasa:build

- name: Change model name
run: mv models/*.tar.gz models/model.tar.gz

# Upload file

- id: "auth"
uses: "google-github-actions/auth@v0"
with:
credentials_json: "${{ secrets.GCP_JSON_KEY }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v0"

- name: Deploy
run: gsutil cp models/model.tar.gz gs://${{ secrets.GCP_BUCKET }}
36 changes: 36 additions & 0 deletions .github/workflows/build-testing-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build testing container

# Build and push to DockerHub the testing container
on:
push:
branches:
- "main"
paths:
- "Docker/testing/**"

jobs:
build:
name: Build model container
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Copy dockerfile
run: cp Docker/testing/Dockerfile .

- name: Docker buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build the Docker image
run: docker build -t rauldpm/tfg-rasa:testing .

- name: Docker Push
run: docker push rauldpm/tfg-rasa:testing
37 changes: 37 additions & 0 deletions .github/workflows/build-train-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build container builder

# Build and push to DockerHub the builder container
# This container will reduce the train process (build-model.yml)
on:
push:
branches:
- "main"
paths:
- "Docker/build/**"

jobs:
build:
name: Build model container
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Copy dockerfile
run: cp Docker/build/Dockerfile .

- name: Docker buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build the Docker image
run: docker build -t rauldpm/tfg-rasa:build .

- name: Docker Push
run: docker push rauldpm/tfg-rasa:build
49 changes: 49 additions & 0 deletions .github/workflows/rasa-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Tests

# Build and push to DockerHub the builder container
# This container will reduce the train process (build-model.yml)
on:
pull_request:
branches:
- "*"
push:
paths:
- "data/**"
- "config.yml"
- "domain.yml"
- "endpoints.yml"
- "credentials.yml"

jobs:
build:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Train model

- name: Docker buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run container (train)
run: docker run -v "$(pwd)/models:/app/models" rauldpm/tfg-rasa:build

# Run tests

- name: Create test results directory
run: mkdir results

- name: Run data validate test
run: docker run -v "$(pwd)/models:/app/models" -v "$(pwd)/results:/app/results" rauldpm/tfg-rasa:testing data-validate 2>&1 | tee -a results/output_data_validate.txt

- name: Run stories test
run: docker run -v "$(pwd)/models:/app/models" -v "$(pwd)/results:/app/results" rauldpm/tfg-rasa:testing test 2>&1 | tee -a results/output_stories_tests.txt
11 changes: 11 additions & 0 deletions Docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM rasa/rasa:3.1.1

USER root

# copy proyect files
# the dockerfile needs to be copied to the root path
COPY . /app/
WORKDIR '/app'

# train model
ENTRYPOINT ["rasa", "train"]
15 changes: 15 additions & 0 deletions Docker/testing/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM rasa/rasa:3.1.1

USER root

# copy proyect files
# the dockerfile needs to be copied to the root path
COPY actions/* /app/actions/
COPY data/* /app/data/
COPY tests/* /app/tests/
COPY config.yml credentials.yml domain.yml endpoints.yml /app/
COPY Docker/testing/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
WORKDIR '/app'

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
20 changes: 20 additions & 0 deletions Docker/testing/check_stories_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

output=${1}


actual=$(grep "Correct" ${output} | awk '{print $7}')
total=$(grep "Correct" ${output} | awk '{print $9}')

actual=(${actual})
total=(${total})

if [[ ${actual[0]} -ne ${total[0]} ]]; then
echo "Some stories failed"
exit 1
fi

if [[ ${actual[1]} -ne ${total[1]} ]]; then
echo "Some stories failed"
exit 1
fi
23 changes: 23 additions & 0 deletions Docker/testing/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Adapted from https://github.com/RasaHQ/rasa-sdk/blob/main/entrypoint.sh

set -Eeuo pipefail

function print_help {
echo "Available options:"
echo " test - Run stories tests"
echo " data-validate - Run nlu data validationm"
}

case ${1} in
test)
exec python -m rasa test
;;
data-validate)
exec python -m rasa data validate
;;
*)
print_help
;;
esac
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# ChatbotTFG
# ChatbotTFG

[![Rasa trained model](https://github.com/rauldpm/ChatbotTFG/actions/workflows/build-model.yml/badge.svg)](https://github.com/rauldpm/ChatbotTFG/actions/workflows/build-model.yml)

[![Build container builder](https://github.com/rauldpm/ChatbotTFG/actions/workflows/build-container.yml/badge.svg)](https://github.com/rauldpm/ChatbotTFG/actions/workflows/build-container.yml)

[![Tests](https://github.com/rauldpm/ChatbotTFG/actions/workflows/rasa-test.yml/badge.svg)](https://github.com/rauldpm/ChatbotTFG/actions/workflows/rasa-test.yml)

0 comments on commit 63655e2

Please sign in to comment.