Last active
January 25, 2019 23:51
Revisions
-
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 19 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,10 @@ Simple web server that listens for Github webhooks to implement push-to-deploy with Pelican static sites Settings are loaded from a json file except for SECRET which should be an environment variable Example `deployer.json` { "repos": { @@ -24,19 +24,26 @@ Add http://<deployer_host>/mysite/thisisasecret as a webhook url and you're done """ import logging import os import subprocess import sys from flask import Flask, json, jsonify, request app = Flask(__name__) def sh(cmd, **kwargs): cmd = cmd.format(**kwargs) output = subprocess.check_output( cmd, stderr=subprocess.STDOUT, shell=True, ) app.logger.info('\n' + cmd) app.logger.info('\n'.join([' > ' + l for l in output.split('\n')])) @app.route('/<repo_id>/{}'.format(os.environ['SECRET']), methods=['POST']) def deploy(repo_id): @@ -45,12 +52,12 @@ def deploy(repo_id): repo = app.config['repos'][repo_id] os.chdir(repo['root']) sh( 'git checkout {branch}', branch=branch, ) sh( 'git pull --ff-only {remote} {branch}', remote=repo.get('remote', 'origin'), branch=branch, ) sh( @@ -63,4 +70,7 @@ def deploy(repo_id): if __name__ == '__main__': with open(sys.argv[1]) as f: app.config.update(**json.load(f)) app.logger.addHandler(logging.StreamHandler()) app.logger.setLevel(logging.INFO) app.run(port=int(os.environ.get('PORT', 5000))) -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Settings are loaded from a json file except for SECRET which should be an environment variable Example deployer.json { "repos": { -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,9 +55,7 @@ def deploy(repo_id): ) sh( 'pelican -d -o {output} content', output=repo['output'].format(branch=branch, **payload), ) return jsonify(dict(ok=True)) -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,7 @@ Add http://<deployer_host>/mysite/thisisasecret as a webhook url and you're done """ import os import sys from subprocess import check_output from flask import Flask, json, jsonify, request @@ -62,6 +63,6 @@ def deploy(repo_id): if __name__ == '__main__': with open(sys.argv[1]) as f: app.config.update(**json.load(f)) app.run(port=int(os.environ.get('PORT', 5000))) -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,10 +48,15 @@ def deploy(repo_id): remote=repo.get('remote', 'origin'), branch=branch, ) sh( 'git checkout -f {branch}', branch=branch, ) sh( 'pelican -d -o {output} content', output=repo['output'], branch=branch, **payload ) return jsonify(dict(ok=True)) -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ "mysite": { "root": "/path/to/repo", "remote": "origin", "output": "/srv/www/{branch}" } }, "port": 5000 @@ -49,7 +49,7 @@ def deploy(repo_id): branch=branch, ) sh( 'pelican -d -o {output} content', output=repo['output'], branch=branch, ) -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 10 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,12 @@ """ Simple web server that listens for Github webhooks to implement push-to-deploy with Pelican static sites Settings are loaded from a json file except for SECRET which should be an environment variable Example `deployer.json` { "repos": { "mysite": { @@ -20,6 +17,12 @@ }, "port": 5000 } Run it $ SECRET=thisisasecret python ./pelican_deployer.py deployer.json Add http://<deployer_host>/mysite/thisisasecret as a webhook url and you're done """ import os from subprocess import check_output -
marksteve revised this gist
Jan 6, 2014 . 1 changed file with 27 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,49 +2,58 @@ Simple web server that listens for Github webhooks to implement push-to-deploy with Pelican static sites Usage: $ python ./pelican_deployer.py deployer.json Settings are loaded from a json file except for SECRET which should be an env variable Example deployer.json: { "repos": { "mysite": { "root": "/path/to/repo", "remote": "origin", "output": "/srv/www" } }, "port": 5000 } """ import os from subprocess import check_output from flask import Flask, json, jsonify, request app = Flask(__name__) def sh(cmd, **kwargs): app.logger.info(check_output(cmd.format(**kwargs), shell=True)) @app.route('/<repo_id>/{}'.format(os.environ['SECRET']), methods=['POST']) def deploy(repo_id): payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] repo = app.config['repos'][repo_id] os.chdir(repo['root']) sh( 'git pull {remote} {branch}', remote=repo.get('remote', 'origin'), branch=branch, ) sh( 'pelican -d -o {output}/{branch} content', output=repo['output'], branch=branch, ) return jsonify(dict(ok=True)) if __name__ == '__main__': with open('deployer.json') as f: app.config.update(**json.load(f)) app.run(port=int(os.environ.get('PORT', 5000))) -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ """ Simple web server that listens for Github webhooks to implement push-to-deploy with Pelican static sites s Usage: $ python ./pelican_deployer.py -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ """ Simple web server that listens for Github service hooks to implement push-to-deploy with Pelican static sites Usage: $ python ./pelican_deployer.py -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ """ Simple web server that listens for Github service hooks to deploy Pelican static sites Usage: $ python ./pelican_deployer.py -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Usage: $ python ./pelican_deployer.py Settings are loaded from environment variables SECRET=<secret key> REMOTE=<git remote> (defaults to origin) -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Usage: $ python ./pelican_deployer.py Settings are loaded from environt SECRET=<secret key> REMOTE=<git remote> (defaults to origin) -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ """ Simple web server that accepts Github service hooks to deploy Pelican static sites Usage: -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ """ Simple web server that accepts Github serice hooks to deploy Pelican static sites Usage: $ python ./pelican_deployer.py -
marksteve revised this gist
Jan 5, 2014 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,17 @@ """ Deploy Pelican with Flask and Github Service Hooks Usage: $ python ./pelican_deployer.py Settings are loaded from env: SECRET=<secret key> REMOTE=<git remote> (defaults to origin) ROOT=<output root> (defaults to /srv/pelican) PORT=<port> (defaults to 5000) """ import os from subprocess import check_output -
marksteve renamed this gist
Jan 5, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,8 @@ def sh(cmd, **kwargs): app.logger.info(check_output(cmd.format(**kwargs), shell=True)) @app.route('/{}'.format(os.environ['SECRET']), methods=['POST']) def deploy(): payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] -
marksteve revised this gist
Jan 4, 2014 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import os from subprocess import check_output from flask import Flask, json, jsonify, request app = Flask(__name__) @@ -10,11 +10,8 @@ def sh(cmd, **kwargs): app.logger.info(check_output(cmd.format(**kwargs), shell=True)) @app.route('/<{}>'.format(os.environ['SECRET']), methods=['POST']) def deploy(secret): payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] -
marksteve revised this gist
Jan 4, 2014 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,23 @@ import os from subprocess import check_output from flask import abort, Flask, json, jsonify, request app = Flask(__name__) def sh(cmd, **kwargs): app.logger.info(check_output(cmd.format(**kwargs), shell=True)) @app.route('/<secret>', methods=['POST']) def deploy(secret): if secret != os.environ['SECRET']: abort(403) payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] sh( 'git pull {remote} {branch}', remote=os.environ.get('REMOTE', 'origin'), @@ -37,3 +34,4 @@ def deploy(secret): if __name__ == '__main__': app.run(port=int(os.environ.get('PORT', 5000))) -
marksteve revised this gist
Jan 4, 2014 . 1 changed file with 17 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,20 +5,33 @@ from flask import abort, Flask, json, jsonify, request app = Flask(__name__) def sh(cmd, **kwargs): print(check_output(cmd.format(**kwargs), shell=True)) @app.route('/<secret>', methods=['POST']) def deploy(secret): if secret != os.environ['SECRET']: abort(403) payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] sh( 'git pull {remote} {branch}', remote=os.environ.get('REMOTE', 'origin'), branch=branch, ) sh( 'pelican -d -o {root}/{branch} content', root=os.environ.get('ROOT', '/srv/pelican'), branch=branch, ) return jsonify(dict(ok=True)) -
marksteve revised this gist
Jan 4, 2014 . 1 changed file with 7 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ from __future__ import print_function import os from subprocess import check_output from flask import abort, Flask, json, jsonify, request @@ -13,18 +12,13 @@ def post(secret): if secret != os.environ['SECRET']: abort(403) payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] cmd = 'pelican -d -o {root}/{branch} content' print(check_output(cmd.format( root=os.environ.get('ROOT', '/srv/pelican'), branch=branch, ), shell=True)) return jsonify(dict(ok=True)) -
marksteve revised this gist
Jan 3, 2014 . 1 changed file with 2 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,12 +17,8 @@ def post(secret): print('Deploying...') payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] cmd = 'pelican -d -o {root}/{branch} content' print(check_output(cmd.format( root=os.environ.get('ROOT', '/srv/pelican'), branch=branch, ), shell=True)) -
marksteve renamed this gist
Jan 3, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
marksteve created this gist
Jan 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ from __future__ import print_function import os import traceback from subprocess import check_output from flask import abort, Flask, json, jsonify, request app = Flask(__name__) @app.route('/<secret>', methods=['POST']) def post(secret): if secret != os.environ['SECRET']: abort(403) try: print('Deploying...') payload = json.loads(request.form['payload']) branch = payload.get('ref').split('/')[2] cmds = [ 'rm -rf output/', 'pelican content', 'rsync -r -m -h --delete --progress output/ {root}/{branch}', ] print(check_output(' && '.join(cmds).format( root=os.environ.get('ROOT', '/srv/pelican'), branch=branch, ), shell=True)) except Exception: traceback.print_exc() raise return jsonify(dict(ok=True)) if __name__ == '__main__': app.run(port=int(os.environ.get('PORT', 5000)))