replaced deploy script with management script

This commit is contained in:
David Thurstenson 2021-10-07 07:06:57 -05:00
parent 509bd26a79
commit 715dde950a
3 changed files with 94 additions and 13 deletions

4
.gitignore vendored
View File

@ -10,8 +10,8 @@
# Content folder where the actual ...ya know... content lives
!content/
# Deploy script
!deploy
# Management script
!tlwiki
# Themes directory
!themes/

11
deploy
View File

@ -1,11 +0,0 @@
#!/usr/bin/env bash
# To auto-deploy this on git push, add a symlink at .git/hooks/pre-push that points to this script
# Example: ln -s ../../deploy .git/hooks/pre-push
# Pull variables in from deploy_id
#source "$SCRIPT_DIR/deploy_id"
source "./deploy_id"
# Generate and push the output to the server
hugo && rsync -avz --delete public/ ${USER}@${HOST}:${DIR}

92
tlwiki Executable file
View File

@ -0,0 +1,92 @@
#!/usr/bin/env python3
import argparse
import yaml
import subprocess
# Valid commands
modecmds = [
'init',
'deploy',
'updeps',
'clean',
'reset',
'nukepave']
# Argument parsing setup
parser = argparse.ArgumentParser(description='Manage tlwiki source.')
parser.add_argument('mode', choices=modecmds,
help='Operation mode for this script')
parser.add_argument('--config', '-c',
default='tlwiki-conf.yaml',
type=argparse.FileType('r'),
help='Configuration file')
args = parser.parse_args()
# load config yaml into config dict
config = yaml.safe_load(args.config)
# General use functions
def cmd_run(*cmdstr):
try:
subprocess.run(cmdstr, check=True)
except subprocess.CalledProcessError:
print('E: Running `' + ' '.join(cmdstr) + '` failed')
exit
# Mode functions
def mode_clean(cfg):
cmd_run('git', 'clean', '-fd')
def mode_reset(cfg):
cmd_run('git', 'reset', '--hard',
cfg['repo']['remoteName'] + '/' + cfg['repo']['branch'])
def mode_init(cfg):
subprocess.run(['hugo', 'new', 'site', '.', '--force'])
def mode_updeps(cfg):
cmd_run('git', 'pull')
cmd_run('git', 'submodule', 'update', '--init', '--recursive')
def mode_deploy(cfg):
cmd_run('hugo')
deployid = cfg['deployID']
cmd_run('rsync', '-avz', '--delete',
'public/',
deployid['user'] + '@' + deployid['host'] + ':' + deployid['dir'])
# Mode switching
if args.mode == 'init':
mode_init(config)
elif args.mode == 'deploy':
mode_init(config)
mode_deploy(config)
elif args.mode == 'updeps':
mode_updeps(config)
elif args.mode == 'clean':
mode_clean(config)
elif args.mode == 'reset':
mode_reset(config)
elif args.mode == 'nukepave':
mode_reset(config)
mode_clean(config)
mode_updeps(config)
mode_init(config)
else:
raise Exception("Invalid mode: " + args.mode)
exit