Skip to content

Deploy Rasa lên server với Docker

Để dễ dàng đưa Rasa lên server sử dụng, ta cần phải dùng Docker. Và chia thành 2 phần: action server và rasa server.


Rasa Server

Ta sẽ dùng base image của Rasa trên Docker Hub, chọn image sao cho khớp với Rasa mình đang chạy trên local

FROM rasa/rasa:3.2.6-full

Thường sẽ phải dùng phiên bản full vì ta có model spacy riêng cho Tiếng Việt

Copy code của ta vào Docker Image

Ta sẽ copy cả folder vào Docker Image

# Use subdirectory as working directory
WORKDIR /app

COPY . ./

Ta phải dùng file .dockerignore chung với lệnh copy

tests/*
models/*
actions/*
.rasa/*
**/.*md
*/.rasa/*
.vscode
*.pyc
story_graph.dot
graph.html

❗Lưu ý thêm folder actions vào vì ta muốn chia action server thành một image riêng

Cài phần mềm riêng

Vì image của Rasa trên DockerHub sẽ không có những phần mềm cần thiết để chạy con Rasa của riêng ta.

# Change to root user to install dependencies
USER root

# Copy actions requirements
COPY ./requirements.txt ./

COPY ./actions/requirements-actions.txt /app/actions

RUN pip install -r requirements.txt
#Tempt fix for rasa 3.2.6 bug
RUN pip install --upgrade aio-pika

Cuối cùng là lệnh để chạy

# Don't use root user to run code
USER 1001

RUN rasa data validate

RUN rasa train

CMD ["--help"]

Action Server

Tưởng tự như Rasa Server

FROM rasa/rasa-sdk:3.2.0

Copy code vào Docker Image

# Use subdirectory as working directory
WORKDIR /app
# Copy actions code to working directory
COPY ./actions /app/actions

File .dockerignore lần này sẽ trống vì mình copy trực tiếp folder actions vào

Cài Dependencies

# Copy actions requirements
COPY ./actions/requirements-actions.txt ./

# Change to root user to install dependencies
USER root
# Install extra requirements for actions code
RUN pip install -r requirements-actions.txt
#Tempt fix for rasa 3.2.6 bug
RUN pip install --upgrade aio-pika

Cuối cùng là lệnh chạ

USER 1001 

# Start the action server
CMD ["start", "--actions", "actions.actions"]

Chạy Docker Image

Tại đây ta có thể dùng file docker-compose.yml để chạy hoặc dùng CI/CD deploy thẳng lên server.

Docker-compose

Bạn có thể tham khảo về docker-compose cho Rasa tại đây

Cách sử dụng Gitlab-ci để chạy image

Tham khảo phần Gitlab-ci của Document để biết thêm


❓ Muốn biết thêm chi tiết hay có câu hỏi nào?

Hãy lên website của RASA hoặc RASA Community Forum