示例#1
0
def package_build_process(name, url, branch, path_to_missile=None,
                          domain=None, stack=None):
    """
    Prepare working copy, checkout working copy, build
    """
    logfilename = "build-%s-%s-%s.log" % (name, branch, datetime.datetime.utcnow().isoformat())
    logfilepath = os.path.join(dd.BUILD_LOGPATH, logfilename)
    sys.stdout = open(logfilepath, "w")
    sys.stderr = sys.stdout

    args = ["name", "url", "branch", "path_to_missile"]
    for arg in args:
        print arg , ": ", locals()[arg]

    with settings(host_string=host, key_filename=key_filename):
        wc = WorkingCopy(name, base_folder="/var/gachette")
        wc.prepare_environment()
        wc.checkout_working_copy(url=url, branch=branch)

        latest_version = RedisBackend().get_latest_version(name)
        new_base_version = RedisBackend().get_new_base_version(name)
        new_version = wc.get_version_from_git(base_version=new_base_version)
        # skipping existing build removed
        new_version += "-%s" % branch
        wc.set_version(app=new_version, env=new_version, service=new_version)
        result = wc.build(output_path="/var/gachette/debs", path_to_missile=path_to_missile)
        RedisBackend().delete_lock("packages", name)
        RedisBackend().create_package(name, new_version, result)
        print "Built new:", name, branch, new_version

    if domain is not None and stack is not None:
        RedisBackend().add_stack_package(domain, stack, name, new_version)
        print "Added to 'domains:%s:stacks:%s:packages' as {'%s': '%s'}" % (domain, stack, name, new_version)
示例#2
0
def final_build_process(name, app_version, env_version, service_version, path_to_missile=None, webcallback=None):
    """
    launch build
    """
    args = ["name", "app_version", "env_version", "service_version", "path_to_missile", "webcallback"]
    for arg in args:
        print arg , ": ", locals()[arg]
    with settings(host_string=host, key_filename=key_filename):
        wc = WorkingCopy(name, base_folder="/var/gachette")
        wc.set_version(app=app_version, 
                    # env=env_version, 
                    # service=service_version,
                    )
        wc.build(output_path="/var/gachette/debs", path_to_missile=path_to_missile, webcallback=webcallback)
        send_notification("WorkingCopy #%s build launched" % name)
示例#3
0
class BuildTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("build_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.working_copy.run')
    def test_build(self, fabric_run_mock):
        app_version = '1.1.0'
        webcallback = 'http://garnison.dev:8080/stacks/1234/build_cb'
        self.wc.set_version(app=app_version)
        self.wc.build('/var/gachette/debs', webcallback=webcallback)

        fabric_run_mock.assert_has_calls(
                [mock.call('trebuchet build %s --arch amd64 --output %s %s %s' \
                    % (os.path.join(self.wc.working_copy, '.missile.yml'),
                       '/var/gachette/debs',
                       self.wc.get_version_suffix(),
                       self.wc.get_webcallback_suffix(webcallback)))])
示例#4
0
class BuildTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("build_test")

    def tearDown(self):
        self.wc = None

    @mock.patch('gachette.lib.working_copy.run')
    def test_build(self, fabric_run_mock):
        app_version = '1.1.0'
        webcallback = 'http://garnison.dev:8080/stacks/1234/build_cb'
        self.wc.set_version(app=app_version)
        self.wc.build('/var/gachette/debs', webcallback=webcallback)

        fabric_run_mock.assert_has_calls(
                [mock.call('trebuchet build %s --arch amd64 --output %s %s %s' \
                    % (os.path.join(self.wc.working_copy, '.missile.yml'),
                       '/var/gachette/debs',
                       self.wc.get_version_suffix(),
                       self.wc.get_webcallback_suffix(webcallback)))])
示例#5
0
class VersionTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("version_test")

    def tearDown(self):
        self.wc = None

    def test_app_version(self):
        self.wc.set_version(app='1.2.3')
        self.assertEqual(
            self.wc.get_version_suffix(), " --app-version 1.2.3",
            "app version is not well recognized (%s)" %
            self.wc.get_version_suffix())

        self.wc.set_version(app='1.2.4')
        self.assertEqual(
            self.wc.get_version_suffix(), " --app-version 1.2.4",
            "app version is updated properly (%s)" %
            self.wc.get_version_suffix())

        self.wc.set_version(app='')
        self.assertEqual(
            self.wc.get_version_suffix(), "",
            "app version is removed properly (%s)" %
            self.wc.get_version_suffix())

    def test_env_version(self):
        self.wc.set_version(env='1.2.3')
        self.assertEqual(
            self.wc.get_version_suffix(), " --env-version 1.2.3",
            "env version is not well recognized (%s)" %
            self.wc.get_version_suffix())

    def test_service_version(self):
        self.wc.set_version(service='1.2.3')
        self.assertEqual(
            self.wc.get_version_suffix(), " --service-version 1.2.3",
            "service version is not well recognized (%s)" %
            self.wc.get_version_suffix())

    def test_multiple_version(self):
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(
            self.wc.get_version_suffix(),
            " --app-version 1.2.3 --env-version 2.3.4",
            "env and app version are not well recognized (%s)" %
            self.wc.get_version_suffix())
        self.wc.set_version(service='3.4.5')
        self.assertEqual(
            self.wc.get_version_suffix(),
            " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5",
            "service, env and app version are not well recognized (%s)" %
            self.wc.get_version_suffix())

    def test_all_version(self):
        self.wc.set_version(service='3.4.5')
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(
            self.wc.get_version_suffix(),
            " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5",
            "service, env and app version are sorted properly (%s)" %
            self.wc.get_version_suffix())
示例#6
0
class VersionTest(unittest.TestCase):
    def setUp(self):
        self.wc = WorkingCopy("version_test")

    def tearDown(self):
        self.wc = None

    def test_app_version(self):
        self.wc.set_version(app='1.2.3')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3", 
                        "app version is not well recognized (%s)" % self.wc.get_version_suffix())

        self.wc.set_version(app='1.2.4')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.4", 
                        "app version is updated properly (%s)" % self.wc.get_version_suffix())

        self.wc.set_version(app='')
        self.assertEqual(self.wc.get_version_suffix(), "",
                        "app version is removed properly (%s)" % self.wc.get_version_suffix())

    def test_env_version(self):
        self.wc.set_version(env='1.2.3')
        self.assertEqual(self.wc.get_version_suffix(), " --env-version 1.2.3", 
                        "env version is not well recognized (%s)" % self.wc.get_version_suffix())

    def test_service_version(self):
        self.wc.set_version(service='1.2.3')
        self.assertEqual(self.wc.get_version_suffix(), " --service-version 1.2.3", 
                        "service version is not well recognized (%s)" % self.wc.get_version_suffix())

    def test_multiple_version(self):
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3 --env-version 2.3.4",
                        "env and app version are not well recognized (%s)" % self.wc.get_version_suffix())
        self.wc.set_version(service='3.4.5')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5",
                        "service, env and app version are not well recognized (%s)" % self.wc.get_version_suffix())

    def test_all_version(self):
        self.wc.set_version(service='3.4.5')
        self.wc.set_version(app='1.2.3')
        self.wc.set_version(env='2.3.4')
        self.assertEqual(self.wc.get_version_suffix(), " --app-version 1.2.3 --env-version 2.3.4 --service-version 3.4.5", 
                        "service, env and app version are sorted properly (%s)" % self.wc.get_version_suffix())