-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (75 loc) · 3.02 KB
/
cicd.yaml
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
name: CI Pipeline
on: push
jobs:
test-and-package:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
- name: setup python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: install dependencies
run: |
pip install -r requirements.txt
- name: run pipeline
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: |
dvc repro
- name: Run model tests
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: |
python -m unittest tests/test_model.py
- name: Promote model to production
if: success()
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: python scripts/promote_model.py
- name: Run Flask app tests
if: success()
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: python -m unittest tests/test_flask_app.py
- name: Login to AWS ECR
run: |
aws configure set aws_access_key_id ${{secrets.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{secrets.AWS_SECRET_ACCESS_KEY }}
aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 843369994444.dkr.ecr.eu-north-1.amazonaws.com
- name: Build Docker Image
run: |
docker build -t text-classification .
- name: Tag Docker Image
run: |
docker tag text-classification:latest 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
- name: Push Docker Image to AWS ECR
run: |
docker push 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
Deploy-to-EC2:
runs-on: ubuntu-latest
needs: test-and-package
steps:
- name: Deploy to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
aws configure set aws_access_key_id ${{secrets.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{secrets.AWS_SECRET_ACCESS_KEY }}
aws set default.region eu-north-1
aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 843369994444.dkr.ecr.eu-north-1.amazonaws.com
docker pull 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
docker stop text-classification || true
docker rm text-classification || true
docker run -d -p 80:5000 -e DAGSHUB_PAT= ${{ secrets.DAGSHUB_PAT }} --name text-classification 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:v1