[fix] Reworks structure and adds docker

This commit is contained in:
alban 2020-10-22 20:44:24 +02:00
parent fd0974134b
commit b31f725d04
60 changed files with 120 additions and 16 deletions

0
.dockerignore Normal file
View File

3
.env.template Normal file
View File

@ -0,0 +1,3 @@
DB_HOST="127.0.0.1"
DB_PORT="6379"
DEBUG=1

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

29
Dockerfile Normal file
View File

@ -0,0 +1,29 @@
FROM python:3.8-slim
LABEL name=laser-app version=0.1
WORKDIR /opt
RUN apt update
RUN apt install -y --no-install-recommends build-essential\
gcc\
libagg2-dev\
libpotrace-dev\
nginx-light\
pkg-config\
python-dev\
redis-server
RUN rm -f /etc/nginx/sites-enabled/*
RUN pip3 install flask numpy pillow redis
RUN pip3 install pypotrace
COPY ./files/nginx/sites-enabled/site.conf /etc/nginx/sites-enabled
COPY . .
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
EXPOSE 80
EXPOSE 5000
EXPOSE 9001
# Start the main process.
CMD ["python", "./server.py", "-i", "db"]

36
docker-compose.yml Normal file
View File

@ -0,0 +1,36 @@
version: '2'
volumes:
laserrdb:
external: true
services:
db:
env_file: .env
image: redis:6-alpine
ports:
- "6379:6379"
volumes:
- laserrdb:/var/lib/redis
app:
env_file: .env
build: .
image: teamlaser/laser-app:latest
ports:
- "5000:5000"
depends_on:
- db
command: python ./server.py
assets:
env_file: .env
build: .
image: teamlaser/laser-app:latest
ports:
- "8080:80"
depends_on:
- app
command: nginx -g 'daemon off;error_log /dev/stdout info;'

5
entrypoint.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
set -e
exec "$@"

View File

@ -0,0 +1,13 @@
server {
server_name _;
listen 80 default_server;
listen [::]:80 default_server;
root /opt/;
location /image {
proxy_pass http://app:5000;
}
# Docker specific conf
resolver 127.0.0.11 ipv6=off;
access_log /dev/stdout;
}

View File

@ -12,12 +12,12 @@
#canvas { margin-top: 20px; border: 1px solid #ccc; display: block; } #canvas { margin-top: 20px; border: 1px solid #ccc; display: block; }
span.ui-slider-handle.ui-corner-all.ui-state-default { background: dodgerblue;} span.ui-slider-handle.ui-corner-all.ui-state-default { background: dodgerblue;}
</style> </style>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" /> <link rel="stylesheet" type="text/css" href="css/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="jquery-ui/jquery-ui.css" /> <link rel="stylesheet" type="text/css" href="js/jquery-ui/jquery-ui.css" />
<script src="jquery-3.5.1.min.js"></script> <script src="js/jquery-3.5.1.min.js"></script>
<script src="jquery-ui/jquery-ui.js"></script> <script src="js/jquery-ui/jquery-ui.js"></script>
<script src="canvas.js"></script> <script src="js/canvas.js"></script>
</head> </head>
<body> <body>
<script> <script>

View File

@ -2,7 +2,7 @@
$(document).ready(function(){ $(document).ready(function(){
var binary_level = 100 var binary_level = 100
var url = "http://localhost" var url = document.URL
// Grab elements, create settings, etc. // Grab elements, create settings, etc.
var canvas = document.getElementById('canvas'); var canvas = document.getElementById('canvas');

View File

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 262 B

View File

Before

Width:  |  Height:  |  Size: 348 B

After

Width:  |  Height:  |  Size: 348 B

View File

Before

Width:  |  Height:  |  Size: 207 B

After

Width:  |  Height:  |  Size: 207 B

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -1,18 +1,35 @@
#! /usr/bin/python3 #! /usr/bin/python3
import flask
from redis import Redis from redis import Redis
from flask import Flask, redirect, url_for, request from flask import Flask, redirect, url_for, request
import json import flask
import hashlib import hashlib
import json
import os
import time import time
r = Redis() # Redis init
app = Flask(__name__) environ = os.environ
m = hashlib.sha256() host = environ['DB_HOST'] if 'DB_HOST' in os.environ else "localhost"
@app.route('/dashboard/<name>') port = environ['DB_PORT'] if 'DB_PORT' in os.environ else 6379
def dashboard(name): debug = environ['DEBUG'] if 'DEBUG' in os.environ else False
return 'welcome %s' % name sep='**************************************'
print("\n{}\nConnecting to Redis server on {}:{}\n{}\n".format(sep,host,port,sep))
r = Redis(host="db", port=port)
# hashlib init
m = hashlib.sha256()
# Flask app init
app = Flask(__name__)
@app.before_first_request
def setup_logging():
if not app.debug:
# In production mode, add log handler to sys.stdout.
app.logger.addHandler(logging.StreamHandler(stream=sys.stdout))
app.logger.setLevel(logging.INFO)
# Routing requests
@app.route('/image',methods = ['POST', 'GET']) @app.route('/image',methods = ['POST', 'GET'])
def image(): def image():
try: try:
@ -44,6 +61,6 @@ def image():
print("woah",e) print("woah",e)
return( json.dumps( {"errors":[ str(e)]})) return( json.dumps( {"errors":[ str(e)]}))
# Run Flask
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug = True) app.run(host= '0.0.0.0',debug = True)