Commit 6458cb40 authored by Nicolas Wavrant's avatar Nicolas Wavrant

flask : new stack to deploy a flask server

parent c9e7414b
from server import *
from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
\ No newline at end of file
[buildout]
parts =
directory
certificate-authority
gunicorn-launcher
gunicorn-graceful
ca-nginx
nginx_conf
nginx-launcher
nginx-promise
flask-promise
symlinks
base-server
base-module
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc/
var = $${buildout:directory}/var/
srv = $${buildout:directory}/srv/
bin = $${buildout:directory}/bin/
tmp = $${buildout:directory}/tmp/
services = $${:etc}/service/
scripts = $${:etc}/run/
www = $${:var}/www
promises = $${:etc}/promise/
run = $${:var}/run/
log = $${:var}/log/
nginx-data = $${:srv}/nginx/
ca-dir = $${:srv}/ssl
#---------------------------
#--
#-- setup nginx
[tempdirectory]
recipe = slapos.cookbook:mkdirectory
client_body_temp_path = $${directory:tmp}/client_body_temp_path
proxy_temp_path = $${directory:tmp}/proxy_temp_path
fastcgi_temp_path = $${directory:tmp}/fastcgi_temp_path
uwsgi_temp_path = $${directory:tmp}/uwsgi_temp_path
scgi_temp_path = $${directory:tmp}/scgi_temp_path
[nginx-frontend]
# Network
local-ip = $${slap-network-information:local-ipv4}
port = 50006
global-ip = $${slap-network-information:global-ipv6}
# SSL
ssl-certificate = $${ca-nginx:cert-file}
ssl-key = $${ca-nginx:key-file}
# Log
path_pid = $${directory:run}/nginx.pid
path_log = $${directory:log}/nginx.log
path_access_log = $${directory:log}/nginx.access.log
path_error_log = $${directory:log}/nginx.error.log
path_tmp = $${buildout:directory}/tmp
# Config files
path_nginx_conf = $${directory:etc}/nginx.conf
# Executables
bin_nginx = ${nginx:location}/sbin/nginx
bin_launcher = $${directory:bin}/nginx
# Utils
path_shell = ${dash:location}/bin/dash
# Misc.
etc_dir = $${directory:etc}
[nginx_conf]
recipe = slapos.recipe.template:jinja2
template = ${template_nginx_conf:location}/${template_nginx_conf:filename}
rendered = $${nginx-frontend:path_nginx_conf}
context =
section param_nginx_frontend nginx-frontend
section param_tempdir tempdirectory
key socket gunicorn-frontend:socket
[nginx-launcher]
recipe = slapos.recipe.template:jinja2
template = ${nginx_template_launcher:location}/${nginx_template_launcher:filename}
rendered = $${nginx-frontend:bin_launcher}
mode = 700
context =
section param_nginx_frontend nginx-frontend
#---------------------
#--
#--WSGI
[gunicorn-frontend]
bin_gunicorn = $${directory:bin}/gunicorn
bin_launcher = $${directory:services}/gunicorn
path_shell = ${dash:location}/bin/dash
socket = $${directory:tmp}/flaskserver.sock
path_pid = $${directory:run}/gunicorn.pid
[gunicorn-launcher]
recipe = slapos.cookbook:wrapper
command-line = $${gunicorn-frontend:bin_gunicorn} www:app -p $${gunicorn-frontend:path_pid} -b unix:$${gunicorn-frontend:socket}
wrapper-path = $${gunicorn-frontend:bin_launcher}
environment = PYTHONPATH=$PYTHONPATH:$${directory:var}
[gunicorn-graceful]
recipe = slapos.cookbook:wrapper
command-line = $${directory:bin}/killpidfromfile $${gunicorn-frontend:path_pid} SIGHUP
wrapper-path = $${directory:scripts}/gunicorn-graceful
#--------------------
#--
#-- ssl certificates
[certificate-authority]
recipe = slapos.cookbook:certificate_authority
openssl-binary = ${openssl:location}/bin/openssl
ca-dir = $${directory:ca-dir}
requests-directory = $${cadirectory:requests}
wrapper = $${directory:services}/certificate_authority
ca-private = $${cadirectory:private}
ca-certs = $${cadirectory:certs}
ca-newcerts = $${cadirectory:newcerts}
ca-crl = $${cadirectory:crl}
[cadirectory]
recipe = slapos.cookbook:mkdirectory
requests = $${directory:ca-dir}/requests/
private = $${directory:ca-dir}/private/
certs = $${directory:ca-dir}/certs/
newcerts = $${directory:ca-dir}/newcerts/
crl = $${directory:ca-dir}/crl/
[ca-nginx]
<= certificate-authority
recipe = slapos.cookbook:certificate_authority.request
key-file = $${cadirectory:certs}/nginx_frontend.key
cert-file = $${cadirectory:certs}/nginx_frontend.crt
executable = $${nginx-launcher:rendered}
wrapper = $${directory:services}/nginx-frontend
# Put domain name
name = example.com
#copy in var/www the minimum files to create a flask application
[base-server]
recipe = hexagonit.recipe.download
url = ${server_base_py:location}/${server_base_py:filename}
#md5sum =
download-only = true
destination = $${directory:www}
mode = 0644
[base-module]
recipe = hexagonit.recipe.download
url = ${module_base_py:location}/${module_base_py:filename}
#md5sum =
download-only = true
destination = $${directory:www}
mode = 0644
# check promises
[nginx-promise]
recipe = slapos.cookbook:check_port_listening
path = $${directory:promises}/nginx
hostname = $${nginx-frontend:global-ip}
port = $${nginx-frontend:port}
[flask-promise]
recipe = slapos.cookbook:check_url_available
path = $${directory:promises}/flask
url = https://[$${nginx-frontend:global-ip}]:$${nginx-frontend:port}
dash_path = ${dash:location}/bin/dash
curl_path = ${curl:location}/bin/curl
[symlinks]
recipe = cns.recipe.symlink
symlink_target = $${directory:bin}
symlink_base = ${buildout:directory}/bin
\ No newline at end of file
[buildout]
parts =
switch_softwaretype
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
[switch_softwaretype]
recipe = slapos.cookbook:softwaretype
default = ${template-flask:output}
flask = ${template-flask:output}
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = $${slap-connection:computer-id}
partition = $${slap-connection:partition-id}
url = $${slap-connection:server-url}
\ No newline at end of file
#! {{ param_nginx_frontend['path_shell'] }}
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
# Run nginx
exec {{ param_nginx_frontend['bin_nginx'] }} -c {{ param_nginx_frontend['path_nginx_conf'] }}
\ No newline at end of file
worker_processes 1;
pid {{ param_nginx_frontend['path_pid'] }};
error_log {{ param_nginx_frontend['path_error_log'] }};
daemon off;
events {
worker_connections 1024;
accept_mutex off;
}
http {
default_type application/octet-stream;
access_log {{ param_nginx_frontend['path_access_log'] }} combined;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen [{{ param_nginx_frontend['global-ip'] }}]:{{ param_nginx_frontend['port'] }} ssl;
server_name _;
ssl_certificate {{ param_nginx_frontend['ssl-certificate'] }};
ssl_certificate_key {{ param_nginx_frontend['ssl-key'] }};
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
keepalive_timeout 90s;
client_body_temp_path {{ param_tempdir['client_body_temp_path'] }};
proxy_temp_path {{ param_tempdir['proxy_temp_path'] }};
fastcgi_temp_path {{ param_tempdir['fastcgi_temp_path'] }};
uwsgi_temp_path {{ param_tempdir['uwsgi_temp_path'] }};
scgi_temp_path {{ param_tempdir['scgi_temp_path'] }};
location / {
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Accel-Mapping /private/;
proxy_pass http://unix:{{ socket }};
}
}
}
\ No newline at end of file
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
# Stack for Flask microframework: http://flask.pocoo.org/
[buildout]
extends =
../../stack/slapos.cfg
../../stack/flask.cfg
../../component/nginx/buildout.cfg
../../component/dash/buildout.cfg
../../component/curl/buildout.cfg
parts =
slapos-cookbook
slapos-toolbox
eggs
template
nginx
nginx_template_launcher
template_nginx_conf
module_base_py
server_base_py
[template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg
output = ${buildout:directory}/template.cfg
md5sum = 9d60640c58337c9b40d11a9047044627
mode = 0644
[template-flask]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-flask.cfg
output = ${buildout:directory}/template-flask.cfg
md5sum = 9d38d13f46024625bb46a9e3c912dc17
mode = 0644
[template_nginx_conf]
recipe = slapos.recipe.download
url = ${:_profile_base_location_}/nginx_conf.in
md5sum = 53dbaa3b816a22f58ee609379cd6147e
filename = nginx_conf.in
location = ${buildout:parts-directory}/${:_buildout_section_name_}
mode = 0644
[nginx_template_launcher]
recipe = slapos.recipe.download
url = ${:_profile_base_location_}/launcher-nginx.in
md5sum = 0ca1502bddf082220e574ef867d7176b
filename = launcher-nginx.in
mode = 0644
location = ${buildout:parts-directory}/${:_buildout_section_name_}
[module_base_py]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
md5sum = 5ad39f196605b062e94b738da03fe91c
location = ${buildout:parts-directory}/${:_buildout_section_name_}
download-only = true
filename = __init__.py
mode = 0644
[server_base_py]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
md5sum = a2bf143a482d46dee421a24189a4b069
location = ${buildout:parts-directory}/${:_buildout_section_name_}
download-only = true
filename = server.py
mode = 0644
[slapos-toolbox]
recipe = zc.recipe.egg
eggs = slapos.toolbox
scripts = killpidfromfile
[eggs]
recipe = zc.recipe.egg
eggs =
slapos.cookbook
hexagonit.recipe.download
Gunicorn
[versions]
gunicorn = 18.0
Flask = 0.10
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment