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',
|
||||
port=7900, sitename=None, stage=False,
|
||||
port=7900, asgi=False, sitename=None, stage=False,
|
||||
coredir=None, lanes=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))
|
||||
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:
|
||||
|
||||
# pycorepos
|
||||
|
@ -116,6 +122,10 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
|||
use_sudo=True, owner=user, mode='0600',
|
||||
context={'env': env, 'envname': envname, 'envdir': envdir,
|
||||
'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),
|
||||
use_sudo=True, owner=user,
|
||||
context={'envdir': envdir, 'production': production})
|
||||
|
@ -139,7 +149,8 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
|||
|
||||
# supervisor
|
||||
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 start {}:'.format(safename))
|
||||
|
||||
|
@ -152,7 +163,8 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
|
|||
# apache
|
||||
deploy_common.apache_site(c, 'apache/site-corporal.mako', sitename,
|
||||
enable=True,
|
||||
context={'sitename': sitename, 'port': port})
|
||||
context={'sitename': sitename, 'port': port,
|
||||
'asgi': asgi})
|
||||
apache.restart(c)
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
ProxyPass "http://127.0.0.1:${port}/"
|
||||
ProxyPassReverse "http://127.0.0.1:${port}/"
|
||||
</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
|
||||
LogLevel warn
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
programs=${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
|
||||
directory=${envdir}/app/work
|
||||
% endif
|
||||
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