-
Notifications
You must be signed in to change notification settings - Fork 31
241 lines (201 loc) · 7.57 KB
/
model_ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
name: Model CI
on:
push:
branches:
- 'master'
pull_request:
types: [opened, synchronize, reopened]
env:
DOMAIN: 'carbon.rasa.com'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: carbon-assistant
NAMESPACE: carbon-assistant
RASA_X_IMAGE_NAME: ${{ secrets.RASA_X_IMAGE_NAME }}
RASA_X_USERNAME: admin
RASA_X_PASSWORD: ${{ secrets.RASA_X_ADMIN_PASSWORD }}
jobs:
build-model:
name: Build, test, and upload model
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade "pip<20"
pip install -r requirements.txt
- name: Check stories are consistent
run: |
rasa data validate stories --max-history 5 --fail-on-warning
- name: Train model
run: |
rasa train
- name: Run Through Test Stories
run: |
rasa test core --stories test_stories/stories.yml --fail-on-prediction-errors
- name: Cross-validate NLU model
id: cvnlu
if: github.event_name == 'pull_request'
run: |
rasa test nlu -f 2 --cross-validation
python format_results.py
- name: Upload Cross Validation Results
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v2
with:
name: cross-validation-result
path: results.md
- name: Upload model
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags') || github.ref == 'refs/heads/master')
uses: actions/upload-artifact@v2
with:
name: model
path: models
- name: Post cross-val results to PR
if: steps.cvnlu.outcome == 'success'
uses: samsucik/comment-on-pr@comment-file-contents
continue-on-error: true
with:
msg: results.md
build-images:
name: Build and Push Images
runs-on: ubuntu-latest
env:
IS_PUSH_EVENT: ${{ github.event_name == 'push' }}
steps:
- uses: actions/checkout@v2
- name: Set image tag
run: |
if [[ $IS_PUSH_EVENT == "false" ]]
then
IMAGE_TAG=${{ github.head_ref }}
else
IMAGE_TAG=$(basename ${{ github.ref }})
fi
echo "IMAGE_TAG=${IMAGE_TAG}-${{ github.sha }}" >> $GITHUB_ENV
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
name: Google Auth
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |-
gcloud --quiet auth configure-docker
- name: Build and push the Docker image
run: |
# Read and export variables from .env file
set -o allexport; source .env; set +o allexport
docker build . \
--build-arg RASA_SDK_IMAGE=rasa/rasa-sdk:${RASA_SDK_VERSION} \
--tag gcr.io/${{ secrets.GKE_PROJECT }}/carbon-bot-actions:$IMAGE_TAG
docker push gcr.io/${{ secrets.GKE_PROJECT }}/carbon-bot-actions:$IMAGE_TAG
deploy-to-cluster:
name: Re-deploy the cluster with the latest action server
runs-on: ubuntu-latest
needs:
- build-images
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags') || github.ref == 'refs/heads/master')
steps:
# Checkout repository because we need the content of the `.env` file later
- uses: actions/checkout@v2
- name: Set image tag
env:
IS_PUSH_EVENT: ${{ github.event_name == 'push' }}
run: |
if [[ $IS_PUSH_EVENT == "false" ]]
then
IMAGE_TAG=${{ github.head_ref }}
else
IMAGE_TAG=$(basename ${{ github.ref }})
fi
echo "IMAGE_TAG=${IMAGE_TAG}-${{ github.sha }}" >> $GITHUB_ENV
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
name: Google Auth
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |-
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- uses: google-github-actions/[email protected]
with:
cluster_name: ${{ secrets.GKE_CLUSTER }}
location: ${{ secrets.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}
- name: Install Helm and helmfile ⛑
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
sudo curl -fsSL https://github.com/roboll/helmfile/releases/download/v0.138.7/helmfile_linux_amd64 --output /usr/local/bin/helmfile
sudo chmod +x /usr/local/bin/helmfile
- name: Install Chart
env:
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
RASA_TOKEN: ${{ secrets.RASA_TOKEN }}
RASA_X_TOKEN: ${{ secrets.RASA_X_TOKEN }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
PASSWORD_SALT: ${{ secrets.PASSWORD_SALT }}
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
RABBITMQ_PASSWORD: ${{ secrets.RABBITMQ_PASSWORD }}
RASA_X_ADMIN_PASSWORD: ${{ secrets.RASA_X_ADMIN_PASSWORD }}
GKE_PROJECT: ${{ secrets.GKE_PROJECT }}
FACEBOOK_VERIFY_TOKEN: ${{ secrets.FACEBOOK_VERIFY_TOKEN }}
FACEBOOK_APP_SECRET: ${{ secrets.FACEBOOK_APP_SECRET }}
FACEBOOK_PAGE_ACCESS_TOKEN: ${{ secrets.FACEBOOK_PAGE_ACCESS_TOKEN }}
CLIMATIQ_API_KEY: ${{ secrets.CLIMATIQ_API_KEY }}
run: |
# Install helm v3
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
# Read and export variables from .env file
set -o allexport; source .env; set +o allexport
kubectl create ns ${NAMESPACE} || true
cd .github/deployments; helmfile sync
cat <<EOF | kubectl apply --namespace ${NAMESPACE} -f -
apiVersion: networking.gke.io/v1beta1
kind: ManagedCertificate
metadata:
generation: 1
name: rasa-bots-certificate
spec:
domains:
- ${{ env.DOMAIN }}
EOF
upload-model:
name: Upload the trained model to Rasa X
needs:
- deploy-to-cluster
- build-model
env:
MODEL_DIRECTORY: "models"
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags') || github.ref == 'refs/heads/master')
runs-on: ubuntu-latest
steps:
- name: Download Model
uses: actions/download-artifact@v2
with:
name: model
path: ${{ env.MODEL_DIRECTORY }}
- name: Get path to model
run: |
ls -R
echo "MODELNAME=${{ env.MODEL_DIRECTORY }}/$(ls ${{ env.MODEL_DIRECTORY }})" >> $GITHUB_ENV
- name: Upload Model to Rasa
run: |
# Get token
RASA_X_TOKEN=$(curl -s --header "Content-Type: application/json" \
--request POST \
--data "{\"username\":\"${RASA_X_USERNAME}\",\"password\":\"${RASA_X_PASSWORD}\"}" \
https://${{ env.DOMAIN }}/api/auth | jq -r .access_token)
# Upload model
curl -k --fail -H "Authorization: Bearer ${RASA_X_TOKEN}" -F "model=@${MODELNAME}" https://${{ env.DOMAIN }}/api/projects/default/models
# ensure model is ready and tag as production
sleep 5
export MODEL=$(basename ${MODELNAME} .tar.gz)
curl --fail -XPUT -H "Authorization: Bearer ${RASA_X_TOKEN}" https://${{ env.DOMAIN }}/api/projects/default/models/${MODEL}/tags/production