Add upgrade script/config to installer
This commit is contained in:
		
							parent
							
								
									9bb0bca325
								
							
						
					
					
						commit
						7e3b38aaee
					
				
					 4 changed files with 204 additions and 5 deletions
				
			
		
							
								
								
									
										5
									
								
								MANIFEST.in
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								MANIFEST.in
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| 
 | ||||
| include *.md | ||||
| include *.rst | ||||
| 
 | ||||
| recursive-include messkit/templates *.mako | ||||
|  | @ -25,6 +25,7 @@ Messkit commands | |||
| """ | ||||
| 
 | ||||
| import os | ||||
| import stat | ||||
| import sys | ||||
| import subprocess | ||||
| 
 | ||||
|  | @ -35,6 +36,7 @@ from rich import print as rprint | |||
| from alembic.util.messaging import obfuscate_url_pw | ||||
| 
 | ||||
| from rattail import commands | ||||
| from rattail.files import resource_path | ||||
| 
 | ||||
| from messkit import __version__ | ||||
| 
 | ||||
|  | @ -71,11 +73,13 @@ class Install(commands.Subcommand): | |||
|         rprint("\n\tThis tool will install and configure a new app.") | ||||
|         rprint("\n\t[italic]NB. You should already have created a new database in PostgreSQL.[/italic]") | ||||
| 
 | ||||
|         # get appdir path | ||||
|         appdir = os.path.join(sys.prefix, 'app') | ||||
|         appdir = self.basic_prompt('appdir path', appdir) | ||||
|         # continue? | ||||
|         if not self.basic_prompt("continue?", True, is_bool=True): | ||||
|             rprint() | ||||
|             sys.exit(0) | ||||
| 
 | ||||
|         # appdir must not yet exist | ||||
|         appdir = os.path.join(sys.prefix, 'app') | ||||
|         if os.path.exists(appdir): | ||||
|             rprint("\n\t[bold red]appdir already exists:[/bold red]  {}\n".format(appdir)) | ||||
|             sys.exit(1) | ||||
|  | @ -106,8 +110,9 @@ class Install(commands.Subcommand): | |||
|         # make the appdir | ||||
|         self.app.make_appdir(appdir) | ||||
| 
 | ||||
|         # make config files | ||||
|         # shared context for generated app files | ||||
|         context = { | ||||
|             'envdir': sys.prefix, | ||||
|             'app_package': 'messkit', | ||||
|             'app_title': "Messkit", | ||||
|             'appdir': appdir, | ||||
|  | @ -115,14 +120,28 @@ class Install(commands.Subcommand): | |||
|             'pyramid_egg': 'Messkit', | ||||
|             'beaker_key': 'messkit', | ||||
|         } | ||||
| 
 | ||||
|         # make config files | ||||
|         rattail_conf = self.app.make_config_file( | ||||
|             'rattail-complete', os.path.join(appdir, 'rattail.conf'), | ||||
|             'rattail', os.path.join(appdir, 'rattail.conf'), | ||||
|             template_path=resource_path('messkit:templates/installer/rattail.conf.mako'), | ||||
|             **context) | ||||
|         quiet_conf = self.app.make_config_file('quiet', appdir) | ||||
|         web_conf = self.app.make_config_file( | ||||
|             'web-complete', os.path.join(appdir, 'web.conf'), | ||||
|             **context) | ||||
| 
 | ||||
|         # make upgrade script | ||||
|         path = os.path.join(appdir, 'upgrade.sh') | ||||
|         self.app.render_mako_template( | ||||
|             resource_path('messkit:templates/installer/upgrade.sh.mako'), | ||||
|             context, output_path=path) | ||||
|         os.chmod(path, stat.S_IRWXU | ||||
|                  | stat.S_IRGRP | ||||
|                  | stat.S_IXGRP | ||||
|                  | stat.S_IROTH | ||||
|                  | stat.S_IXOTH) | ||||
| 
 | ||||
|         rprint("\n\tappdir created at:  [bold green]{}[/bold green]".format(appdir)) | ||||
| 
 | ||||
|         bindir = os.path.join(sys.prefix, 'bin') | ||||
|  |  | |||
							
								
								
									
										146
									
								
								messkit/templates/installer/rattail.conf.mako
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										146
									
								
								messkit/templates/installer/rattail.conf.mako
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,146 @@ | |||
| ## -*- mode: conf; -*- | ||||
| 
 | ||||
| <%text>############################################################</%text> | ||||
| # | ||||
| # ${app_title} core config | ||||
| # | ||||
| <%text>############################################################</%text> | ||||
| 
 | ||||
| 
 | ||||
| <%text>##############################</%text> | ||||
| # rattail | ||||
| <%text>##############################</%text> | ||||
| 
 | ||||
| [rattail] | ||||
| app_package = ${app_package} | ||||
| timezone.default = ${timezone} | ||||
| appdir = ${appdir} | ||||
| datadir = ${os.path.join(appdir, 'data')} | ||||
| batch.files = ${os.path.join(appdir, 'data', 'batch')} | ||||
| workdir = ${os.path.join(appdir, 'work')} | ||||
| export.files = ${os.path.join(appdir, 'data', 'exports')} | ||||
| 
 | ||||
| [rattail.config] | ||||
| # require = /etc/rattail/rattail.conf | ||||
| configure_logging = true | ||||
| usedb = true | ||||
| preferdb = true | ||||
| 
 | ||||
| [rattail.db] | ||||
| default.url = ${db_url} | ||||
| versioning.enabled = true | ||||
| 
 | ||||
| [rattail.mail] | ||||
| 
 | ||||
| # this is the global email shutoff switch | ||||
| #send_emails = false | ||||
| 
 | ||||
| # recommended setup is to always talk to postfix on localhost and then | ||||
| # it can handle any need complexities, e.g. sending to relay | ||||
| smtp.server = localhost | ||||
| 
 | ||||
| # by default only email templates from rattail proper are used | ||||
| templates = rattail:templates/mail | ||||
| 
 | ||||
| # this is the "default" email profile, from which all others initially | ||||
| # inherit, but most/all profiles will override these values | ||||
| default.prefix = [${app_title}] | ||||
| default.from = rattail@localhost | ||||
| default.to = root@localhost | ||||
| # nb. in test environment it can be useful to disable by default, and | ||||
| # then selectively enable certain (e.g. feedback, upgrade) emails | ||||
| #default.enabled = false | ||||
| 
 | ||||
| [rattail.upgrades] | ||||
| command = ${os.path.join(appdir, 'upgrade.sh')} --verbose | ||||
| files = ${os.path.join(appdir, 'data', 'upgrades')} | ||||
| 
 | ||||
| 
 | ||||
| <%text>##############################</%text> | ||||
| # alembic | ||||
| <%text>##############################</%text> | ||||
| 
 | ||||
| [alembic] | ||||
| script_location = rattail.db:alembic | ||||
| version_locations = rattail.db:alembic/versions | ||||
| 
 | ||||
| 
 | ||||
| <%text>##############################</%text> | ||||
| # logging | ||||
| <%text>##############################</%text> | ||||
| 
 | ||||
| [loggers] | ||||
| keys = root, exc_logger, beaker, txn, sqlalchemy, django_db, flufl_bounce, requests | ||||
| 
 | ||||
| [handlers] | ||||
| keys = file, console, email | ||||
| 
 | ||||
| [formatters] | ||||
| keys = generic, console | ||||
| 
 | ||||
| [logger_root] | ||||
| handlers = file, console | ||||
| level = DEBUG | ||||
| 
 | ||||
| [logger_exc_logger] | ||||
| qualname = exc_logger | ||||
| handlers = email | ||||
| level = ERROR | ||||
| 
 | ||||
| [logger_beaker] | ||||
| qualname = beaker | ||||
| handlers = | ||||
| level = INFO | ||||
| 
 | ||||
| [logger_txn] | ||||
| qualname = txn | ||||
| handlers = | ||||
| level = INFO | ||||
| 
 | ||||
| [logger_sqlalchemy] | ||||
| qualname = sqlalchemy.engine | ||||
| handlers = | ||||
| # handlers = file | ||||
| # level = INFO | ||||
| 
 | ||||
| [logger_django_db] | ||||
| qualname = django.db.backends | ||||
| handlers = | ||||
| level = INFO | ||||
| # level = DEBUG | ||||
| 
 | ||||
| [logger_flufl_bounce] | ||||
| qualname = flufl.bounce | ||||
| handlers = | ||||
| level = WARNING | ||||
| 
 | ||||
| [logger_requests] | ||||
| qualname = requests | ||||
| handlers = | ||||
| # level = WARNING | ||||
| 
 | ||||
| [handler_file] | ||||
| class = handlers.RotatingFileHandler | ||||
| args = (${repr(os.path.join(appdir, 'log', 'rattail.log'))}, 'a', 1000000, 100, 'utf_8') | ||||
| formatter = generic | ||||
| 
 | ||||
| [handler_console] | ||||
| class = StreamHandler | ||||
| args = (sys.stderr,) | ||||
| formatter = console | ||||
| # formatter = generic | ||||
| # level = INFO | ||||
| # level = WARNING | ||||
| 
 | ||||
| [handler_email] | ||||
| class = handlers.SMTPHandler | ||||
| args = ('localhost', 'rattail@localhost', ['root@localhost'], "[Rattail] Logging") | ||||
| formatter = generic | ||||
| level = ERROR | ||||
| 
 | ||||
| [formatter_generic] | ||||
| format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(funcName)s: %(message)s | ||||
| datefmt = %Y-%m-%d %H:%M:%S | ||||
| 
 | ||||
| [formatter_console] | ||||
| format = %(levelname)-5.5s [%(name)s][%(threadName)s] %(funcName)s: %(message)s | ||||
							
								
								
									
										29
									
								
								messkit/templates/installer/upgrade.sh.mako
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										29
									
								
								messkit/templates/installer/upgrade.sh.mako
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,29 @@ | |||
| #!/bin/sh -e | ||||
| <%text>##################################################</%text> | ||||
| # | ||||
| # upgrade script for ${app_title} app | ||||
| # | ||||
| <%text>##################################################</%text> | ||||
| 
 | ||||
| if [ "$1" = "--verbose" ]; then | ||||
|     VERBOSE='--verbose' | ||||
|     QUIET= | ||||
| else | ||||
|     VERBOSE= | ||||
|     QUIET='--quiet' | ||||
| fi | ||||
| 
 | ||||
| cd ${envdir} | ||||
| 
 | ||||
| PIP='bin/pip' | ||||
| ALEMBIC='bin/alembic' | ||||
| 
 | ||||
| # upgrade pip and friends | ||||
| $PIP install $QUIET --disable-pip-version-check --upgrade pip | ||||
| $PIP install $QUIET --upgrade setuptools wheel | ||||
| 
 | ||||
| # upgrade app proper | ||||
| $PIP install $QUIET --upgrade --upgrade-strategy eager Messkit | ||||
| 
 | ||||
| # migrate schema | ||||
| $ALEMBIC -c app/rattail.conf upgrade heads | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar