Skip to content

Commit

Permalink
Merge pull request #13 from CyrilBaah/dev
Browse files Browse the repository at this point in the history
Add Ops files
  • Loading branch information
CyrilBaah authored Oct 2, 2024
2 parents 540010c + df01e25 commit eedd5ca
Show file tree
Hide file tree
Showing 41 changed files with 689 additions and 60 deletions.
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

0 comments on commit eedd5ca

Please sign in to comment.