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

Dev #13

Merged
merged 39 commits into from
Oct 2, 2024
Merged

Dev #13

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9955546
flake8 script corrected
Apr 21, 2023
d69e65b
fixes
Apr 21, 2023
cc7a952
pr checker
Apr 21, 2023
944c429
db
Apr 21, 2023
937d06d
resolved black issue
Apr 21, 2023
1e9bb4d
Merge pull request #1 from CyrilBaah/fixes
CyrilBaah Apr 21, 2023
94c5279
sample test
May 9, 2023
331f67a
Merge pull request #2 from CyrilBaah/test
CyrilBaah May 9, 2023
bc368ba
correct test
May 9, 2023
d558a9d
changes
May 9, 2023
247bfd6
linter fixes
May 9, 2023
08a44a5
branch changes
May 9, 2023
12d81e0
Merge pull request #4 from CyrilBaah/test
CyrilBaah May 15, 2023
b519a5d
docs API
May 15, 2023
b73ff52
containerization
May 15, 2023
3568ed2
manifest files
May 16, 2023
30f8d02
update service version
May 16, 2023
05bd521
Updated Readme
May 16, 2023
8f24fce
files changes
May 16, 2023
3615639
Readme
May 16, 2023
c8847e1
Merge pull request #5 from CyrilBaah/k8s
CyrilBaah May 16, 2023
fdff8b4
Readme | configure ingress
May 16, 2023
50f04b8
server dashboard
May 16, 2023
09acae3
workout seeders | Readme
May 16, 2023
b58c9e6
Merge pull request #6 from CyrilBaah/k8s
CyrilBaah May 16, 2023
0ec5748
readme db postgres
May 17, 2023
58ff10a
Merge pull request #9 from CyrilBaah/k8s
CyrilBaah May 17, 2023
7f19630
manifest file
Jul 27, 2023
338658f
Merge pull request #10 from CyrilBaah/k8s
CyrilBaah Jul 27, 2023
e0ca0d5
remove deploy
Sep 21, 2023
55579ad
Merge pull request #11 from CyrilBaah/k8s
CyrilBaah Sep 21, 2023
0ffb020
env.example
Sep 21, 2023
ece3297
Add health status
Sep 21, 2023
4276569
create Makefile
Baahcy Sep 21, 2023
e72c89a
modify k8s files
Baahcy Sep 21, 2023
fa456db
expose service
Baahcy Sep 22, 2023
ad407b5
ops files
Baahcy Sep 22, 2023
dde9f85
makefile updated
Baahcy Sep 23, 2023
df01e25
Merge pull request #12 from CyrilBaah/k8s
CyrilBaah Sep 23, 2023
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
71 changes: 71 additions & 0 deletions .github/workflows/pr-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Pull Request Checker

on:
push:
branches: [ main, staging ]
pull_request:
branches: [ dev, staging, main ]

jobs:
build:
runs-on: ubuntu-latest

env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
TEST_DATABASE_PREFIX: test_

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests
run: |
python manage.py test

# - name: Run Flake8
# run: |
# flake8

- name: Run Black
run: |
black --check .

- name: Run isort
run: |
isort --check-only .

# - name: Generate coverage report
# run: |
# coverage run --source='.' manage.py test
# coverage report -m

# - name: Upload coverage report to Codecov
# uses: codecov/[email protected]
# with:
# flags: unittests
# fail_ci_if_error: true
# name: codecov-report
# files: coverage.xml
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,7 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

file.txt
file.txt
configmapexample.yml
secretsexample.yml
deploy.yml
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.8-slim-buster

# Python environment setup
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Create and set working directory
ENV PROJECT=/home/app

RUN mkdir -p ${PROJECT}
RUN mkdir -p ${PROJECT}/static
WORKDIR ${PROJECT}

# Packages required for setting up WSGI
RUN apt-get update
RUN apt-get install -y --no-install-recommends gcc libc-dev python3-dev

# Copy and install requirements
RUN pip install --upgrade pip
COPY ./requirements.txt ${PROJECT}/requirements.txt
RUN pip install -r ${PROJECT}/requirements.txt

# Copy project to working directory
COPY . ${PROJECT}

EXPOSE 8000

RUN chmod +x ./entrypoint.sh
ENTRYPOINT ["sh", "/home/app/entrypoint.sh"]

111 changes: 111 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Define variables
CLUSTER_NAME := dev
IMAGE_NAME := fitnesstracker
CONTAINER_NAME := fitnesstracker
PORT := 8000

.PHONY: create-cluster get-cluster set-context delete-cluster install-nginxingresscontroller get-nginxingress get-logs cluster-info get-nodes get-pods expose-frontend build run stop remove remove-image ps ps-all images exec clean help

create-cluster:
@echo "Creating Kind cluster..."
kind create cluster --config config.yml --name $(CLUSTER_NAME)

get-cluster:
@echo "Getting Kind clusters..."
kind get clusters

set-context:
@echo "Setting kubectl context to $(CLUSTER_NAME)..."
kubectl config use-context kind-$(CLUSTER_NAME)

delete-cluster:
@echo "Deleting Kind cluster..."
kind delete cluster --name $(CLUSTER_NAME)

push-image:
docker push cyrilbaah/fitnesstracker:latest

install-nginxingresscontroller:
@echo "Install NGINX Ingress Controller..."
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

get-nginxingress:
@echo "Get nginxingress pods..."
kubectl get pods -n ingress-nginx -owide

get-logs:
@echo "Get pods for logs command..."
@echo "$ kubectl logs -f <name-app-xxx>"

cluster-info:
@echo "Get cluster information..."
kubectl cluster-info --context kind-$(CLUSTER_NAME)

get-nodes:
@echo "Get cluster nodes..."
kubectl get nodes -owide

get-pods:
@echo "Get cluster pods..."
kubectl get pods -owide

expose-backend:
@echo "Get port for backend..."
kubectl port-forward svc/$(CONTAINER_NAME) -n default 8000:8000

build:
docker build -t cyrilbaah/$(IMAGE_NAME) .

run:
docker run -d -p $(PORT):$(PORT) --name $(CONTAINER_NAME) $(IMAGE_NAME)

stop:
docker stop $(CONTAINER_NAME)

remove:
docker rm $(CONTAINER_NAME)

remove-image:
docker rmi $(IMAGE_NAME)

ps:
docker ps

ps-all:
docker ps -a

images:
docker images

exec:
docker exec -it $(CONTAINER_NAME) bash

clean:
docker stop $(shell docker ps -aq) || true
docker rm $(shell docker ps -aq) || true
docker rmi $(shell docker images -aq) || true

help:
@echo "Available targets:"
@echo " create-cluster - Create the Kind cluster"
@echo " get-cluster - List available Kind clusters"
@echo " set-context - Set kubectl context to the Kind cluster"
@echo " delete-cluster - Delete the Kind cluster"
@echo " get-pods - List all pods"
@echo " get-nodes - List all nodes"
@echo " expose-backend - Makes backend app accessible"
@echo " get-nginxingress - List all nginx ingress"
@echo " get-logs - Get logs command"
@echo " build - Build Docker image"
@echo " run - Run Docker container in detached mode"
@echo " stop - Stop Docker container"
@echo " remove - Remove Docker container"
@echo " remove-image - Remove Docker image"
@echo " ps - View running containers"
@echo " ps-all - View all containers (including stopped ones)"
@echo " images - View Docker images"
@echo " exec - Execute a command inside the running container"
@echo " clean - Clean up (stop and remove) all containers and images"
@echo " help - Display this help message"

.DEFAULT_GOAL := help
71 changes: 67 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Fitness Tracker
## How to set up locally using Docker container - **Recommended**
### Prerequisite
- Make sure **Docker** is installed locally. *Checkout installation here* [Docker](https://www.docker.com/ "Docker")
- Make sure **Mysql** is installed locally. *Checkout installation here* [Mysql](https://www.mysql.com/ "Mysql")
- Make sure **Postgres** is installed locally. *Checkout installation here* [Postgres](https://www.postgresql.org/ "Postgres")

1. Clone the project.
```sh
git clone
git clone https://github.com/CyrilBaah/fitnesstracker.git
```
```sh
cd
cd fitnesstracker
```
2. Change the env.example file to .env .
3. Run
Expand Down Expand Up @@ -51,8 +51,71 @@ Fitness Tracker
```sh
./manage seed_nutritions
```

- Workout
```sh
./manage seed_workouts
```
## Generate documentation
```sh
./manage.py spectacular --color --file schema.yml
```

## Documentation API
http://127.0.0.1:8000/api/schema/docs

## Generate Secret Key
```sh
./scripts/run-secretkey.sh
```

## Run kubernetes Manifest files
### Make sure on of the following is installed
- **Minikube** is installed. *Checkout installation here* [Minikube](https://minikube.sigs.k8s.io/docs/ "Minikube")
- **Kind** is installed. *Checkout installation here* [Kind](https://kind.sigs.k8s.io/ "Kind")

```sh
$ kubectl apply -f ops/
```

## Serve the application
```sh
$ kubectl port-forward service/fitnesstracker 8000:8000
```

## Serve minikube server | Dashboard
```sh
$ minikube dashboard --url
```
## Get Node Address

```sh
$ kubectl get service fitnesstracker -o jsonpath='{.spec.clusterIP}'
```

```sh
$ kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}'
```

## Configure Ingress
Get ClusterIP
```sh
$ kubectl get service fitnesstracker
```
Modify /etc/hosts
```sh
$ sudo nano /etc/hosts
```
Add cluster IP to /etc/hosts
```bash
123.456.7.8 fitnesstracker.com
```

## Use [KinD](https://kind.sigs.k8s.io/ "KinD")
1. Run
```
make create-cluster
```
2. Install Nginx Ingress Controller
```
make install-nginxingresscontroller
```
19 changes: 0 additions & 19 deletions accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,6 @@ def validate(self, data):
pass
raise serializers.ValidationError("Incorrect Credentials")

# def validate(self, data):
# # Check if a password was provided
# if 'password' in data:
# user = authenticate(**data)
# if user and user.is_active:
# return user
# else:
# # If no password was provided, try to authenticate using Google ID
# try:
# if 'google_id' in data:
# user = authenticate(**data)

# # user = CustomUser.objects.get(email=data['email'], google_id__isnull=False)
# if user and user.is_active:
# return user
# except CustomUser.DoesNotExist:
# pass
# raise serializers.ValidationError("Incorrect Credentials")


class ChangePasswordSerializer(serializers.Serializer):
"""Change password Serializer"""
Expand Down
3 changes: 0 additions & 3 deletions accounts/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.test import TestCase

# Create your tests here.
9 changes: 3 additions & 6 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth import get_user_model
from rest_framework import status
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView, UpdateAPIView
from rest_framework.generics import GenericAPIView, UpdateAPIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_simplejwt.tokens import RefreshToken

from .models import CustomUser
from .serializers import (
ChangePasswordSerializer,
CustomUserSerializer,
Expand Down Expand Up @@ -178,5 +175,5 @@ def post(self, request, *args, **kwargs):
"data": [],
}
return Response(response, status=status.HTTP_205_RESET_CONTENT)
except Exception as e:
except Exception:
return Response(status=status.HTTP_400_BAD_REQUEST)
Loading
Loading