Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
164 lines (132 sloc) 4.68 KB
# -*- python -*-
# ex: set syntax=python:
import os
from buildbot.buildslave import BuildSlave
from buildbot.status import html, web
from buildbot.status.builder import SUCCESS,WARNINGS,FAILURE,EXCEPTION,RETRY
from buildbot.process import factory
from buildbot.steps.shell import ShellCommand
from buildbot.steps.source import Git, SVN
from buildbot.config import BuilderConfig
from buildbot.changes import svnpoller, gitpoller
from buildbot.schedulers.basic import Scheduler
from buildbot.schedulers.filter import ChangeFilter
import yay
c['slaves'] = [
BuildSlave('pb', 'pb'),
]
c['status'].append(html.WebStatus(
http_port="8080",
allowForce=True,
public_html=os.path.join(os.path.dirname(web.__file__), "files"),
))
c['slavePortnum'] = "8079"
c['change_source'] = []
def if_failing(step):
""" I am a doStepIf function that returns True if a build is failing """
return step.build.result in (FAILURE, EXCEPTION, RETRY)
def if_succeeding(step):
""" I am a doStepIf function that returns True if build is succeeding """
return step.build.result in (SUCCESS, WARNINGS)
def vagrant(cmd):
""" I prepend the path to the vagrant command """
return "%s %s" % (config.VAGRANT, cmd)
def add_cleanup_steps(f, kind, desired):
""" Add cleanup steps for rolling back or throwing build away """
if kind == "fail":
dsi = if_failing
always_run = True
else:
dsi = if_succeeding
always_run = False
if desired == "rollback":
f.addStep(ShellCommand(
name="rollback-if-%s" % kind,
description="rollback-if-%s" % kind,
command=vagrant("snap back"),
doStepIf=dsi,
alwaysRun=True,
))
elif desired == "destroy":
f.addStep(ShellCommand(
name="destroy-if-%s" % kind,
description="destroy-if-%s" % kind,
command=vagrant("destroy"),
doStepIf=dsi,
alwaysRun=always_run,
))
def add_deployment(f, project):
""" Add a `vagrant up` / `vagrant deploy` run to a BuildFactory """
on_failure = project.get("on-failure", "rollback")
on_success = project.get("on-success", "leave-running")
# Do a snapshot of cluster before deploying to it
# But only need to do that if we are required to rollback
if on_failure == "rollback" or on_success == "rollback":
f.addStep(ShellCommand(
name="snapshot",
description="snapshot",
command=vagrant("snap take"),
))
f.addStep(ShellCommand(
name="up",
description="up",
command=vagrant("up"),
))
f.addStep(ShellCommand(
name="provision",
description="provision",
command=vagrant("provision"),
))
add_cleanup_steps(f, "fail", on_failure)
add_cleanup_steps(f, "success", on_success)
path = os.path.join(os.path.dirname(__file__), "caroline.yay")
cfg = yay.load_uri(path)
for project in cfg.get('projects', []):
repo = project["repo"]
f = factory.BuildFactory()
if repo["type"] == "git":
f.addStep(Git(
repourl=repo["url"],
))
elif repo["type"] == "svn":
f.addStep(SVN(
baseURL=repo["url"],
defaultBranch="trunk",
username=repo.get("username", None),
password=repo.get("password", None),
))
add_deployment(f, project)
c['builders'].append(BuilderConfig(
name = project['name'],
slavename = 'pb',
factory = f,
env = dict(
PATH = ":".join([config.PATH] + os.environ["PATH"].split(":")),
),
))
# Build any time poller picks up changes
c['schedulers'].append(Scheduler(
name=project["name"],
builderNames=[project["name"]],
change_filter=ChangeFilter(project=project["name"]),
))
# Set up polling for the projects repository
# Each poller will get its own directory to store state in
pollerdir = os.path.join(config.VARDIR, "pollers", project["name"])
if not os.path.exists(pollerdir):
os.makedirs(pollerdir)
if repo["type"] == "git":
c['change_source'].append(gitpoller.GitPoller(
repourl=repo["url"],
workdir=pollerdir,
project=project["name"],
))
elif repo["type"] == "svn":
c['change_source'].append(svnpoller.SVNPoller(
svnurl=repo["url"],
cachepath=os.path.join(pollerdir, "pollerstate"),
project=project["name"],
split_file=svnpoller.split_file_branches,
svnuser=repo.get("username", None),
svnpasswd=repo.get("password", None),
))
Something went wrong with that request. Please try again.