Skip to content

Commit c150474

Browse files
authored
feat[readme]: Update Readme.md with changes (#5)
* 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
1 parent 25b0771 commit c150474

File tree

4 files changed

+161
-136
lines changed

4 files changed

+161
-136
lines changed

CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing to DevOps Demo Project
2+
3+
First off, thanks for taking the time to contribute!
4+
5+
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.
6+
7+
## How Can I Contribute?
8+
9+
### Reporting Bugs
10+
11+
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.
12+
13+
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.
14+
15+
### Suggesting Enhancements
16+
17+
This section guides you through submitting an enhancement suggestion for the DevOps Demo Project, including completely new features and minor improvements to existing functionality.
18+
19+
Before suggesting an enhancement, please check the open issues to see if a similar suggestion has already been made.
20+
21+
### Pull Requests
22+
23+
The process described here has several goals:
24+
25+
- Maintain the project's quality
26+
- Fix problems that are important to users
27+
- Engage the community in working toward the best possible solutions
28+
29+
Please follow these steps to have your contribution considered by the maintainers:
30+
31+
1. Fork the repository.
32+
2. Create a new branch for your feature or bugfix.
33+
3. Write clear, concise commit messages.
34+
4. Create a pull request.
35+
36+
Thank you for your contributions!
37+
38+
## Code of Conduct
39+
40+
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]].

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 100 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,103 @@
1-
# Demo Devops Python
2-
3-
This is a simple application to be used in the technical test of DevOps.
4-
5-
## Getting Started
6-
7-
### Prerequisites
8-
9-
- Python 3.11.3
10-
11-
### Installation
12-
13-
Clone this repo.
14-
15-
```bash
16-
git clone https://bitbucket.org/devsu/demo-devops-python.git
17-
```
18-
19-
Install dependencies.
20-
21-
```bash
22-
pip install -r requirements.txt
23-
```
24-
25-
Migrate database
26-
27-
```bash
28-
py manage.py makemigrations
29-
py manage.py migrate
30-
```
31-
32-
### Database
33-
34-
The database is generated as a file in the main path when the project is first run, and its name is `db.sqlite3`.
35-
36-
Consider giving access permissions to the file for proper functioning.
37-
38-
## Usage
39-
40-
To run tests you can use this command.
41-
42-
```bash
43-
py manage.py test
44-
```
45-
46-
To run locally the project you can use this command.
47-
48-
```bash
49-
py manage.py runserver
50-
```
51-
52-
Open http://localhost:8000/api/ with your browser to see the result.
53-
54-
### Features
55-
56-
These services can perform,
57-
58-
#### Create User
59-
60-
To create a user, the endpoint **/api/users/** must be consumed with the following parameters:
61-
62-
```bash
63-
Method: POST
64-
```
65-
66-
```json
67-
{
68-
"dni": "dni",
69-
"name": "name"
70-
}
71-
```
72-
73-
If the response is successful, the service will return an HTTP Status 200 and a message with the following structure:
74-
75-
```json
76-
{
77-
"id": 1,
78-
"dni": "dni",
79-
"name": "name"
80-
}
81-
```
82-
83-
If the response is unsuccessful, we will receive status 400 and the following message:
84-
85-
```json
86-
{
87-
"detail": "error"
88-
}
89-
```
90-
91-
#### Get Users
92-
93-
To get all users, the endpoint **/api/users** must be consumed with the following parameters:
94-
95-
```bash
96-
Method: GET
97-
```
98-
99-
If the response is successful, the service will return an HTTP Status 200 and a message with the following structure:
100-
101-
```json
102-
[
103-
{
104-
"id": 1,
105-
"dni": "dni",
106-
"name": "name"
107-
}
108-
]
109-
```
110-
111-
#### Get User
112-
113-
To get an user, the endpoint **/api/users/<id>** must be consumed with the following parameters:
114-
115-
```bash
116-
Method: GET
117-
```
118-
119-
If the response is successful, the service will return an HTTP Status 200 and a message with the following structure:
120-
121-
```json
122-
{
123-
"id": 1,
124-
"dni": "dni",
125-
"name": "name"
126-
}
127-
```
128-
129-
If the user id does not exist, we will receive status 404 and the following message:
130-
131-
```json
132-
{
133-
"detail": "Not found."
134-
}
135-
```
1+
# Demo DevOps Python Application
2+
3+
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.
4+
5+
## Table of Contents
6+
- [Architecture](#architecture)
7+
- [Tools](#Tools)
8+
- [Setup Instructions](#setup-instructions)
9+
- [CI/CD Pipelines](#ci-cd-pipelines)
10+
- [Kubernetes Deployment](#kubernetes-deployment)
11+
- [Contributing](#contributing)
12+
- [License](#license)
13+
14+
## Architecture
15+
16+
The Django API is deployed on a DigitalOcean Kubernetes cluster with the following components:
17+
- **Deployment**: The API is deployed with 2 replicas, managed by a Horizontal Pod Autoscaler (HPA) that can scale up to 3 replicas.
18+
- **Service Account**: A basic service account is used to follow security standards.
19+
- **LoadBalancer**: Exposes the API to the world, accessible via the domain [`api.algova.dev`](https://api.algova.dev). It may take about 1 minute.
20+
- **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.
21+
- **Static Files**: Served from an S3 bucket with proper ACL configurations.
22+
23+
![Architecture Diagram](https://lucid.app/publicSegments/view/5f85d354-b853-494c-b0aa-f24e1dfe826c/image.png)
24+
25+
## Tools
26+
The following tools were used to develop this project:
27+
- Django: Python library used to power the backend.
28+
- Helm: Used to manage Kubernetes deployments in an organized and clean manner.
29+
- Kubernetes: Where our API is deployed, providing scalability and security.
30+
- Docker: Our API is containerized for easy deployment in any environment.
31+
- Github Actions: Used to deploy our API and to test our PRs before merging.
32+
- Pylint: Keeps our code following high standards.
33+
- Pytest: Ensures proper testing of our API to avoid downtimes.
34+
- Trivy: Keeps us alert to vulnerabilities in our Docker images.
35+
36+
## Setup Instructions
37+
The project was divided according to the task to be performed:
38+
**In all cases, we must clone the repo**
39+
```bash
40+
git clone https://github.com/Adriana618/devops-deemo.git
41+
cd devops-deemo
42+
```
43+
# Develop:
44+
You must have Minikube, Docker, and Helm installed.
45+
```bash
46+
sudo apt-get update
47+
sudo apt-get install -y python3 python3-pip docker.io kubectl minikube
48+
pip3 install -r requirements/dev.txt
49+
```
50+
# Test:
51+
You must have Minikube, Docker, and Helm installed.
52+
```bash
53+
sudo apt-get update
54+
sudo apt-get install -y python3 python3-pip docker.io kubectl minikube
55+
pip3 install -r requirements/test.txt
56+
```
57+
# Deploy:
58+
You must have a Kubernetes cluster with 2 nodes with 1CPU and 2GB of memory at a minimum.
59+
60+
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.
61+
- DJANGO_SECRET_KEY
62+
- DATABASE_NAME='db.sqlite3'
63+
- DJANGO_ALLOWED_HOSTS
64+
- AWS_STORAGE_BUCKET_NAME
65+
- AWS_ACCESS_KEY_ID
66+
- AWS_SECRET_ACCESS_KEY
67+
- AWS_DEFAULT_REGION
68+
69+
2. **Dockerize the Application**:
70+
- 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>
71+
72+
## CI/CD Pipelines
73+
74+
![CI/CD Diagram](https://lucid.app/publicSegments/view/1c2e5da3-7498-412c-abdc-838d29c90397/image.png)
75+
76+
### Deploy API
77+
This GitHub Action deploys commits merged into the `master` branch to a Kubernetes cluster on DigitalOcean.
78+
79+
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>
80+
81+
### Test PR
82+
This GitHub Action tests pull requests by running static code analysis, code coverage, and vulnerability scans.
83+
84+
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>
85+
86+
## Kubernetes Deployment
87+
88+
### Deployment Configuration
89+
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>
90+
91+
### Service Configuration
92+
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>
93+
94+
### Secrets
95+
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>
96+
97+
## Contributing
98+
99+
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.
136100

137101
## License
138102

139-
Copyright © 2023 Devsu. All rights reserved.
103+
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.

demo/settings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5252
]
5353

54+
CSRF_TRUSTED_ORIGINS = [f'https://{host}' for host in ALLOWED_HOSTS if host]
55+
5456
ROOT_URLCONF = "demo.urls"
5557

5658
TEMPLATES = [

0 commit comments

Comments
 (0)