Update Readme and redis deployment
This commit is contained in:
parent
95582e71a0
commit
72c341aaac
39
README.md
39
README.md
|
@ -19,6 +19,16 @@ pip install -r requirements.txt
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Running Backend & Frontend Together (Using Docker Compose)
|
### Running Backend & Frontend Together (Using Docker Compose)
|
||||||
|
|
||||||
|
A sample docker compose file is provided in the root directory. You can use it to run the backend and frontend together.
|
||||||
|
|
||||||
|
> Please modify the environment variables in the docker-compose.yml file before running it.
|
||||||
|
|
||||||
|
APIs:
|
||||||
|
- [VirusTotal](https://developers.virustotal.com/v3.0/reference)
|
||||||
|
- [AWS DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)
|
||||||
|
- [AWS](https://aws.amazon.com/)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Run backend & frontend using docker-compose
|
# Run backend & frontend using docker-compose
|
||||||
docker-compose up
|
docker-compose up
|
||||||
|
@ -37,6 +47,8 @@ kubectl apply -f backend_service.yaml
|
||||||
```
|
```
|
||||||
### For development
|
### For development
|
||||||
|
|
||||||
|
Copy the `env` file to `.env` and modify the environment variables accordingly.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Run frontend locally
|
# Run frontend locally
|
||||||
cd ../safeshare-frontend
|
cd ../safeshare-frontend
|
||||||
|
@ -73,3 +85,30 @@ python post_and_get_files.py
|
||||||
# Uploads multiple files in multiple threads (upload/download)
|
# Uploads multiple files in multiple threads (upload/download)
|
||||||
python stressTest.py
|
python stressTest.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
## React App
|
||||||
|
|
||||||
|
Frontend is built using ReactJS and TailwindCSS. It is Containerised using Docker.
|
||||||
|
|
||||||
|
An image is here [amusement3004/safeshare-frontend:latest](https://hub.docker.com/repository/docker/amusement3004/safeshare-frontend)
|
||||||
|
|
||||||
|
## Django App
|
||||||
|
|
||||||
|
Backend is built using Django REST Framework. It is Containerised using Docker.
|
||||||
|
|
||||||
|
An image is here [amusement3004/safeshare:latest](https://hub.docker.com/repository/docker/amusement3004/safeshare)
|
||||||
|
|
||||||
|
## Virus Scanning Microservice
|
||||||
|
|
||||||
|
Virus Scanning microservice is built using [gRPC](https://grpc.io/), [Protocol Buffers](https://developers.google.com/protocol-buffers)
|
||||||
|
and [VirusTotal API](https://developers.virustotal.com/v3.0/reference). It is included in the Django App.
|
||||||
|
|
||||||
|
## Trash Cleaning Microservice
|
||||||
|
|
||||||
|
The application provides an automated cleaning service for the files that are uploaded to the server.
|
||||||
|
The files are deleted after a certain period of time (ttl).
|
||||||
|
The time period can be set in the `.env` file. (`TRASH_TIMEOUT`)
|
||||||
|
|
||||||
|
This service will periodically check redis for the files that have expired and delete them from the server's storage.
|
|
@ -81,26 +81,3 @@ spec:
|
||||||
- name: redis-persistent-storage
|
- name: redis-persistent-storage
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
claimName: redis-pv-claim
|
claimName: redis-pv-claim
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: autoscaling/v1
|
|
||||||
kind: HorizontalPodAutoscaler
|
|
||||||
metadata:
|
|
||||||
name: safeshare-redis-hpa
|
|
||||||
labels:
|
|
||||||
app: safeshare
|
|
||||||
spec:
|
|
||||||
scaleTargetRef:
|
|
||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
name: safeshare-redis
|
|
||||||
minReplicas: 3
|
|
||||||
maxReplicas: 6
|
|
||||||
metrics:
|
|
||||||
- type: Resource
|
|
||||||
resource:
|
|
||||||
name: cpu
|
|
||||||
target:
|
|
||||||
type: Utilization
|
|
||||||
averageUtilization: 50
|
|
|
@ -173,23 +173,18 @@ PRIVATE_IPS_PREFIX = ('10.', '172.', '192.')
|
||||||
|
|
||||||
|
|
||||||
def get_client_ip(request):
|
def get_client_ip(request):
|
||||||
"""get the client ip from the request
|
|
||||||
"""
|
"""
|
||||||
# remote_address = request.META.get('REMOTE_ADDR')
|
Get Client's IP
|
||||||
|
"""
|
||||||
remote_address = request.META.get('HTTP_X_FORWARDED_FOR') or request.META.get('REMOTE_ADDR')
|
remote_address = request.META.get('HTTP_X_FORWARDED_FOR') or request.META.get('REMOTE_ADDR')
|
||||||
# set the default value of the ip to be the REMOTE_ADDR if available
|
|
||||||
# else None
|
|
||||||
ip = remote_address
|
ip = remote_address
|
||||||
# try to get the first non-proxy ip (not a private ip) from the
|
|
||||||
# HTTP_X_FORWARDED_FOR
|
|
||||||
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||||
|
|
||||||
if x_forwarded_for:
|
if x_forwarded_for:
|
||||||
proxies = x_forwarded_for.split(',')
|
proxies = x_forwarded_for.split(',')
|
||||||
# remove the private ips from the beginning
|
|
||||||
while len(proxies) > 0 and proxies[0].startswith(PRIVATE_IPS_PREFIX):
|
while len(proxies) > 0 and proxies[0].startswith(PRIVATE_IPS_PREFIX):
|
||||||
proxies.pop(0)
|
proxies.pop(0)
|
||||||
# take the first ip which is not a private one (of a proxy)
|
|
||||||
if len(proxies) > 0:
|
if len(proxies) > 0:
|
||||||
ip = proxies[0]
|
ip = proxies[0]
|
||||||
print(ip)
|
|
||||||
return ip
|
return ip
|
||||||
|
|
Loading…
Reference in New Issue