-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (123 loc) · 4.87 KB
/
Copy pathcicd.yaml
File metadata and controls
149 lines (123 loc) · 4.87 KB
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
name: CICD Pipeline
on: push
jobs:
model-deployment:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Linux-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: Linux-pip-
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run pipeline
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-north-1
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: dvc repro
- name: Push DVC-tracked data to remote
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-north-1
run: dvc push
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Add changes to Git
run: git add .
- name: Commit changes
if: ${{ github.actor != 'github-actions[bot]' }}
run: git commit -m "Automated commit of DVC outputs and updated code" || echo "No changes to commit"
- name: Push changes
if: ${{ github.actor != 'github-actions[bot]' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push origin ${{ github.ref_name }}
- name: Run model loading test
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: pytest -p no:warnings -s scripts/load_model_test.py
- name: Run model performance test
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: pytest -p no:warnings -s scripts/performance_test.py
- name: Promote model to production
if: success()
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: python scripts/promote_model.py
- name: Start FastAPI App
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: nohup python fastapi/app.py &
- name: Wait for FastAPI to Start
run: |
for i in {1..10}; do
if curl -s http://localhost:5000/docs > /dev/null; then
echo "FastAPI is up!"
exit 0
fi
sleep 2
done
echo "FastAPI did not start in time" && exit 1
- name: Run FastAPI tests
run: pytest -p no:warnings -s scripts/fastapi_test.py
- name: Stop FastAPI App
run: killall python
- name: Login to AWS ECR
if: success()
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-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/m3t3s7a1
- name: Build Docker image
if: success()
run: |
docker build -t yt-plugin .
- name: Tag Docker image
if: success()
run: |
docker tag yt-plugin:latest public.ecr.aws/m3t3s7a1/yt-plugin:latest
- name: Push Docker image to AWS ECR
if: success()
run: |
docker push public.ecr.aws/m3t3s7a1/yt-plugin:latest
# Zip the required files
- name: Zip files for deployment
if: success()
run: |
zip -r deployment.zip appspec.yml deploy/scripts/install_dependencies.sh deploy/scripts/start_docker.sh deploy/scripts/download_env.sh
# Upload the ZIP file to S3
- name: Upload ZIP and secret to S3
if: success()
env:
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }}
run: |
aws s3 cp deployment.zip s3://ytcodedeploybucket/deployment.zip
echo "DAGSHUB_PAT=${{ secrets.DAGSHUB_PAT }}" > /tmp/dagshub.env
aws s3 cp /tmp/dagshub.env s3://ytcodedeploybucket/dagshub.env
# Deploy to AWS CodeDeploy using the uploaded ZIP file
- name: Deploy to AWS CodeDeploy
if: success()
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 deploy create-deployment \
--application-name YT-Plugin \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name YT-Plugin-Deployment-Group \
--s3-location bucket=ytcodedeploybucket,key=deployment.zip,bundleType=zip \
--file-exists-behavior OVERWRITE \
--region eu-north-1