-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (83 loc) · 3.34 KB
/
backend.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
name: Backend model CI/CD
run-name: Action executed by ${{ github.actor }} - Backend CI/CD
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
ci_build_and_test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Environment setup # Set up with a specific version of Python
uses: actions/setup-python@v4
with:
python-version: 3.8
cache: pip
- name: Cache # Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-
- name: Create .env file
run: |
echo "MLFLOW_TRACKING_URI=${{ secrets.MLFLOW_TRACKING_URI }}" >> .env
echo "MLFLOW_TRACKING_USERNAME=${{ secrets.MLFLOW_TRACKING_USERNAME }}" >> .env
echo "MLFLOW_TRACKING_PASSWORD=${{ secrets.MLFLOW_TRACKING_PASSWORD }}" >> .env
- name: Install packages # Install dependencies needed for tests (not for whole project)
run: pip install pytest mlflow python-dotenv fastapi httpx torch torchvision pydantic python-multipart dvc
- name: Pull model
run: |
dvc remote modify origin --local auth basic
dvc remote modify origin --local user ${{ secrets.DAGSHUB_USERNAME }}
dvc remote modify origin --local password ${{ secrets.DAGSHUB_TOKEN }}
dvc pull -r origin models/trained_model.pt
- name: Run tests
run: |
pytest tests/test_mlflow.py
pytest tests/test_train_model.py
pytest tests/test_api.py
continue-on-error: false
cd_push_to_dockerhub:
needs: ci_build_and_test
runs-on: ubuntu-latest
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Environment setup # Set up with a specific version of Python
uses: actions/setup-python@v4
with:
python-version: 3.8
cache: pip
- name: Cache # Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-
- name: Install packages # Install dependencies
run: pip install dvc docker
- name: Pull model
run: |
dvc remote modify origin --local auth basic
dvc remote modify origin --local user ${{ secrets.DAGSHUB_USERNAME }}
dvc remote modify origin --local password ${{ secrets.DAGSHUB_TOKEN }}
dvc pull -r origin models/trained_model.pt
- name: Docker login
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Build
run: docker build -f Dockerfile-backend.txt . -t app-beans-backend-github-actions
- name: Tags
run: |
docker tag app-beans-backend-github-actions ${{ secrets.DOCKER_USER }}/app-beans-backend-github-actions:${{ github.sha }}
docker tag app-beans-backend-github-actions ${{ secrets.DOCKER_USER }}/app-beans-backend-github-actions:latest
- name: Push
run: |
docker push ${{ secrets.DOCKER_USER }}/app-beans-backend-github-actions:${{ github.sha }}
docker push ${{ secrets.DOCKER_USER }}/app-beans-backend-github-actions:latest