Skip to content

Commit

Permalink
change[readme]: Add diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriana618 committed Jul 20, 2024
1 parent 528da61 commit 8c68e74
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 32 deletions.
81 changes: 49 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,95 @@ This repository contains a simple Django application that demonstrates various D

## Table of Contents
- [Architecture](#architecture)
- [Tools](#Tools)
- [Setup Instructions](#setup-instructions)
- [CI/CD Pipelines](#ci-cd-pipelines)
- [Kubernetes Deployment](#kubernetes-deployment)
- [Infrastructure as Code](#infrastructure-as-code)
- [Monitoring and Logging](#monitoring-and-logging)
- [Contributing](#contributing)
- [License](#license)

## Architecture

The Django API is deployed on a Kubernetes cluster with the following components:
The Django API is deployed on a DigitalOcean Kubernetes cluster with the following components:
- **Deployment**: The API is deployed with 2 replicas, managed by a Horizontal Pod Autoscaler (HPA) that can scale up to 3 replicas.
- **Service Account**: A basic service account is used to follow security standards.
- **LoadBalancer**: Exposes the API to the world, accessible via the domain `https://api.algova.dev`.
- **DNS and SSL**: Managed using Route53 and Let's Encrypt. The domain `api.algova.dev` points to the LoadBalancer with automatic SSL certificate renewal.
- **LoadBalancer**: Exposes the API to the world, accessible via the domain [`api.algova.dev`](https://api.algova.dev). It may take about 1 minute.
- **DNS and SSL**: Managed using Route53 and Let's Encrypt. The domain [`api.algova.dev`](https://api.algova.dev) points to the LoadBalancer with automatic SSL certificate renewal.
- **Static Files**: Served from an S3 bucket with proper ACL configurations.

![Architecture Diagram](path/to/architecture-diagram.png)
![Architecture Diagram](https://lucid.app/publicSegments/view/216cc460-6c9f-46c7-bf47-b84b90ca15e5/image.png)

## Setup Instructions
## Tools
The following tools were used to develop this project:
- Django: Python library used to power the backend.
- Helm: Used to manage Kubernetes deployments in an organized and clean manner.
- Kubernetes: Where our API is deployed, providing scalability and security.
- Docker: Our API is containerized for easy deployment in any environment.
- Github Actions: Used to deploy our API and to test our PRs before merging.
- Pylint: Keeps our code following high standards.
- Pytest: Ensures proper testing of our API to avoid downtimes.
- Trivy: Keeps us alert to vulnerabilities in our Docker images.

1. **Clone the Repository**:
## Setup Instructions
The project was divided according to the task to be performed:
**In all cases, we must clone the repo**
```bash
git clone https://github.com/Adriana618/devops-deemo.git
cd devops-deemo
```

2. **Install Dependencies**:
# Develop:
You must have Minikube, Docker, and Helm installed.
```bash
sudo apt-get update
sudo apt-get install -y python3 python3-pip docker.io kubectl minikube
pip3 install -r requirements.txt
pip3 install -r requirements/dev.txt
```

3. **Dockerize the Application**:
# Test:
You must have Minikube, Docker, and Helm installed.
```bash
sudo apt-get update
sudo apt-get install -y python3 python3-pip docker.io kubectl minikube
pip3 install -r requirements/test.txt
```
# Deploy:
You must have a Kubernetes cluster with 2 nodes with 1CPU and 2GB of memory at a minimum.

After having the necessary setup for each stage, proceed to fill in the Helm values.yaml file or overwrite the variables at the time of installing the app.
- DJANGO_SECRET_KEY
- DATABASE_NAME='db.sqlite3'
- DJANGO_ALLOWED_HOSTS
- AWS_STORAGE_BUCKET_NAME
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION

2. **Dockerize the Application**:
- Dockerfile located at <a href="https://github.com/Adriana618/devops-deemo/blob/master/docker-conf/Dockerfile-django-api" target="_blank">docker-conf/Dockerfile-django-api</a>

## CI/CD Pipelines

[CI/CD Diagram](https://lucid.app/publicSegments/view/3f074f38-a519-47aa-adca-604faf1ecc18/image.png)

### Deploy API
This GitHub Action deploys commits merged into the `master` branch to a Kubernetes cluster on DigitalOcean.

See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/.github/workflows/deploy.yml" target="_blank">.github/workflows/deploy.yml</a>
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/.github/workflows/deploy-api.yml" target="_blank">.github/workflows/deploy-api.yml</a>

### Test PR
This GitHub Action tests pull requests by running static code analysis, code coverage, and vulnerability scans.

See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/.github/workflows/test-pr.yml" target="_blank">.github/workflows/test-pr.yml</a>
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/.github/workflows/deploy-pr.yml" target="_blank">.github/workflows/deploy-pr.yml</a>

## Kubernetes Deployment

### Deployment Configuration
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/k8s/deployment.yaml" target="_blank">k8s/deployment.yaml</a>
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/devops-deemo/templates/api/api-deployment.yaml" target="_blank">devops-deemo/templates/api/api-deployment.yaml</a>

### Service Configuration
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/k8s/service.yaml" target="_blank">k8s/service.yaml</a>

### ConfigMap and Secrets
See the files <a href="https://github.com/Adriana618/devops-deemo/blob/master/k8s/configmap.yaml" target="_blank">k8s/configmap.yaml</a> and <a href="https://github.com/Adriana618/devops-deemo/blob/master/k8s/secret.yaml" target="_blank">k8s/secret.yaml</a>

### Ingress Configuration
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/k8s/ingress.yaml" target="_blank">k8s/ingress.yaml</a>

## Infrastructure as Code

Using Terraform, the infrastructure is provisioned on AWS:

See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/terraform/main.tf" target="_blank">terraform/main.tf</a>

## Monitoring and Logging
See the file <a href="https://github.com/Adriana618/devops-deemo/blob/master/devops-deemo/templates/api/api-services.yaml" target="_blank">devops-deemo/templates/api/api-services.yaml</a>

The application is monitored using Prometheus and Grafana, with logs centralized in the ELK stack.
### Secrets
See the files <a href="https://github.com/Adriana618/devops-deemo/blob/master/devops-deemo/templates/api/api-secrets.yaml" target="_blank">devops-deemo/templates/api/api-secrets.yaml</a>

## Contributing

Expand Down
2 changes: 2 additions & 0 deletions demo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

CSRF_TRUSTED_ORIGINS = [f'https://{host}' for host in ALLOWED_HOSTS if host]

ROOT_URLCONF = "demo.urls"

TEMPLATES = [
Expand Down

0 comments on commit 8c68e74

Please sign in to comment.