Git Product home page Git Product logo

cw_django_dev's Introduction

Claritywave challenge

GitHub Workflow Status (with event) Codacy Badge Codacy Badge

Author: CW-TEAM

Setting up

Local Development

Poetry

Setting up .venv enviroment with poetry for python 3.11

poetry config virtualenvs.in-project true
pyenv local 3.11.0
poetry shell 
poetry install 

This project uses ruff as a formatter and linter

ruff check . --fix
ruff format .

Testing

They are found in the ./tests/ path.

pytest

Database

Sqlite for local developemen and test

Production

Kubernetes configurations files are defined in ./deploy/.

Commands

Use the following example to create dummy data:

python manage.py create_dummy_data

It'll help you to setup two users

username pass
user_1 123
user_2 123

There is a command to update the ranking of the questions that are no longer of the current day

python manage.py update_daily_ranking

About the strategy to solve the daily ranking

There so many ways to approach this problem, I could setup a unix cron job, django celery beat, update the ranking on every request with a background task, but I decided to make it part of the kubernetes deployment using its cronjob resource. I do believe that making optimistic updateds in an frequent interval doesn't impact the database, I probably should make and index with created and is_from_today.

About the current deployment

This project is deployed in an EC2 Instance running kubernetes cluster using minikube with a Postgres Database. There are some security group rules to access the kubernetes cluster server and the app deployed. Given that this is a toy deployment there are some security and best practices concerns, i.e., minikube is not for production, but for now, it gets the job done.

For learning purposes I decided to go for this approach instead of using docker swarm or just deploy the app on bare metal. Also this a list of this to improve:

  • CI
  • Make a better github action ci to reuse the docker cache from previous jobs
  • Set up rules to run specific jobs based on branches o releases
  • Test workflow to use a postgress db
  • Load testing
  • E2E
  • CD
  • Set up manual deployments, that requires approvals
  • Integrate a real GitOps strategy with... maybe... "argocd"
  • Analysis and monitor tools
  • APP
  • Django is a nice web framework, but if my views have some interaction with apis (to monitor or performance), I will consider decoupling the frontend from it.

  • For the previous reason mentionen above I used django-ninja instead of rest-framework, but I'll choose a typed library if I will interact with too many developers or I'll update the app the next year.

About tasks

An effort list recollection, gitops is my weak point, since I implemented it on the fly, anyway it was a nice weekend.

task effort
application analysis 2h
application fix 3h
application tests 3h
ci 8h
cd (Learning is a fun process) 12h 🤓☝

Play with it

You can interact with it here: DEPLOYED APP, you can use any of this users:

username pass
user_1 123
user_2 123

Also the cron job that update the ranking is creating a question every two minutes.

For security reasons I'll not provide access to ec2 where this is app deployed, but I'll share some terminal text related to this deployment:

ubuntu@ip-172-31-85-44:~$ docker ps
CONTAINER ID   IMAGE                                 COMMAND                  CREATED        STATUS        PORTS                                                                                                                        NAMES
674531872cbd   nginx:latest                          "/docker-entrypoint.…"   3 hours ago    Up 3 hours                                                                                                                                 nginx-base
b89d7243f2e8   gcr.io/k8s-minikube/kicbase:v0.0.42   "/usr/local/bin/entr…"   11 hours ago   Up 11 hours   0.0.0.0:32797->22/tcp, 0.0.0.0:32796->2376/tcp, 0.0.0.0:32795->5000/tcp, 0.0.0.0:32794->8443/tcp, 0.0.0.0:32793->32443/tcp   minikube
ubuntu@ip-172-31-85-44:~$
ubuntu@ip-172-31-85-44:~$ kubectl get deploy
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
cw-base    1/1     1            1           50m
postgres   1/1     1            1           4h52m
ubuntu@ip-172-31-85-44:~$ kubectl get po
NAME                       READY   STATUS      RESTARTS   AGE
cw-base-6cf85f7c89-9gr7r   1/1     Running     0          51m
cw-cron-28361524-9zwff     0/1     Completed   0          18s
postgres-58488bc-rvpmg     1/1     Running     0          4h52m
ubuntu@ip-172-31-85-44:~$ kubectl get job
NAME               COMPLETIONS   DURATION   AGE
cw-cron-28361524   1/1           6s         21s

cw_django_dev's People

Contributors

enfasis avatar claritywave avatar kaajavi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.