Skip to content

Commit

Permalink
Merge pull request #4 from tryolabs/feature/part4
Browse files Browse the repository at this point in the history
Feature/part4
  • Loading branch information
FlorenciaOjeda authored Jun 27, 2024
2 parents 45cd720 + 29e4e53 commit 3fd0eb0
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 17 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: 'Continuous Delivery'

on:
push:
branches:
- "main"

jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3

# Authenticate to Google Cloud
- name: Authenticate to Google Cloud
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
run: |
echo "$GOOGLE_CREDENTIALS" > /tmp/google-credentials.json
gcloud auth activate-service-account --key-file=/tmp/google-credentials.json
# Build and push Docker image
- name: Build and push Docker image
env:
CONTAINER_IMAGE_URL: ${{ secrets.CONTAINER_IMAGE_URL }}
GCLOUD_REGION: ${{ secrets.GCLOUD_REGION }}
run: |
docker build -t $CONTAINER_IMAGE_URL:latest .
gcloud auth configure-docker $GCLOUD_REGION
docker push $CONTAINER_IMAGE_URL:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3

# Authenticate to Google Cloud
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'

# Deploy container to Cloud Run and capture URL
- name: Deploy container to Cloud Run
env:
CONTAINER_IMAGE_URL: ${{ secrets.CONTAINER_IMAGE_URL }}
GCLOUD_REGION: ${{ secrets.GCLOUD_REGION }}
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
id: deploy
run: |
echo "Deployment running."
URL=$(gcloud run deploy latam-challenge \
--image=$CONTAINER_IMAGE_URL:latest \
--platform=managed \
--allow-unauthenticated \
--region=$GCLOUD_REGION \
--port=8000 \
--project=$GCLOUD_PROJECT_ID \
--format="value(status.url)")
echo "::set-output name=url::$URL"
echo "Image URL: $URL"
# Set STRESS_URL environment variable for later use
- name: Set STRESS_URL as env variable to use later the Makefile
run: echo "STRESS_URL=${{ steps.deploy.outputs.url }}" >> $GITHUB_ENV

# Run stress tests
- name: Run stress tests
run: |
make stress-test STRESS_URL=${{ env.STRESS_URL }}
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Continuous Integration'

on:
pull_request:
branches:
- "develop"

jobs:
test:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3

# Setup Python
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

# Cache dependencies to speed up workflow
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt -r requirements-test.txt
# Run tests
- name: Run tests
run: |
make model-test
make api-test
19 changes: 19 additions & 0 deletions challenge/training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pandas as pd

from sklearn.model_selection import train_test_split
from challenge.model import DelayModel

model = DelayModel()
data = pd.read_csv(filepath_or_buffer="data/data.csv")

features, target = model.preprocess(
data=data,
target_column="delay"
)

_, features_validation, _, target_validation = train_test_split(features, target, test_size = 0.33, random_state = 42)

model.fit(
features=features,
target=target
)
1 change: 0 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pytest~=6.2.5
pytest-cov~=2.12.1
mockito~=1.2.2
Jinja2~=3.0.3
Flask~=2.0.3
itsdangerous==2.0.1
Werkzeug==2.0.3

4 changes: 2 additions & 2 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestModel(unittest.TestCase):
def setUp(self) -> None:
super().setUp()
self.model = DelayModel()
self.data = pd.read_csv(filepath_or_buffer="../data/data.csv")
self.data = pd.read_csv(filepath_or_buffer="data/data.csv")


def test_model_preprocess_for_training(
Expand Down Expand Up @@ -100,4 +100,4 @@ def test_model_predict(

assert isinstance(predicted_targets, list)
assert len(predicted_targets) == features.shape[0]
assert all(isinstance(predicted_target, int) for predicted_target in predicted_targets)
assert all(isinstance(predicted_target, int) for predicted_target in predicted_targets)
7 changes: 0 additions & 7 deletions workflows/cd.yml

This file was deleted.

7 changes: 0 additions & 7 deletions workflows/ci.yml

This file was deleted.

0 comments on commit 3fd0eb0

Please sign in to comment.