Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions #30

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Backend model CI/CD

run-name: Action executed by ${{ github.actor }} - Backend CI/CD

on:
push:
branches:
- main
- github-actions
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
run: pip install pytest mlflow python-dotenv

- name: Run training tests
run: |
pytest tests/test_mlflow.py
pytest tests/test_train_model.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 data
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
58 changes: 58 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Frontend CI/CD

run-name: Action executed by ${{ github.actor }} - Frontend CI/CD

on:
push:
paths:
- 'src/web/**'
branches:
- main
- github-actions
pull_request:
paths:
- 'src/web/**'
branches:
- main

jobs:

cd_push_to_dockerhub:
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: Install packages # Install dependencies
run: pip install docker

- name: Docker login
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}

- name: Build
run: docker build -f Dockerfile-frontend.txt . -t app-beans-frontend-github-actions

- name: Tags
run: |
docker tag app-beans-frontend-github-actions ${{ secrets.DOCKER_USER }}/app-beans-frontend-github-actions:${{ github.sha }}
docker tag app-beans-frontend-github-actions ${{ secrets.DOCKER_USER }}/app-beans-frontend-github-actions:latest

- name: Push
run: |
docker push ${{ secrets.DOCKER_USER }}/app-beans-frontend-github-actions:${{ github.sha }}
docker push ${{ secrets.DOCKER_USER }}/app-beans-frontend-github-actions:latest
21 changes: 0 additions & 21 deletions .github/workflows/main.yml

This file was deleted.

19 changes: 13 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
flake8==6.0.0
numpy==1.24.2
numpy~=1.23.5
scikit-learn==1.3.0
codecarbon==2.3.1
pynblint==0.1.5
#pynblint==0.1.5
great_expectations==0.17.22
Pillow==10.0
pytest==7.4.3
torchvision==0.16.1
torchvision~=0.16.0
python-multipart==0.0.6
fastapi==0.68.0
fastapi~=0.104.1
uvicorn[standard]==0.24.0.post1
httpx==0.21.0
datasets==2.15.0
Flask==3.0.0
datasets~=2.14.5
dvc>=3.0.0
docker==6.1.3
torch~=2.1.0
pydantic~=1.10.13
flask~=3.0.0
python-dotenv~=1.0.0
pandas~=2.0.3
mlflow~=2.8.0
2 changes: 1 addition & 1 deletion tests/test_train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_epoch_loss():

def test_accuracy_threshold():
for index, row in runs_final.iterrows():
assert row["metrics.test_accuracy"]>70, "Model accuracy under threshold, review model architecture"
assert row["metrics.validation_accuracy"]>70, "Model accuracy under threshold, review model architecture"

def test_artifacts():
for index, row in runs_final.iterrows():
Expand Down