Ejemplo n.º 1
0
    def deploy(self, *args):
        args = list(args)
        if not len(args) or not args[0]:
            print "deploy command requires an action. Valid actions are: "
            print " list applications"
            print " list groups [application]"
            print " list deployments"
            print " list configs"
            print " create (cluster) [role] (commit_id)"
            return
        action = args.pop(0)

        if action == 'list':
            dep = deploy.Deploy()
            if not len(args):
                print "list what? applications, groups, deployments or configs?"
                return
            what = args.pop(0)
            if what == 'applications' or what == 'apps':
                dep.list_applications()
            elif what == 'groups':
                # application name?
                application = None
                if len(args):
                    application = args.pop(0)
                dep.list_groups(application)
            elif what == 'configs':
                dep.list_configs()
            elif what == 'deployments':
                dep.list_deployments()
            else:
                print "Unknown list type: {}".format(what)
        elif action == 'create':
            # require cluster, role (optional), commit_id
            cluster = None
            role = None
            commit_id = None
            if len(args) < 2:
                print "deploy create requires at least cluster and commit id"
                return
            elif len(args) == 2:
                cluster = args.pop(0)
                commit_id = args.pop(0)
            elif len(args) == 3:
                cluster = args.pop(0)
                role = args.pop(0)
                commit_id = args.pop(0)
            dep = deploy.Deploy(cluster, role)
            dep.create(commit_id)
        else:
            print "Unknown deploy command: {}".format(action)
Ejemplo n.º 2
0
    def test_copy_files(self):
        with tempfile.TemporaryDirectory() as dir:
            os.mkdir(os.path.join(dir, "example.com"))
            os.mkdir(os.path.join(dir, "dest"))
            configfile = os.path.join(dir, "config.ini")
            certfile = os.path.join(dir, "example.com", "cert.pem")
            chainfile = os.path.join(dir, "example.com", "chain.pem")
            fullchainfile = os.path.join(dir, "example.com", "fullchain.pem")
            keyfile = os.path.join(dir, "example.com", "privkey.pem")

            config = configparser.ConfigParser()
            config.add_section("deploy")
            config["DEFAULT"]["cert-path"] = os.path.join(dir, "dest", "cert")
            config["DEFAULT"]["chain-path"] = os.path.join(
                dir, "dest", "chain")
            config["DEFAULT"]["combined-path"] = os.path.join(
                dir, "dest", "combined")
            config["DEFAULT"]["fullchain-path"] = os.path.join(
                dir, "dest", "fullchain")
            config["DEFAULT"]["key-path"] = os.path.join(dir, "dest", "key")
            config["deploy"]["command"] = ""
            with open(configfile, "w") as f:
                config.write(f)

            with open(certfile, "w") as f:
                f.write("CERTIFICATE\n")
            with open(chainfile, "w") as f:
                f.write("CHAIN\n")
            with open(fullchainfile, "w") as f:
                f.write("FULLCHAIN\n")
            with open(keyfile, "w") as f:
                f.write("KEY\n")

            d = deploy.Deploy(os.path.join(dir, "example.com"), configfile)
            d.run()

            with open(os.path.join(dir, "dest", "cert")) as f:
                b = f.read()
                self.assertEqual(b, "CERTIFICATE\n")
            with open(os.path.join(dir, "dest", "chain")) as f:
                b = f.read()
                self.assertEqual(b, "CHAIN\n")
            with open(os.path.join(dir, "dest", "combined")) as f:
                b = f.read()
                self.assertEqual(b, "FULLCHAIN\nKEY\n")
            with open(os.path.join(dir, "dest", "fullchain")) as f:
                b = f.read()
                self.assertEqual(b, "FULLCHAIN\n")
            with open(os.path.join(dir, "dest", "key")) as f:
                b = f.read()
                self.assertEqual(b, "KEY\n")
Ejemplo n.º 3
0
def deploy_cmd(cmdline):
    DEPLOY_USAGE = ('%prog deploy <webgen output dir> '
                    '<deploy dir> <webgen manifest>')
    parser = optparse.OptionParser(usage=DEPLOY_USAGE,
                                   version=OPTPARSE_VERSION,
                                   add_help_option=False)
    (options, args) = parser.parse_args(cmdline)

    if len(args) != 3:
        parser.print_help()
        return 2

    deploy.Deploy(args[0], args[1], args[2])
    return 0
Ejemplo n.º 4
0
    def test_deploy_command(self):
        with tempfile.TemporaryDirectory() as dir:
            configfile = os.path.join(dir, "config.ini")
            config = configparser.ConfigParser()
            config.add_section("deploy")
            config["DEFAULT"]["cert-path"] = ""
            config["DEFAULT"]["chain-path"] = ""
            config["DEFAULT"]["combined-path"] = ""
            config["DEFAULT"]["fullchain-path"] = ""
            config["DEFAULT"]["key-path"] = ""
            config["deploy"]["command"] = "echo 'OK!'"
            with open(configfile, "w") as f:
                config.write(f)

            d = deploy.Deploy(os.path.join(dir, "example.com"), configfile)
            subprocess.run = Mock()
            d.run()
            subprocess.run.assert_called_once_with("echo 'OK!'", shell=True)
Ejemplo n.º 5
0
    def Generate(self, input_root, use_processors):
        ts = time.localtime()
        ts_str = time.strftime('%Y%m%d-%H%M%S', ts)
        out_dir = self._SiteLocation(ts_str)
        manifest_file = self._ManifestLocation(ts_str)

        generator.Generator(input_root, use_processors).Generate(
            out_dir, timestamp=ts, manifest_path=manifest_file)

        self._SetLink(_LATEST_LINK, ts_str)

        if not self._LinkExists(_CURRENT_LINK):
            self._SetLink(_CURRENT_LINK, ts_str)
            if self._deploy_dir:
                deploy.Deploy(out_dir, self._deploy_dir, manifest_file)
            current = True
        else:
            current = False

        return ts_str, out_dir, manifest_file, current
Ejemplo n.º 6
0
    def get_deployment_group_name(self, group_arg):
        group_name = group_arg  # default to using arg as deploymentgroup name

        # check to see if group_arg is a valid deploymentegroup name or valid cluster/role
        dep = deploy.Deploy()
        groups = dep.get_groups()
        group_names = groups['deploymentGroups']
        if group_name not in group_names: # not valid deployment group name
            # look in config for group name from cluster/role
            cluster,role = self.get_cluster_and_role_from_args(group_arg, quiet=True)
            if role:
                cfg = config.get_role_config(cluster, role)
                group_name = cfg.get('deployment_group')
                if not group_name:
                    print("Failed to find DeploymentGroup name in configuration for role {}".format(role))
                    return None
            else:
                print("Invalid DeploymentGroup name '{}' and no deployment_group is configured for this role.".format(group_arg))
                return None
        return group_name
Ejemplo n.º 7
0
def main():
    config = c.get_default_config()
    parser = ArgumentParser(version=__version__)

    config = create_config(parser)

    # Logging
    configure_logging(config.get('misc', 'logging') or '', verbosity=config.getint('misc', 'verbosity'))
    logger.info(colors.HEADER + '=====' + colors.ENDC)
    logger.info(colors.OKGREEN + 'PyEPM ' + colors.ENDC + '%s', __version__)
    logger.info(colors.HEADER + '=====' + colors.ENDC)

    logger.debug(c.dump_config(config))

    args = parser.parse_args()

    for filename in args.filename:
        if not os.path.exists(filename):
            logger.warn("\nFile does not exist: %s" % filename)
        else:
            logger.info("\nDeploying " + colors.BOLD + "%s" % filename + colors.ENDC + "...")
            deployment = deploy.Deploy(filename, config)
            deployment.deploy()
Ejemplo n.º 8
0
def main():
    config = c.get_default_config()
    parser = ArgumentParser(version=__version__)

    config = create_config(parser)

    # Logging
    configure_logging(config.get('misc', 'logging') or '',
                      verbosity=config.getint('misc', 'verbosity'))
    logger.info('PyEPM %s', __version__)
    logger.info('=====')

    logger.debug(c.dump_config(config))

    args = parser.parse_args()

    for filename in args.filename:
        if not os.path.exists(filename):
            logger.warn("File does not exist: %s" % filename)
        else:
            logger.info("Deploying %s..." % filename)
            deployment = deploy.Deploy(filename, config)
            deployment.deploy()
Ejemplo n.º 9
0
    def ChangeCurrent(self, version=0):
        ts = self._FindTimestamps()
        if not ts:
            raise NoVersionsError()
        if version >= len(ts):
            raise ArgumentError('Invalid version %d specified, '
                                'only %d available' % (version, len(ts)))

        current = self._LinkTimestamp(_CURRENT_LINK)

        if current and current == ts[version]:
            # Nothing to do, we're current already.
            return current

        # (re)point the symlink
        if self._deploy_dir:
            deploy.Undeploy(self._SiteLocation(current), self._deploy_dir,
                            self._ManifestLocation(current))
        self._SetLink(_CURRENT_LINK, ts[version])
        if self._deploy_dir:
            deploy.Deploy(self._SiteLocation(ts[version]), self._deploy_dir,
                          self._ManifestLocation(ts[version]))

        return ts[version]
 def testcase_thread(self):
     deploy.Deploy(self.uiautomator_test_results).exec_testcase()
Ejemplo n.º 11
0
Archivo: main.py Proyecto: anbet/udo
    def deploy(self, *args):
        args = list(args)
        if not len(args) or not args[0]:
            print "deploy command requires an action. Valid actions are: "
            print " list applications"
            print " list groups [application]"
            print " list deployments"
            print " list configs"
            print " create (group) (commit_id)"
            print " last [group]"
            return
        action = args.pop(0)

        if action == 'list':
            dep = deploy.Deploy()
            if not len(args):
                print "list what? applications, groups, deployments or configs?"
                return
            what = args.pop(0)
            if what == 'applications' or what == 'apps':
                dep.list_applications()
            elif what == 'groups':
                # application name?
                application = None
                if len(args):
                    application = args.pop(0)
                dep.list_groups(application)
            elif what == 'configs':
                dep.list_configs()
            elif what == 'deployments':
                dep.list_deployments()
            else:
                print "Unknown list type: {}".format(what)
        elif action == 'create':
            # require group, commit_id
            if len(args) != 2:
                print "deploy create requires group and commit id"
                return

            group = args.pop(0)
            commit_id = args.pop(0)
            dep = deploy.Deploy()
            dep.create(group, commit_id)
        elif action == 'last':
            dep = deploy.Deploy()
            group = None
            if len(args) == 1:
                group = args.pop(0)
                dep.print_last_deployment(deployment_group_name=group)
            else:
                dep.print_last_deployment()
        elif action == 'stop':
            dep = deploy.Deploy()
            dep.stop_deployment()
        elif len(args) == 1:
            # let's just assume we wanna create a deployment
            group = action
            commit_id = args.pop(0)
            dep = deploy.Deploy()
            dep.create(group, commit_id)
        else:
            print "Unknown deploy command: {}".format(action)
Ejemplo n.º 12
0
    docker_container_name = os.environ.get('PROJECT_NAME')
    check(docker_container_name, 'PROJECT_NAME')
    swarm_mode = os.environ.get('SWARM_MODE')
    image = os.environ.get('DOCKER_IMAGE')

    # Parse commandline arguments
    if len(sys.argv) > 1:
        parse_optional_args(sys.argv[1:])

    # Swarm mode
    if swarm_mode and swarm_mode.lower() == str(True).lower():
        if docker_compose_file:
            check(docker_stack_name, 'STACK_NAME')
            print("------------Deploy stack------------")
            deploy = deploy.Deploy(endpoint_name, docker_container_name, None,
                                   None, None, None, None, docker_stack_name,
                                   docker_compose_file, None)
            deploy.deploy_stack()
        else:
            check(image, 'DOCKER_IMAGE')
            print("------------Deploy service------------")
            deploy = deploy.Deploy(endpoint_name, docker_container_name, image,
                                   docker_networks, docker_ports,
                                   docker_volumes, docker_envs,
                                   docker_stack_name, docker_compose_file,
                                   docker_memory_limit)
            deploy.deploy_service(docker_service_mode, docker_replicas)
    else:
        check(image, 'DOCKER_IMAGE')
        print("------------Deploy container------------")
        deploy = deploy.Deploy(endpoint_name, docker_container_name, image,