Skip to content

Commit

Permalink
Add Nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhima-Mochi committed Jan 23, 2024
1 parent 78a710b commit 9fd3bff
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 54 deletions.
18 changes: 0 additions & 18 deletions docker-compose.linux.yml

This file was deleted.

18 changes: 0 additions & 18 deletions docker-compose.windows.yml

This file was deleted.

32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.9'

services:

linkzapurl-server-1:
build:
context: ./
dockerfile: Dockerfile
image: linkzapurl-server
container_name: linkzapurl-server-1
volumes:
- "./docker/config.yaml:/config/config.yaml"
restart: always
ports:
- "9000:8080"
environment:
MACHINE_ID: 1
ENDPOINT: http://localhost
linkzapurl-server-2:
build:
context: ./
dockerfile: Dockerfile
image: linkzapurl-server
container_name: linkzapurl-server-2
volumes:
- "./docker/config.yaml:/config/config.yaml"
restart: always
ports:
- "9001:8080"
environment:
MACHINE_ID: 2
ENDPOINT: http://localhost
11 changes: 0 additions & 11 deletions docker/config.linux.yaml

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions docker/mongodb/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Build Docker images
docker-compose build

# Stop and remove containers
docker-compose down -v
# Stop
docker-compose down

# Start all services
docker-compose up -d
Expand Down
10 changes: 10 additions & 0 deletions docker/nginx/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.9'

services:
nginx:
image: nginx:1.25.3
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
restart: always
10 changes: 10 additions & 0 deletions docker/nginx/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Build Docker images
docker-compose build

# Stop
docker-compose down

# Start all services
docker-compose up -d
25 changes: 25 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
events {
worker_connections 1024;
}

http {
limit_req_zone $binary_remote_addr zone=postLimit:10m rate=10r/s; # 10 requests per second

upstream loadbalancer {
server host.docker.internal:9000;
server host.docker.internal:9001;
}

server {
listen 80;

location / {
proxy_pass http://loadbalancer;
}

location /api/v1/urls {
limit_req zone=postLimit burst=100;
proxy_pass http://loadbalancer;
}
}
}
6 changes: 3 additions & 3 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
# Stop and remove containers
docker-compose -f docker-compose.windows.yml down -v
docker-compose down -v

# Build Docker images
docker-compose -f docker-compose.windows.yml build
docker-compose build

# Start all services
docker-compose -f docker-compose.windows.yml up
docker-compose up -d
2 changes: 1 addition & 1 deletion tests/api_stress_test_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
parser.add_argument("-n", "--number", help="Number of requests to be sent", type=int, default=1000)
args = parser.parse_args()

url = f"http://localhost:9000/{args.code}"
url = f"http://localhost/{args.code}"

with ThreadPoolExecutor(max_workers=10) as executor:
responses = list(executor.map(lambda _: send_request(url), range(args.number)))
Expand Down
2 changes: 1 addition & 1 deletion tests/api_stress_test_shorten.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main():

number_of_requests = int(args.number) if args.number else 1000

url = "http://localhost:9000/api/v1/urls"
url = "http://localhost/api/v1/urls"
data = {
"expireAt": "2025-02-08T09:20:41Z",
"url": "https://google.com"
Expand Down

0 comments on commit 9fd3bff

Please sign in to comment.