changes for docker deployment
This commit is contained in:
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
||||
FROM tiangolo/uwsgi-nginx-flask:python3.8-alpine AS builder
|
||||
|
||||
RUN python -m venv /opt/venv
|
||||
# Make sure we use the virtualenv:
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps ca-certificates gcc linux-headers \
|
||||
musl-dev jpeg-dev zlib-dev libffi-dev git make \
|
||||
&& pip install --upgrade pip
|
||||
|
||||
COPY ./requirements.txt /app/requirements.txt
|
||||
RUN pip install wheel && pip install -r requirements.txt
|
||||
|
||||
|
||||
FROM tiangolo/uwsgi-nginx-flask:python3.8-alpine
|
||||
|
||||
#ENV LISTEN_PORT 8080
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
COPY ./fotos-nginx.conf /etc/nginx/conf.d/fetfotos2020.conf
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
COPY . /app
|
||||
25
bak/uwsgi.ini.back
Normal file
25
bak/uwsgi.ini.back
Normal file
@@ -0,0 +1,25 @@
|
||||
[uwsgi]
|
||||
# User and group www-data on debian
|
||||
uid = 33
|
||||
gid = 33
|
||||
master = true
|
||||
# No. of processes can be increased
|
||||
processes = 9
|
||||
chown-socket =www-data:www-data
|
||||
virtualenv = /opt/venv
|
||||
pythonpath = /srv/flask-fet-fotos/
|
||||
#pidfile = /srv/simple_sample_flat_index/uwsgi.pid
|
||||
#socket = /srv/simple_sample_flat_index/uwsgi.sock
|
||||
pidfile=/var/run/fet_fotos.pid
|
||||
socket = /var/run/fet_fotos.sock
|
||||
chmod-socket = 666
|
||||
module = foto_gallery
|
||||
callable= app
|
||||
wsgi-file = run.py
|
||||
logdate = true
|
||||
|
||||
loglevel = debug
|
||||
gevent = 100
|
||||
vacuum=true
|
||||
plugins=python3,logfile
|
||||
py-autoreload=2
|
||||
16
build_docker
Executable file
16
build_docker
Executable file
@@ -0,0 +1,16 @@
|
||||
docker stop flask-fet-fotos
|
||||
docker container rm flask-fet-fotos
|
||||
docker build -t flask-fet-fotos .
|
||||
#docker run -d --name mycontainer -p 8080:8080 -v $(pwd):/app -e FLASK_APP=main.py -e FLASK_DEBUG=1 myimage flask run --host=0.0.0.0 --port=8080
|
||||
while true; do
|
||||
read -p "Run a docker container?" yn
|
||||
case $yn in
|
||||
[Yy]* ) docker run --name flask-fet-fotos -d -p 8080:8080 \
|
||||
-v "$(pwd)/data:/mnt" flask-fet-fotos; break;;
|
||||
[Nn]* ) break;;
|
||||
* ) echo "Please answer yes or no.";;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
#-v "$(pwd):/app"
|
||||
@@ -1,13 +0,0 @@
|
||||
[Unit]
|
||||
Description=uWSGI Simple Sample for Flat Page with Index Default
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
#User=www-data
|
||||
#Group=www-data
|
||||
WorkingDirectory=/srv/flask-fet-fotos
|
||||
Environment="PATH=/srv/flask-fet-fotos/.env/bin"
|
||||
ExecStart=uwsgi --ini uwsgi.ini
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,16 +0,0 @@
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 ;
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
|
||||
server_name _;
|
||||
|
||||
root /var/www/html;
|
||||
|
||||
location / {
|
||||
include uwsgi_params;
|
||||
uwsgi_pass unix:///var/run/fet_fotos.sock
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
[Unit]
|
||||
Description=uWSGI Simple Sample for Flat Page with Index Default
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
#User=www-data
|
||||
#Group=www-data
|
||||
WorkingDirectory=/srv/foto_gallery
|
||||
Environment="PATH=/srv/foto_gallery/.env/bin"
|
||||
ExecStart=/srv/foto_gallery/.env/bin/uwsgi --ini uwsgi.ini
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -9,18 +9,36 @@ from flask import Flask, Blueprint,render_template, send_from_directory,jsonify,
|
||||
import flatpages_index
|
||||
from flatpages_index import FlatPagesIndex
|
||||
from flask_frozen import Freezer
|
||||
from config import Config
|
||||
#from config import Config
|
||||
import os
|
||||
import re
|
||||
from PIL import Image, ExifTags, ImageOps
|
||||
from functools import partial
|
||||
from flask_csp.csp import csp_header, csp_default
|
||||
|
||||
cfg = Config("config.cfg")
|
||||
#cfg = Config("./config.cfg")
|
||||
import environ
|
||||
env = environ.Env(
|
||||
# set casting, default value
|
||||
DEBUG=(bool, False),
|
||||
pages_root=(str,'data_sample'),
|
||||
static_root=(str,'static'),
|
||||
default_template=(str, 'page.html'),
|
||||
url_prefix =(str, "/stuff"),
|
||||
FLATPAGES_EXTENSION = (str, ".md"),
|
||||
FLATPAGES_AUTO_RELOAD = (bool, True)
|
||||
|
||||
)
|
||||
# Initialize application
|
||||
app = Flask(__name__)
|
||||
app.config.update(cfg)
|
||||
#app.config.update(cfg)
|
||||
app.config["pages_root"]=env('pages_root')
|
||||
app.config["static_root"]=env('static_root')
|
||||
app.config["default_template"]=env('default_template')
|
||||
app.config["url_prefix"]=env('url_prefix')
|
||||
app.config["FLATPAGES_EXTENSION"]=env('FLATPAGES_EXTENSION')
|
||||
app.config["FLATPAGES_AUTO_RELOAD"]=env('FLATPAGES_AUTO_RELOAD')
|
||||
|
||||
app.logger.setLevel(logging.DEBUG)
|
||||
# Initialize FlatPages Index
|
||||
|
||||
@@ -35,10 +53,10 @@ flatpages.get('index')
|
||||
app.logger.info('Initialize FET Foto Gallery App')
|
||||
app.logger.info('flatpages loaded %d pages' % len(flatpages._pages))
|
||||
app.logger.info("Data directory is: %s" % flatpages.root)
|
||||
app.logger.info("Url prefix;: %s" % cfg.url_prefix)
|
||||
|
||||
csp_d=csp_default()
|
||||
csp_d.update({'default-src':"'self' 'unsafe-inline'", 'script-src': "'unsafe-inline' 'self'"})
|
||||
|
||||
#csp_d=csp_default()
|
||||
#csp_d.update({'default-src':"'self' 'unsafe-inline'", 'script-src': "'unsafe-inline' 'self'"})
|
||||
|
||||
|
||||
|
||||
@@ -87,7 +105,6 @@ def thumb(size=64,name=''):
|
||||
|
||||
@page_blueprint.route('/<path:name>/',strict_slashes=False)
|
||||
@page_blueprint.route('/')
|
||||
@csp_header()
|
||||
def post(name=''):
|
||||
print("Post: %s" % name)
|
||||
page = flatpages.get(name)
|
||||
@@ -104,8 +121,8 @@ def post(name=''):
|
||||
elif os.path.exists(os.path.join('static',name)):
|
||||
print("send from static dir %s" % name)
|
||||
return send_from_directory(os.path.abspath('static'),name)
|
||||
elif os.path.exists(os.path.join(cfg["fet_assets"],name)):
|
||||
return send_from_directory(cfg["fet_assets"],name)
|
||||
#elif os.path.exists(os.path.join(cfg["fet_assets"],name)):
|
||||
# return send_from_directory(cfg["fet_assets"],name)
|
||||
elif os.path.exists(os.path.join("blueimp",name)):
|
||||
return send_from_directory(os.path.abspath('blueimp'),name)
|
||||
else:
|
||||
@@ -133,6 +150,6 @@ def postjson(name='index'):
|
||||
|
||||
|
||||
|
||||
app.register_blueprint(page_blueprint, url_prefix=cfg.url_prefix,static_folder='static')
|
||||
app.register_blueprint(api_blueprint, url_prefix="/api/"+cfg.url_prefix,static_folder='static')
|
||||
app.add_url_rule('%s/<path:name>' % cfg.url_prefix,'page', post)
|
||||
app.register_blueprint(page_blueprint, url_prefix=app.config["url_prefix"],static_folder='static')
|
||||
app.register_blueprint(api_blueprint, url_prefix="/api/"+app.config["url_prefix"],static_folder='static')
|
||||
app.add_url_rule('%s/<path:name>' % app.config["url_prefix"],'page', post)
|
||||
|
||||
12
fotos-nginx.conf
Normal file
12
fotos-nginx.conf
Normal file
@@ -0,0 +1,12 @@
|
||||
server {
|
||||
listen 8080;
|
||||
index index.html;
|
||||
location /static {
|
||||
alias /app/static;
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
location / {
|
||||
include uwsgi_params;
|
||||
uwsgi_pass unix:///tmp/uwsgi.sock;
|
||||
}
|
||||
}
|
||||
9
main.py
Normal file
9
main.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from foto_gallery import app,freezer
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "build":
|
||||
freezer.freeze()
|
||||
else:
|
||||
app.run(host='0.0.0.0',port=8080, debug=True)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
flask
|
||||
Frozen-Flask
|
||||
config
|
||||
python-environ
|
||||
gevent
|
||||
Pillow
|
||||
wheel
|
||||
flask_csp
|
||||
git+https://github.com/andreassteph/flatpages_index.git
|
||||
|
||||
27
uwsgi.ini
27
uwsgi.ini
@@ -1,25 +1,6 @@
|
||||
[uwsgi]
|
||||
# User and group www-data on debian
|
||||
uid = 33
|
||||
gid = 33
|
||||
master = true
|
||||
# No. of processes can be increased
|
||||
processes = 9
|
||||
chown-socket =www-data:www-data
|
||||
virtualenv = /srv/flask-fet-fotos/.env
|
||||
pythonpath = /srv/flask-fet-fotos/
|
||||
#pidfile = /srv/simple_sample_flat_index/uwsgi.pid
|
||||
#socket = /srv/simple_sample_flat_index/uwsgi.sock
|
||||
pidfile=/var/run/fet_fotos.pid
|
||||
socket = /var/run/fet_fotos.sock
|
||||
chmod-socket = 666
|
||||
module = foto_gallery
|
||||
uid = 100
|
||||
gid = 101
|
||||
module = main
|
||||
callable = app
|
||||
wsgi-file = run.py
|
||||
logdate = true
|
||||
#logger = file:/srv/simple_sample_flat_index/uwsgi.log
|
||||
loglevel = debug
|
||||
gevent = 100
|
||||
vacuum=true
|
||||
plugins=python3,logfile
|
||||
py-autoreload=2
|
||||
venv=/opt/venv
|
||||
Reference in New Issue
Block a user