Skip to content

Commit

Permalink
feat[readme]: Update Readme.md with changes (#5)
Browse files Browse the repository at this point in the history
* feat[readme]: Update Readme.md with changes

* change[readme]: Change language to ENG

* change[readme]: Add diagrams

* docs[license]: Add LICENSE and CONTRIBUTING.md

* fix[readme]: Update diagrams links
  • Loading branch information
Adriana618 authored Jul 20, 2024
1 parent 25b0771 commit c150474
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 136 deletions.
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing to DevOps Demo Project

First off, thanks for taking the time to contribute!

The following is a set of guidelines for contributing to the DevOps Demo Project. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

## How Can I Contribute?

### Reporting Bugs

This section guides you through submitting a bug report for the DevOps Demo Project. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.

Before creating a bug report, please check if there are any existing issues that describe the problem you're experiencing. When you create a bug report, be sure to include as many details as possible.

### Suggesting Enhancements

This section guides you through submitting an enhancement suggestion for the DevOps Demo Project, including completely new features and minor improvements to existing functionality.

Before suggesting an enhancement, please check the open issues to see if a similar suggestion has already been made.

### Pull Requests

The process described here has several goals:

- Maintain the project's quality
- Fix problems that are important to users
- Engage the community in working toward the best possible solutions

Please follow these steps to have your contribution considered by the maintainers:

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Write clear, concise commit messages.
4. Create a pull request.

Thank you for your contributions!

## Code of Conduct

This project and everyone participating in it is governed by the DevOps Demo Project Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [[email protected]].
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
236 changes: 100 additions & 136 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,139 +1,103 @@
# Demo Devops Python

This is a simple application to be used in the technical test of DevOps.

## Getting Started

### Prerequisites

- Python 3.11.3

### Installation

Clone this repo.

```bash
git clone https://bitbucket.org/devsu/demo-devops-python.git
```

Install dependencies.

```bash
pip install -r requirements.txt
```

Migrate database

```bash
py manage.py makemigrations
py manage.py migrate
```

### Database

The database is generated as a file in the main path when the project is first run, and its name is `db.sqlite3`.

Consider giving access permissions to the file for proper functioning.

## Usage

To run tests you can use this command.

```bash
py manage.py test
```

To run locally the project you can use this command.

```bash
py manage.py runserver
```

Open http://localhost:8000/api/ with your browser to see the result.

### Features

These services can perform,

#### Create User

To create a user, the endpoint **/api/users/** must be consumed with the following parameters:

```bash
Method: POST
```

```json
{
"dni": "dni",
"name": "name"
}
```

If the response is successful, the service will return an HTTP Status 200 and a message with the following structure:

```json
{
"id": 1,
"dni": "dni",
"name": "name"
}
```

If the response is unsuccessful, we will receive status 400 and the following message:

```json
{
"detail": "error"
}
```

#### Get Users

To get all users, the endpoint **/api/users** must be consumed with the following parameters:

```bash
Method: GET
```

If the response is successful, the service will return an HTTP Status 200 and a message with the following structure:

```json
[
{
"id": 1,
"dni": "dni",
"name": "name"
}
]
```

#### Get User

To get an user, the endpoint **/api/users/<id>** must be consumed with the following parameters:

```bash
Method: GET
```

If the response is successful, the service will return an HTTP Status 200 and a message with the following structure:

```json
{
"id": 1,
"dni": "dni",
"name": "name"
}
```

If the user id does not exist, we will receive status 404 and the following message:

```json
{
"detail": "Not found."
}
```
# Demo DevOps Python Application

This repository contains a simple Django application that demonstrates various DevOps practices. The application is deployed on a Kubernetes cluster using Helm and GitHub Actions for CI/CD pipelines.

## Table of Contents
- [Architecture](#architecture)
- [Tools](#Tools)
- [Setup Instructions](#setup-instructions)
- [CI/CD Pipelines](#ci-cd-pipelines)
- [Kubernetes Deployment](#kubernetes-deployment)
- [Contributing](#contributing)
- [License](#license)

## Architecture

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 [`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](https://lucid.app/publicSegments/view/5f85d354-b853-494c-b0aa-f24e1dfe826c/image.png)

## 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.

## 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
```
# 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/dev.txt
```
# 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/1c2e5da3-7498-412c-abdc-838d29c90397/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-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/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/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/devops-deemo/templates/api/api-services.yaml" target="_blank">devops-deemo/templates/api/api-services.yaml</a>

### 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

Please follow the <a href="https://github.com/Adriana618/devops-deemo/blob/master/CONTRIBUTING.md" target="_blank">contribution guidelines</a> to propose improvements or report issues.

## License

Copyright © 2023 Devsu. All rights reserved.
This project is licensed under the MIT License - see the <a href="https://github.com/Adriana618/devops-deemo/blob/master/LICENSE" target="_blank">LICENSE</a> file for details.
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 c150474

Please sign in to comment.