feat: Add new docker image
This commit is contained in:
20
sites/Dockerfile
Normal file
20
sites/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
COPY . /app
|
||||
COPY ../templates /app/templates
|
||||
COPY ../.env /app/.env
|
||||
COPY ../requirements.txt /app/requirements.txt
|
||||
|
||||
# Add mount point for data volume
|
||||
VOLUME /data
|
||||
|
||||
ENTRYPOINT ["python3"]
|
||||
CMD ["sldserver.py"]
|
||||
|
||||
FROM builder as dev-envs
|
||||
48
sites/slds.py
Normal file
48
sites/slds.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from flask import Flask, make_response, redirect, request, jsonify, render_template, send_from_directory
|
||||
import os
|
||||
import dotenv
|
||||
import requests
|
||||
import json
|
||||
import schedule
|
||||
import time
|
||||
from email_validator import validate_email, EmailNotValidError
|
||||
import accounts
|
||||
|
||||
app = Flask(__name__)
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
#Assets routes
|
||||
@app.route('/assets/<path:path>')
|
||||
def assets(path):
|
||||
return send_from_directory('templates/assets', path)
|
||||
|
||||
#! TODO make prettier
|
||||
def error(message):
|
||||
return jsonify({'success': False, 'message': message}), 400
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
host = request.host
|
||||
return jsonify({'success': True, 'message': host})
|
||||
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def catch_all(path):
|
||||
# If file exists, load it
|
||||
if os.path.isfile('templates/' + path):
|
||||
return render_template(path)
|
||||
|
||||
# Try with .html
|
||||
if os.path.isfile('templates/' + path + '.html'):
|
||||
return render_template(path + '.html')
|
||||
return redirect('/') # 404 catch all
|
||||
|
||||
# 404 catch all
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
return redirect('/')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=False, port=5000, host='0.0.0.0')
|
||||
42
sites/sldserver.py
Normal file
42
sites/sldserver.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import time
|
||||
from flask import Flask
|
||||
from slds import app
|
||||
import slds
|
||||
from gunicorn.app.base import BaseApplication
|
||||
import os
|
||||
import dotenv
|
||||
import sys
|
||||
import json
|
||||
|
||||
|
||||
class GunicornApp(BaseApplication):
|
||||
def __init__(self, app, options=None):
|
||||
self.options = options or {}
|
||||
self.application = app
|
||||
super().__init__()
|
||||
|
||||
def load_config(self):
|
||||
for key, value in self.options.items():
|
||||
if key in self.cfg.settings and value is not None:
|
||||
self.cfg.set(key.lower(), value)
|
||||
|
||||
def load(self):
|
||||
return self.application
|
||||
|
||||
if __name__ == '__main__':
|
||||
workers = os.getenv('WORKERS')
|
||||
threads = os.getenv('THREADS')
|
||||
if workers is None:
|
||||
workers = 1
|
||||
if threads is None:
|
||||
threads = 2
|
||||
workers = int(workers)
|
||||
threads = int(threads)
|
||||
options = {
|
||||
'bind': '0.0.0.0:5001',
|
||||
'workers': workers,
|
||||
'threads': threads,
|
||||
}
|
||||
gunicorn_app = GunicornApp(app, options)
|
||||
print('Starting server with ' + str(workers) + ' workers and ' + str(threads) + ' threads', flush=True)
|
||||
gunicorn_app.run()
|
||||
Reference in New Issue
Block a user