Skip to content

Instantly share code, notes, and snippets.

@akloboucnik
Last active January 2, 2016 02:28
Show Gist options
  • Save akloboucnik/8236826 to your computer and use it in GitHub Desktop.
Save akloboucnik/8236826 to your computer and use it in GitHub Desktop.
JSBin deployment
from fabric.api import settings, run, cd
from fabric.state import env
from fabric.contrib.console import confirm
from fabric.context_managers import shell_env
from os import urandom
# yum install node sqlite-devel gcc-c++
def install_rpms():
# TODO check if installed first
run('yum -y install node sqlite-devel gcc-c++')
# TODO maybe create user for running jsbin?
# npm install jsbin
def install_jsbin():
with settings(warn_only = True):
if run('npm list -g --parseable | grep jsbin').failed:
run('npm install -g jsbin')
# copy template config file
def create_config():
with cd('/root'):
with settings(warn_only = True):
if run('test -f jsbin.json').failed:
# get config template
run('wget https://gist.github.com/akloboucnik/8236826/raw/bc02be025920fc66eba4f6cf8ba9a56c642a2801/jsbin.json')
# replace values in template
run('sed -i "s/<hostname>/%s/g" jsbin.json' % env.host)
run('sed -i "s/<session_secret>/%s/g" jsbin.json' % urandom(16).encode('hex'))
# TODO install custom template
# run as nohup on 8080 port
def run_jsbin():
with shell_env(JSBIN_CONFIG='/root/jsbin.json'):
with cd('/root'):
run('sh -c "((nohup jsbin 2>&1 >/dev/null </dev/null) &)"', pty=False)
def deploy():
install_rpms()
install_jsbin()
create_config()
run_jsbin()
{
"env": "development",
"timezone": "UTC",
"url": {
"host": "<hostname>:8000",
"prefix": "/",
"ssl": false,
"static": false
},
"max-request-size": "1MB",
"store": {
"adapter": "sqlite",
"sqlite": {
"location": "/tmp/jsbin.db"
},
"mysql": {
"host": "localhost",
"user": "root",
"password": "",
"database": "jsbin",
"charset": "utf8mb4",
"collate": "utf8mb4_unicode_ci"
}
},
"session": {
"secret": "<session_secret>"
},
"analytics": {
"id": null
},
"mail": {
"adapter": "sendmail",
"sendmail": {},
"smtp": {
"service": "Gmail",
"auth": {
"user": "",
"pass": ""
}
}
},
"server": {
"logger": "default"
},
"notify": {
"errors": [],
"report": []
},
"blacklist": {
"html": ["processform.cgi", "habbo.com"],
"css": [],
"javascript": []
},
"reserved": [
"list",
"show",
"gist",
"about",
"account",
"accounts",
"activity",
"all",
"announcements",
"api_rules",
"api_terms",
"apirules",
"apps",
"archive",
"auth",
"badges",
"blog",
"business",
"contacts",
"devices",
"download",
"downloads",
"faq",
"favorites",
"favs",
"find_sources",
"find_users",
"followers",
"following",
"friend_request",
"friendrequest",
"friends",
"goodies",
"help",
"home",
"inbox",
"invitations",
"invite",
"jobs",
"login",
"logout",
"me",
"messages",
"notifications",
"nudge",
"oauth",
"privacy",
"rules",
"search",
"sent",
"settings",
"share",
"signup",
"signin",
"static",
"statistics",
"terms",
"tos",
"translate",
"trends",
"users",
"unarchive",
"user",
"widgets",
"tutorials",
"video",
"videos"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment