fix: make it work

This commit is contained in:
alban 2023-07-26 01:28:19 +02:00
parent a21ba6b8fb
commit 0e43bea656
11 changed files with 110 additions and 42 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

8
.idea/laser-app.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/laser-app.iml" filepath="$PROJECT_DIR$/.idea/laser-app.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,29 +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
python-dev
RUN rm -f /etc/nginx/sites-enabled/*
RUN pip3 install flask numpy pillow redis
RUN pip3 install pypotrace
COPY ./server/files/nginx/sites-enabled/site.conf /etc/nginx/sites-enabled
WORKDIR /opt
COPY . .
COPY ./server/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
# COPY ./server/entrypoint.sh /usr/bin/
# RUN chmod +x /usr/bin/entrypoint.sh
#
# ENTRYPOINT /usr/bin/entrypoint.sh
EXPOSE 80
EXPOSE 5000
EXPOSE 9001
# Start the main process.
CMD ["python", "./server.py", "-i", "db"]

49
docker-compose.yml Normal file
View File

@ -0,0 +1,49 @@
version: "3.7"
services:
nginx:
image: nginx:latest
ports:
- 80:80
expose:
- 80:80
networks:
- snap_net
volumes:
- .:/opt:ro
- ./server/files/nginx/sites-enabled/site.conf:/etc/nginx/conf.d/default.conf:ro
# command: sleep 60000
app:
image: laserapp:0.1
environment:
- DB_HOST=redis
expose:
- 5000
ports:
- "5000:5000"
networks:
- snap_net
volumes:
- ./app/:/app/
# command: sleep 60000
worker:
image: laserapp:0.1
environment:
- DB_HOST=redis
networks:
- snap_net
volumes:
- ./app/:/app/
command: bash -c "while true; do /usr/local/bin/python3 worker.py; sleep 1; done"
redis:
image: redis
networks:
- snap_net
ports:
- 6379
networks:
snap_net:
driver: bridge

View File

@ -106,36 +106,15 @@ $(document).ready(function(){
img = new Image();
var objectUrl = _URL.createObjectURL(file);
img.onload = function () {
let w = 640
let h = 640 * this.height / this.width
showSnap(this,w,h)
let w = 640;
let h = 640 * this.height / this.width;
showSnap(this,w,h);
};
img.src = objectUrl;
}
if(files && typeof FileReader !== "undefined") {
for(var i=0; i<files.length; i++) {
// fileToSnap(files[i]);
}
}
}
var fileToSnap = function(file) {
if( (/image/i).test(file.type) ) {
var reader = new FileReader();
reader.onload = function(e) {
let base_image = new Image();
base_image.src = e.target.result;
console.log(
base_image.width
)
base_image.width = 640;
base_image.onload = function(){
showSnap(base_image,640,480)
}
};
reader.readAsDataURL(file);
}
}
// Draws every segment received, except black colored target ones
var drawSimu = function() {

View File

@ -22,21 +22,20 @@ 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)
#
# @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'])
def image():
try:
data = dict()
res =r.keys("*")
print("Received request")
# Clean the request
if "text" in request.form:
data["text"] = request.form["text"][:256]

View File

@ -6,6 +6,9 @@ server {
location ~ /(hash_name|image) {
proxy_pass http://app:5000;
}
location / {
try_files $uri /index.html;
}
# Docker specific conf
resolver 127.0.0.11 ipv6=off;
access_log /dev/stdout;