Skip to content

Commit

Permalink
Version 0.1 merge (#9)
Browse files Browse the repository at this point in the history
* Add gitignore

* Add packaging files

* Add formatting to python script files

* Fixes to make notebook work

* Notebook review, challange updated.

* Fix data loading directory for test

* update gitignore

* fix prediction test

* Add comment to challange.md

* Passed models tests

* Add poetry lock file

* Fix model bugs

* Additional model improvements

* Remove ipdb from model training.

* Update fastapi version

* Add api

* Update gitignore

* Removed unused imports

* Update model storing directory

* Chande model loading

* Change directory for storing the model

* Update poetry with appropriate versions

* Add dockerfile

* Update dockerfile command

* Add deploy script, and docker fix

* update library version for stress test

* update stress tests url

* Update doc

* Add copy of model to dockerfile

* Update dockerfile and poetry lock

* Add change to dockerfile

* Add training to deploy script

* Moved ci/cd files to appropriate directory.

* First ci update

* Add paths to testing

* Add .github folder to trigger

* add '' to paths

* Add commands to ci

* Fix syntax error

* Add module files to needed paths

* setup python version

* Check directory

* Checkout code

* Fix installation

* add virtualenv folder to executing machine

* Add test dependencies to poetry

* Modified dependencies installation

* Add model retrival

* Add api test

* rename job

* Add cd workflow

* Fix syntax error

* Check secret upload

* Add gcp authentication

* Add github actions workflows to PRs on main.
  • Loading branch information
Bear-Witness-98 authored Jul 19, 2024
1 parent 8377c97 commit a63f7b3
Show file tree
Hide file tree
Showing 19 changed files with 4,906 additions and 336 deletions.
15 changes: 15 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[flake8]
# select all
select = A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
max-line-length = 88
inline-quotes = double
exclude = .venv, .git, .eggs, __pycache__, build, dist, __init__.py, .ipynb, .ipynb_checkpoints
ignore =
# disable, whitespace before ':'
E203,
# disable "too many leading '#' for block comment"
E266,
# disable "line break before binary operator" which clashes with black
W503,
# disable "invalid escape sequence"
W605,
48 changes: 48 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'Continuous Delivery'

on:
pull_request:
branches:
- develop
- main
paths:
- 'challenge/**'
- 'scripts/**'
- '.github/**'
- 'pyproject.toml'
- 'poetry.lock'

jobs:
run_testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Google Cloud SDK
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_CREDENTIAL }}
- name: Check directory
run: |
ls
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10.8'
- name: Python version
run: |
python --version
- name: Install poetry and virtualenv
run: |
pip install poetry
- name: Install dependencies
run: |
poetry config virtualenvs.create false
poetry lock --no-update
poetry install
- name: Push to prod
run: |
bash scripts/deploy.sh
- name: Run stress test
run: |
make stress-test
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 'Continuous Integration'

on:
pull_request:
branches:
- develop
- main
paths:
- 'challenge/**'
- 'scripts/**'
- '.github/**'
- 'pyproject.toml'
- 'poetry.lock'

jobs:
run_testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check directory
run: |
ls
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10.8'
- name: Python version
run: |
python --version
- name: Install poetry and virtualenv
run: |
pip install poetry
- name: Install dependencies
run: |
poetry config virtualenvs.create false
poetry lock --no-update
poetry install
- name: Get model
run:
python challenge/model.py
- name: Run model test
run: |
make model-test
- name: Run api test
run: |
make api-test
165 changes: 165 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

reports/*
*.pkl
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.8
40 changes: 40 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
// Set correct python path to venv's one
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
// Hide .venv from explorer and searchbar
"files.watcherExclude": {
"**/.venv/**": true
},
"files.exclude": {
"**/.venv/": true
},
"search.exclude": {
"**/.venv/": true
},
// Linting and formatting
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
// auto formatter
"black-formatter.importStrategy": "fromEnvironment",
// import formatter
"isort.importStrategy": "fromEnvironment",
"isort.args": [
"--settings-path",
"${workspaceFolder}/pyproject.toml"
],
// linting
"flake8.importStrategy": "fromEnvironment",
"flake8.args": [
"--config=${workspaceFolder}/.flake8"
],
"editor.wordWrapColumn": 100,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
//
// Jupyter
//
"jupyter.notebookFileRoot": "${workspaceFolder}",
"jupyter.interactiveWindow.textEditor.executeSelection": true,
}
23 changes: 21 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# syntax=docker/dockerfile:1.2
FROM python:latest
# put you docker configuration here
FROM python:3.10.11
# put you docker configuration here

WORKDIR /module
RUN apt update && apt install -y build-essential
RUN pip install poetry

# copy all stuff into container
COPY challenge/ ./challenge
COPY pyproject.toml/ .
COPY poetry.lock .
COPY models/ ./models

# add empty README and install
RUN touch README.md
RUN poetry config virtualenvs.create false
RUN poetry lock --no-update
RUN poetry install --only main


CMD ["python", "-m", "uvicorn", "challenge.api:app", "--host", "0.0.0.0", "--port", "8080"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ install: ## Install dependencies
pip install -r requirements-test.txt
pip install -r requirements.txt

STRESS_URL = http://127.0.0.1:8000
STRESS_URL = https://delay-model-api-qzo5moezqa-uw.a.run.app
.PHONY: stress-test
stress-test:
# change stress url to your deployed app
# change stress url to your deployed app
mkdir reports || true
locust -f tests/stress/api_stress.py --print-stats --html reports/stress-test.html --run-time 60s --headless --users 100 --spawn-rate 1 -H $(STRESS_URL)

Expand Down
Loading

0 comments on commit a63f7b3

Please sign in to comment.