Skip to content

Commit 9fe3171

Browse files
committed
Create CD pipeline
1 parent 73b799b commit 9fe3171

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

.github/workflows/cd.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Continuous Deployment'
2+
3+
#on:
4+
# push:
5+
# branches:
6+
# - main
7+
# - develop
8+
# - release/*
9+
on: [push, pull_request]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Get the branch name
19+
run: |
20+
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
21+
id: get_branch_name
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.9'
27+
28+
- name: Authenticate to GCP
29+
uses: 'google-github-actions/auth@v2'
30+
with:
31+
credentials_json: '${{ secrets.CD_SA_KEYS }}'
32+
33+
- name: Install dependencies
34+
run: |
35+
pip install -r requirements.txt -r requirements-dev.txt -r requirements-test.txt
36+
37+
- name: Run training script
38+
run: |
39+
python train.py
40+
41+
- name: Authenticate Docker to GAR
42+
uses: docker/login-action@v3
43+
with:
44+
registry: '${{ vars.GCP_REGION }}-docker.pkg.dev'
45+
username: _json_key
46+
password: ${{ secrets.CD_SA_KEYS }}
47+
48+
- name: Build and push Docker image
49+
uses: docker/build-push-action@v6
50+
with:
51+
push: true
52+
tags: '${{ vars.GAR_REPOSITORY }}/${{ vars.GAR_IMAGE_NAME }}'

docs/challenge.md

+2
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ The CI workflows focus on running the tests and assesing the quality of the code
133133
The CD workflows focus on training the model, deploying the API and running the stress testing against it. These workflows only run when there's a push to the `main`, `develop` or `release` branches on the repository.
134134
135135
* Undesirable model tracking
136+
* env variables ci/cd
137+
* makefile argument

train.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from challenge.model import DelayModel
2+
import pandas as pd
3+
4+
print("Loading data...")
5+
# Read the data
6+
df = pd.read_csv("data/data.csv")
7+
print("-> Data loaded")
8+
9+
# Create the model
10+
model = DelayModel()
11+
12+
print("Preprocessing data...")
13+
# Preprocess the data
14+
X_train, y_train = model.preprocess(df, "delay")
15+
print("-> Preprocessed data")
16+
17+
18+
print("Training model...")
19+
# Train the model
20+
model.fit(X_train, y_train)
21+
print("-> Model trained")
22+
23+
print("Saving model...")
24+
# Store the model
25+
model.save("challenge/tmp/model_checkpoint.pkl")
26+
print("-> Model saved")

0 commit comments

Comments
 (0)