Add support for installing Corporal web app with ASGI mode
This commit is contained in:
parent
0dd6a7e62a
commit
8c474e14d4
|
@ -12,7 +12,7 @@ from corporal.fablib import deploy_common
|
||||||
|
|
||||||
|
|
||||||
def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
||||||
port=7900, sitename=None, stage=False,
|
port=7900, asgi=False, sitename=None, stage=False,
|
||||||
coredir=None, lanes=None,
|
coredir=None, lanes=None,
|
||||||
core_office_url=None):
|
core_office_url=None):
|
||||||
"""
|
"""
|
||||||
|
@ -35,6 +35,12 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
||||||
c.sudo('chmod 0600 {}/pip.conf'.format(envdir))
|
c.sudo('chmod 0600 {}/pip.conf'.format(envdir))
|
||||||
mkdir(c, srcdir, owner=user, use_sudo=True)
|
mkdir(c, srcdir, owner=user, use_sudo=True)
|
||||||
|
|
||||||
|
# uvicorn
|
||||||
|
if asgi:
|
||||||
|
# (latest as of writing is 0.20.0)
|
||||||
|
c.sudo("bash -lc 'workon {} && pip install uvicorn[standard]'".format(envname),
|
||||||
|
user=user)
|
||||||
|
|
||||||
if stage:
|
if stage:
|
||||||
|
|
||||||
# pycorepos
|
# pycorepos
|
||||||
|
@ -116,6 +122,10 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
||||||
use_sudo=True, owner=user, mode='0600',
|
use_sudo=True, owner=user, mode='0600',
|
||||||
context={'env': env, 'envname': envname, 'envdir': envdir,
|
context={'env': env, 'envname': envname, 'envdir': envdir,
|
||||||
'port': port})
|
'port': port})
|
||||||
|
if asgi:
|
||||||
|
deploy_common(c, 'corporal/webasgi.conf.mako', '{}/webasgi.conf'.format(appdir),
|
||||||
|
use_sudo=True, owner=user, mode='0600',
|
||||||
|
context={'env': env, 'envname': envname, 'envdir': envdir})
|
||||||
deploy_common(c, 'corporal/upgrade.sh.mako', '{}/upgrade.sh'.format(appdir),
|
deploy_common(c, 'corporal/upgrade.sh.mako', '{}/upgrade.sh'.format(appdir),
|
||||||
use_sudo=True, owner=user,
|
use_sudo=True, owner=user,
|
||||||
context={'envdir': envdir, 'production': production})
|
context={'envdir': envdir, 'production': production})
|
||||||
|
@ -139,7 +149,8 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
||||||
|
|
||||||
# supervisor
|
# supervisor
|
||||||
deploy_common(c, 'corporal/supervisor.conf.mako', '/etc/supervisor/conf.d/{}.conf'.format(safename),
|
deploy_common(c, 'corporal/supervisor.conf.mako', '/etc/supervisor/conf.d/{}.conf'.format(safename),
|
||||||
use_sudo=True, context={'envdir': envdir, 'safename': safename})
|
use_sudo=True, context={'envdir': envdir, 'safename': safename,
|
||||||
|
'port': port, 'asgi': asgi})
|
||||||
c.sudo('supervisorctl update')
|
c.sudo('supervisorctl update')
|
||||||
c.sudo('supervisorctl start {}:'.format(safename))
|
c.sudo('supervisorctl start {}:'.format(safename))
|
||||||
|
|
||||||
|
@ -152,7 +163,8 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
||||||
# apache
|
# apache
|
||||||
deploy_common.apache_site(c, 'apache/site-corporal.mako', sitename,
|
deploy_common.apache_site(c, 'apache/site-corporal.mako', sitename,
|
||||||
enable=True,
|
enable=True,
|
||||||
context={'sitename': sitename, 'port': port})
|
context={'sitename': sitename, 'port': port,
|
||||||
|
'asgi': asgi})
|
||||||
apache.restart(c)
|
apache.restart(c)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,13 @@
|
||||||
ProxyPass "http://127.0.0.1:${port}/"
|
ProxyPass "http://127.0.0.1:${port}/"
|
||||||
ProxyPassReverse "http://127.0.0.1:${port}/"
|
ProxyPassReverse "http://127.0.0.1:${port}/"
|
||||||
</Location>
|
</Location>
|
||||||
|
% if asgi:
|
||||||
|
<Location "/ws/">
|
||||||
|
ProxyPreserveHost On
|
||||||
|
ProxyPass "ws://127.0.0.1:${port}/ws/"
|
||||||
|
ProxyPassReverse "ws://127.0.0.1:${port}/ws/"
|
||||||
|
</Location>
|
||||||
|
% endif
|
||||||
|
|
||||||
ErrorLog ${'$'}{APACHE_LOG_DIR}/error.log
|
ErrorLog ${'$'}{APACHE_LOG_DIR}/error.log
|
||||||
LogLevel warn
|
LogLevel warn
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
programs=${safename}_webmain
|
programs=${safename}_webmain
|
||||||
|
|
||||||
[program:${safename}_webmain]
|
[program:${safename}_webmain]
|
||||||
|
% if asgi:
|
||||||
|
environment=TAILBONE_ASGI_CONFIG="${envdir}/app/webasgi.conf"
|
||||||
|
command=${envdir}/bin/uvicorn --port ${port} --factory corporal.web.app:asgi_main
|
||||||
|
% else:
|
||||||
command=${envdir}/bin/pserve pastedeploy+ini:${envdir}/app/web.conf
|
command=${envdir}/bin/pserve pastedeploy+ini:${envdir}/app/web.conf
|
||||||
directory=${envdir}/app/work
|
directory=${envdir}/app/work
|
||||||
|
% endif
|
||||||
user=rattail
|
user=rattail
|
||||||
|
|
52
corporal/fablib/deploy/corporal/webasgi.conf.mako
Normal file
52
corporal/fablib/deploy/corporal/webasgi.conf.mako
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
## -*- mode: conf; -*-
|
||||||
|
|
||||||
|
<%text>############################################################</%text>
|
||||||
|
#
|
||||||
|
# config for Corporal web app
|
||||||
|
#
|
||||||
|
<%text>############################################################</%text>
|
||||||
|
|
||||||
|
|
||||||
|
<%text>##############################</%text>
|
||||||
|
# rattail
|
||||||
|
<%text>##############################</%text>
|
||||||
|
|
||||||
|
[rattail.config]
|
||||||
|
include = %(here)s/rattail.conf
|
||||||
|
|
||||||
|
[tailbone]
|
||||||
|
expose_websockets = true
|
||||||
|
|
||||||
|
|
||||||
|
<%text>##############################</%text>
|
||||||
|
# pyramid
|
||||||
|
<%text>##############################</%text>
|
||||||
|
|
||||||
|
[app:main]
|
||||||
|
use = egg:Corporal
|
||||||
|
|
||||||
|
pyramid.reload_templates = false
|
||||||
|
pyramid.debug_all = false
|
||||||
|
pyramid.default_locale_name = en
|
||||||
|
pyramid.includes = pyramid_exclog
|
||||||
|
|
||||||
|
beaker.session.type = file
|
||||||
|
beaker.session.data_dir = %(here)s/sessions/data
|
||||||
|
beaker.session.lock_dir = %(here)s/sessions/lock
|
||||||
|
beaker.session.secret = ${env.tailbone_beaker_secret}
|
||||||
|
beaker.session.key = ${envname}
|
||||||
|
|
||||||
|
pyramid_deform.tempdir = %(here)s/data/uploads
|
||||||
|
|
||||||
|
exclog.extra_info = true
|
||||||
|
|
||||||
|
# required for tailbone
|
||||||
|
rattail.config = %(__file__)s
|
||||||
|
|
||||||
|
|
||||||
|
<%text>##############################</%text>
|
||||||
|
# logging
|
||||||
|
<%text>##############################</%text>
|
||||||
|
|
||||||
|
[handler_file]
|
||||||
|
args = ('${envdir}/app/log/webasgi.log', 'a', 'utf_8')
|
Loading…
Reference in a new issue