Пример #1
0
bot = Robot()

clone_url = os.getenv("GOPHER_CUSTOM_REPOSITORY")
clone_branch = os.getenv("GOPHER_CUSTOM_BRANCH")
cfgdir = os.getenv("GOPHER_CONFIGDIR")

if not clone_url:
    bot.Say("GOPHER_CUSTOM_REPOSITORY not set")
    exit()

if not cfgdir:
    bot.Say("GOPHER_CONFIGDIR not set")
    bot.Log("Error", "GOPHER_CONFIGDIR not set in updatecfg.py")
    exit()

if not bot.Exclusive("updatecfg", False):
    bot.Say("Configuration update already in progress")
    bot.Log("Warn", "Configuration update already in progress, exiting")
    exit()

bot.SetWorkingDirectory(cfgdir)
bot.FailTask("tail-log", [])
bot.FailTask("status", ["Updating configuration failed"])

bot.AddTask("git-init", [clone_url])
bot.AddTask("exec", ["git", "pull"])
bot.AddTask("run-pipeline", [])
bot.AddTask("status", ["Custom configuration repository successfully updated"])
bot.AddCommand("builtin-admin", "reload")
Пример #2
0
if not cfgdir:
    bot.Say("GOPHER_CONFIGDIR not set")
    bot.Log("Error", "GOPHER_CONFIGDIR not set in updatecfg.py")
    exit()

if not bot.Exclusive("updatecfg", False):
    bot.Say("Configuration update already in progress")
    bot.Log("Warn", "Configuration update already in progress, exiting")
    exit()

bot.FailTask("status", [ "Updating configuration failed, check history for 'updatecfg'"])

if not clone_url.startswith("http"):
    match = re.match(r"ssh://(?:.*@)?([^:/]*)(?::([^/]*)/)?", clone_url)
    if match:
        bot.AddTask("ssh-init", [])
        scanhost = match.group(1)
        if match.group(2):
            scanhost = "%s:%s" % ( scanhost, match.group(2) )
        bot.AddTask("ssh-scan", [ scanhost ])
    else:
        match = re.match(r"(?:.*@)?([^:/]*)", clone_url)
        if match:
            bot.AddTask("ssh-init", [])
            bot.AddTask("ssh-scan", [ match.group(1) ])

bot.AddTask("git-sync", [ clone_url, clone_branch, cfgdir, "true" ])
bot.AddTask("runpipeline", [])
bot.AddTask("status", [ "Custom configuration repository successfully updated" ])
bot.AddCommand("builtin-admin", "reload")
Пример #3
0
repobranch = "%s/%s" % (repository, branch)
if not bot.Exclusive(repobranch, False):
    bot.Log("Warn", "Build of '%s' already in progress, exiting" % repobranch)
    if len(bot.user) > 0:
        bot.Say(
            "localbuild of '%s' already in progress, not starting a new build"
            % repobranch)
    exit()

bot.ExtendNamespace(repobranch, keep_history)

if not clone_url.startswith("http"):
    match = re.match(r"ssh://(?:.*@)?([^:/]*)(?::([^/]*)/)?", clone_url)
    if match:
        bot.AddTask("ssh-init", [])
        scanhost = match.group(1)
        if match.group(2):
            scanhost = "%s:%s" % (scanhost, match.group(2))
        bot.AddTask("ssh-scan", [scanhost])
    else:
        match = re.match(r"(?:.*@)?([^:/]*)", clone_url)
        if match:
            bot.AddTask("ssh-init", [])
            bot.AddTask("ssh-scan", [match.group(1)])

# Start with a clean jobdir
bot.AddTask("cleanup", [])
bot.AddTask("git-sync", [clone_url, branch, repobranch, "true"])
bot.AddTask("runpipeline", [])
Пример #4
0
sys.path.append("%s/lib" % os.getenv("GOPHER_INSTALLDIR"))
from gopherbot_v2 import Robot

bot = Robot()

cfgdir = os.getenv("GOPHER_CONFIGDIR")
try:
    os.stat("%s/git/config" % cfgdir)
except FileNotFoundError:
    bot.Log("Warn", "%s/git/config not found, git push will fail" % cfgdir)

bot.SetParameter("XDG_CONFIG_HOME", cfgdir)

# Pop off the executable path
sys.argv.pop(0)

clone_url = sys.argv.pop(0)

if not clone_url.startswith("http"):
    match = re.match(r"ssh://(?:.*@)?([^:/]*)(?::([^/]*)/)?", clone_url)
    if match:
        scanhost = match.group(1)
        if match.group(2):
            scanhost = "%s:%s" % (scanhost, match.group(2))
    else:
        match = re.match(r"(?:.*@)?([^:/]*)", clone_url)
        if match:
            scanhost = match.group(1)
    bot.AddTask("ssh-init", [])
    bot.AddTask("ssh-scan", [scanhost])
Пример #5
0
bot.Log("Info", "Creating bootstrap pipeline for %s" % clone_url)

ssh_repo = False
if not clone_url.startswith("http"):
    match = re.match(r"ssh://(?:.*@)?([^:/]*)(?::([^/]*)/)?", clone_url)
    if match:
        ssh_repo = True
        scanhost = match.group(1)
        if match.group(2):
            scanhost = "%s:%s" % ( scanhost, match.group(2) )
    else:
        match = re.match(r"(?:.*@)?([^:/]*)", clone_url)
        if match:
            ssh_repo = True
            scanhost = match.group(1)

if ssh_repo:
    depkey = os.getenv("DEPLOY_KEY")
    if len(depkey) == 0:
        bot.Log("Error", "GOPHER_CUSTOM_REPOSITORY needs ssh, but no DEPLOY_KEY set")
        exit(1)
    bot.SetParameter("DEPLOY_KEY", depkey)
    bot.AddTask("ssh-init", ["bootstrap"])
    bot.AddTask("ssh-scan", [ scanhost ])

tkey = os.path.join(cfgdir, "binary-encrypted-key")
bot.AddTask("exec", [ "rm", "-f", tkey ])
bot.AddTask("git-sync", [ clone_url, "master", cfgdir, "false" ])
bot.AddTask("exec", [ "touch", ".restore" ])
bot.AddTask("restart", [])
Пример #6
0
cfgconf = os.path.join(cfgdir, "conf")

hasconfig = True
try:
    os.stat(cfgconf)
except FileNotFoundError:
    hasconfig = False
except:
    bot.Log("Error", "Checking for %s: %s" % (cfgconf, sys.exc_info()[0]))
    exit(1)

# First, see if we're doing a restore
if hasconfig:
    try:
        os.stat(".restore")
        bot.AddTask("exec", [ "rm", "-f", ".restore" ])
        bot.AddJob("restore", [])
        exit(0)
    except FileNotFoundError:
        pass
    exit(0)

clone_url = os.getenv("GOPHER_CUSTOM_REPOSITORY")
if len(clone_url) == 0:
    bot.Log("Warn", "GOPHER_CUSTOM_REPOSITORY not set, not bootstrapping")
    exit(0)

clone_branch = os.getenv("GOPHER_CUSTOM_BRANCH")

if not clone_url.startswith("http"):
    depkey = os.getenv("GOPHER_DEPLOY_KEY")
Пример #7
0
        repoconf = repodata[repository]
        if "Type" in repoconf:
            repotype = repoconf["Type"]
            if repotype != "none":
                build_triggered = True
                bot.Log(
                    "Debug",
                    "Adding primary build for %s / %s to the pipeline" %
                    (repository, branch))
                bot.AddJob(repotype, [repository, branch])
    try:
        deps = get_deps(repository, True)
    except Exception as e:
        err = "Resolving dependencies for %s / %s: %s" % (repository, branch,
                                                          e)
        bot.AddTask("fail", [err])
        exit(0)
    if deps:
        build_triggered = True
        bot.Log(
            "Debug", "Starting builds for everything that depends on %s / %s" %
            (repository, branch))
        bot.AddJob("gopherci", [repository, branch, "true"])

if len(sys.argv) == 1:
    # build depdencies for a repository
    build_triggered = True
    for reponame in repodata.keys():
        if "dependencies" in repodata[reponame]:
            if repository in repodata[reponame]["dependencies"]:
                repoconf = repodata[reponame]
Пример #8
0
        if "Type" in repoconf:
            repotype = repoconf["Type"]
            if repotype != "none":
                build_triggered = True
                bot.Log(
                    "Debug",
                    "Adding primary build for %s / %s to the pipeline" %
                    (repository, branch))
                bot.AddJob(repotype, ["build", repository, branch])
    try:
        deps = get_deps(repository, True)
    except Exception as e:
        err = "Resolving dependencies for %s / %s: %s" % (repository, branch,
                                                          e)
        bot.Log("Error", err)
        bot.AddTask("status", [err])
        exit(0)
    if deps:
        build_triggered = True
        bot.Log(
            "Debug", "Starting builds for everything that depends on %s / %s" %
            (repository, branch))
        bot.AddJob("gopherci", ["builddeps", repository, branch])

if command == "job":
    # Run a custom pipeline
    pipeline = sys.argv.pop(0)
    if repository in repodata:
        repoconf = repodata[repository]
        if "Type" in repoconf:
            repotype = repoconf["Type"]
Пример #9
0
clone_url = repoconf["CloneURL"]
if len(clone_url) == 0:
    bot.Say("No 'clone_url' specified for '%s' in repositories.yaml" %
            repository)
    exit(1)

keep_history = repoconf["KeepLogs"]
if keep_history == None:
    keep_history = -1

# Protect the repository directory with Exclusive
if not bot.Exclusive(repository, False):
    bot.Log("Warn", "Build of '%s' already in progress, exiting" % repository)
    if len(bot.user) > 0:
        bot.Say(
            "build for '%s' already in progress, not starting a new build for branch '%s'"
            % (repository, branch))
    exit()

repobranch = "%s/%s" % (repository, branch)
bot.ExtendNamespace(repobranch, keep_history)

bot.AddTask("start-build", [])
bot.AddTask("git-init", [clone_url])
# Start with a clean jobdir
bot.AddTask("cleanup", [repository])
bot.AddTask("git-clone", [clone_url, branch, repository, "true"])
bot.AddTask("run-pipeline", [pipeline] + sys.argv)
bot.FinalTask("finish-build", [])