-
-
Save anonymous/a86328bf160155bcffbf to your computer and use it in GitHub Desktop.
This file contains 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 characters
$ cd /fabric/apib2b | |
$ fab -R prod deploy | |
================================================ | |
/fabric/apib2b/fabfile.py | |
from worker import * | |
env.roledefs = { | |
'int': ['localhost', 'localhost', 'www3'], | |
'prod': ['localhost', 'localhost', 'www2'] | |
} | |
deployer = ApiB2b(env) | |
@task | |
def deploy(): | |
deployer.deploy_code() | |
============================================ | |
/fabric/apib2b/worker.py | |
import sys | |
from fabric.api import * | |
from fabric.context_managers import settings | |
sys.path.insert(0, '/fabric/') | |
from Worker import Worker | |
class ApiB2b(Worker): | |
def doDeployment(self): | |
print "doing actual deployment!" | |
self.stop_tomcat() | |
self.updateGit() | |
self.start_tomcat() | |
def stop_tomcat(self): | |
self.info("stopping tomcat") | |
self.success("stopped tomcat") | |
def start_tomcat(self): | |
self.info("starting tomcat") | |
self.success("started tomcat") | |
def updateGit(self): | |
code_dir = '/fabric/xx-xx.git' | |
with settings(warn_only=True): | |
if run("test -d %s" % code_dir).failed: | |
self.info("directory does not exist! cloning new one .....") | |
run("git clone git@xxx/xx-xx.git %s" % code_dir) | |
else: | |
with cd(code_dir): | |
run("git log") | |
=================================== | |
/fabric/Worker.py | |
from fabric.colors import red, green, yellow | |
class Worker(object): | |
GIT_URL = "ssh://mygitserver/project" | |
DEPLOYED = '/opt/project/deployed/{}' | |
DEPLOYED_DIR = '/opt/project/deployed' | |
def __init__(self, env): | |
self.env = env | |
def doDeployment(self): | |
raise NotImplementedError | |
def deploy_code(self): | |
self.info("starting deployment") | |
self.info("using hosts: %s" % self.env.hosts) | |
self.doDeployment() | |
current = self.DEPLOYED.format('current') | |
# run('ln -s {} {}'.format(env.deploy, current)) | |
def info(self, msg): | |
print(yellow("INFO: %s " % msg)) | |
def success(self, msg): | |
print(green("SUCCESS: %s " % msg)) | |
def warn(self, msg): | |
print(red("WARN: %s " % msg)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment