Docker Test with Nginx

This commit is contained in:
Yûki VACHOT 2022-02-01 16:27:57 +01:00
parent 886f22ac85
commit 1a3bee1846
14 changed files with 70 additions and 34 deletions

View file

@ -4,27 +4,46 @@ services:
nginx:
image: nginx:latest
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./logs/nginx:/etc/nginx/logs
- ./cert:/etc/nginx/cert
- ./frontend/conf/nginx.conf:/etc/nginx/nginx.conf
- ./frontend/logs/nginx:/etc/nginx/logs
- ./frontend/cert:/etc/nginx/cert
networks:
- net
ports:
- 80:80
depends_on:
- server
server:
container_name: server
build: frontend/backend
command: python -m flask run
ports:
- "4200:4200"
volumes:
- ./frontend/backend:/data/frontend/backend
- ./frontend/app.py:/data/frontend/app.py
- ./frontend/config.py:/data/frontend/config.py
environment:
- FLASK_APP=app.py
- FLASK_ENV=production
- FLASK_DEBUG=1
- FLASK_RUN_PORT=4200
- PYTHONUNBUFFERED=1
networks:
- net
depends_on:
- frontend
frontend:
container_name: frontend
build: .
command: npm start
# ports:
# - "4200:4200"
build: frontend
command: npm run build
volumes:
- ./src:/data/frontend
- ./node_modules:/data/frontend/node_modules
- ./frontend/src:/data/frontend
- ./frontend/node_modules:/data/frontend/node_modules
environment:
- NODE_ENV=production
networks:
- net
networks:
net:

2
frontend/.gitignore vendored
View file

@ -47,3 +47,5 @@ testem.log
Thumbs.db
package-lock.json
backend/dist

View file

@ -20,7 +20,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/",
"outputPath": "backend/dist/",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
@ -42,13 +42,13 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
"maximumWarning": "1mb",
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
"maximumWarning": "4kb",
"maximumError": "8kb"
}
],
"fileReplacements": [

View file

@ -1,7 +1,7 @@
from . import create_app
from backend import create_app
import os
app = create_app(os.environ.get('FLASK_ENV', None))
app = create_app(os.environ.get('FLASK_ENV'))
if __name__ == "__main__":
app.run(host='0.0.0.0', DEBUG=True)

View file

@ -1,6 +1,7 @@
FROM python:latest
WORKDIR /data/backend
WORKDIR /data/frontend/backend
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
COPY . .
WORKDIR /data/frontend

View file

@ -5,3 +5,4 @@ PyJWT==2.3.0
pytest==6.2.5
psycopg2==2.9.2
Flask-Cors==3.0.10
requests==2.22.0

View file

@ -1,6 +1,5 @@
from flask import request, Blueprint, send_from_directory, current_app as app
import requests
import os
from werkzeug.exceptions import HTTPException
from .responses import send_message, send_error
from .sessionJWT import create_auth_token, check_auth_token
@ -36,17 +35,17 @@ def handle_exception(e):
@bp.route('/', methods=['GET'])
def root():
return send_from_directory("frontend/dist", "index.html")
return send_from_directory("dist", "index.html")
@bp.route('/frontend/dist/<path:path>', methods=['GET'])
@bp.route('/frontend/backend/dist/<path:path>', methods=['GET'])
def static(path):
return send_from_directory("frontend/dist", path)
return send_from_directory("dist", path)
@bp.route('/assets/<path:path>', methods=['GET'])
def assets(path):
return send_from_directory("frontend/dist/assets", path)
return send_from_directory("dist/assets", path)
# Login

View file

@ -17,18 +17,18 @@ http {
proxy_read_timeout 90;
proxy_buffers 32 4k;
upstream frontend {
server frontend:4200;
upstream server {
server server:4200;
}
server {
listen 80;
server_name wordpress;
server_name flask-aled;
access_log logs/access.log;
location / {
proxy_pass http://frontend;
proxy_pass http://server;
}
}

View file

@ -19,3 +19,17 @@
192.168.16.1 - - [28/Jan/2022:11:04:23 +0000] "GET /styles.f64087845b474dd2.css HTTP/1.1" 304 0 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50"
192.168.16.1 - - [28/Jan/2022:11:04:23 +0000] "GET /assets/logo.png HTTP/1.1" 304 0 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50"
192.168.16.1 - - [28/Jan/2022:11:04:23 +0000] "GET /favicon.ico HTTP/1.1" 200 948 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50"
172.21.0.1 - - [01/Feb/2022:14:58:24 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.21.0.1 - - [01/Feb/2022:14:58:25 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.21.0.1 - - [01/Feb/2022:14:58:30 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.21.0.1 - - [01/Feb/2022:14:58:30 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.21.0.1 - - [01/Feb/2022:15:01:07 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.21.0.1 - - [01/Feb/2022:15:01:07 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:14:43 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:14:43 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:19:49 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:19:52 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:22:17 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:22:18 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:22:19 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
172.22.0.1 - - [01/Feb/2022:15:22:19 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"

View file

@ -3,8 +3,8 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng build && python flask run",
"build": "ng build --build-optimizer --baseHref=frontend/dist/",
"start": "ng build --build-optimizer --baseHref=frontend/backend/dist/ && cd .. && python -m flask run",
"build": "ng build --build-optimizer --baseHref=frontend/backend/dist/",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},