[~] Refactor

This commit is contained in:
Siarhei Siniak 2021-11-11 11:43:39 +03:00
parent d7084d3c96
commit 3d0a0c5f09
6 changed files with 86 additions and 29 deletions

@ -1,11 +0,0 @@
events {
multi_accept on;
worker_connections 1024;
}
http {
server {
listen 80;
return 302 https://product-development-service.blogspot.com;
}
}

@ -22,10 +22,10 @@ def forward(config_dir, config):
) )
ssh_command = [ ssh_command = [
'ssh', 'ssh',
'-o', '-o', 'ExitOnForwardFailure yes',
'ExitOnForwardFailure yes', '-o', 'StrictHostKeyChecking no',
'-o', '-o', 'ServerAliveInterval 1',
'StrictHostKeyChecking no' '-o', 'ConnectTimeout 1',
] ]
ports = dict( ports = dict(

59
d1/nginx_config.py Normal file

@ -0,0 +1,59 @@
import json
import io
import sys
with io.open(
sys.argv[1],
'r'
) as f:
forward_nginx = json.load(f)
with io.open(
sys.argv[2],
'w'
) as f:
sections = []
for entry in forward_nginx:
sections.append(r'''
location ^~ /{app_name}/ {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_redirect off;
proxy_buffering off;
proxy_pass {target_endpoint};
}
'''.replace(
'{app_name}', entry['app_name'],
).replace(
'{target_endpoint}', entry['target_endpoint'],
))
f.write(r'''
events {
multi_accept on;
worker_connections 8;
}
http {
server {
listen 80;
client_max_body_size 200M;
{sections_config}
location / {
return 302 https://product-development-service.blogspot.com;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
'''.replace(
'{sections_config}', '\n'.join(sections)
))

@ -1,17 +1,20 @@
version: '3.7' version: '3.7'
services: services:
blank-app: app:
build: build:
context: . context: .
dockerfile: ./docker/blank-app/Dockerfile dockerfile: ./docker/app/Dockerfile
volumes: volumes:
- .:/app:rw - ./d1/nginx_config.py:/app/d1/nginx_config.py:ro
restart: always - ./tmp/cache/forward.nginx.json:/app/tmp/cache/forward.nginx.json:ro
forward:
build:
context: .
dockerfile: ./docker/forward/Dockerfile
volumes:
- ./d1/forward.py:/app/d1/forward.py:ro
- ./tmp/cache/forward_data:/app/tmp/cache/forward_data:ro
restart: always restart: always
ports:
- 80:80
#forward:
# build:
# context: .
# dockerfile: ./docker/forward/Dockerfile
# volumes:
# - ./d1/forward.py:/app/d1/forward.py:ro
# - ./tmp/cache/forward_data:/app/tmp/cache/forward_data:ro
# restart: always

9
docker/app/Dockerfile Normal file

@ -0,0 +1,9 @@
FROM nginx:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python3
WORKDIR /app
ENTRYPOINT /bin/sh -c "\
python3 d1/nginx_config.py tmp/cache/forward.nginx.json /etc/nginx/nginx.conf && \
/docker-entrypoint.sh nginx -g 'daemon off;' \
"

@ -1,3 +0,0 @@
FROM nginx:latest
COPY d1/blank-app-nginx.conf /etc/nginx/nginx.conf