Example #1
0
def generate(config, bootnode_config, wrkchain_id):
    wrkchain = config['wrkchain']

    services = []
    if bootnode_config['type'] == 'dedicated':
        services.append(bootnode(bootnode_config['nodes']))

    nodes = generate_nodes(wrkchain['nodes'], bootnode_config, wrkchain_id)
    services = services + nodes

    if config['wrkchain']['chaintest']['use']:
        services = services + [chaintest(config['wrkchain']['chaintest'])]

    networks = {
        'wrkchainnet': {
            'driver': 'bridge',
            'ipam': {
                'config': [{
                    'subnet': config['docker_network']['subnet']
                }]
            }
        }
    }

    config = Config(version=COMPOSE_VERSION,
                    services=services,
                    volumes=[],
                    networks=networks,
                    secrets=[],
                    configs=[])
    return serialize_config(config, None)
    def config(self, config_options, options):
        """
        Validate and view the compose file.

        Usage: config [options]

        Options:
            -q, --quiet     Only validate the configuration, don't print
                            anything.
            --services      Print the service names, one per line.

        """
        print "project dir:" + self.project_dir
        environment = Environment.from_env_file(self.project_dir)
        print environment

        config_path = get_config_path_from_options(
            self.project_dir, config_options, environment
        )
        compose_config = config.load(
            config.find(self.project_dir, config_path, environment)
        )

        if options['--quiet']:
            return

        if options['--services']:
            print('\n'.join(service['name'] for service in compose_config.services))
            return

        print(serialize_config(compose_config))
    def config(self, config_options, options):
        """
        Validate and view the compose file.

        Usage: config [options]

        Options:
            -q, --quiet     Only validate the configuration, don't print
                            anything.
            --services      Print the service names, one per line.

        """
        print "project dir:" + self.project_dir
        environment = Environment.from_env_file(self.project_dir)
        print environment

        config_path = get_config_path_from_options(self.project_dir,
                                                   config_options, environment)
        compose_config = config.load(
            config.find(self.project_dir, config_path, environment))

        if options['--quiet']:
            return

        if options['--services']:
            print('\n'.join(service['name']
                            for service in compose_config.services))
            return

        print(serialize_config(compose_config))
Example #4
0
def get_selected_mode_config(selected_mode, modes, containing_dir):
    """ Returns the string of the yaml configuration for the given mode """
    # entries in `modes` are each a list of filenames
    try:
        config_details = compose.config.find(
            containing_dir, modes[selected_mode],
            environment.Environment.from_env_file(containing_dir))
    except KeyError:
        print(("Specified mode not '{}' found! Please check or spelling or add"
               " as a new mode.".format(selected_mode)))
        sys.exit()

    loaded_config = compose.config.load(config_details)

    broken_serialized = serialize.serialize_config(loaded_config)
    fixed_serialized = fix_merged_configs(broken_serialized)

    return fixed_serialized
Example #5
0
def get_selected_mode_config(selected_mode, modes, containing_dir):
    """ Returns the string of the yaml configuration for the given mode """
    # entries in `modes` are each a list of filenames
    try:
        config_details = compose.config.find(
            containing_dir,
            modes[selected_mode],
            environment.Environment.from_env_file(containing_dir)
        )
    except KeyError:
        print(("Specified mode not '{}' found! Please check or spelling or add"
               " as a new mode.".format(selected_mode)))
        sys.exit()

    loaded_config = compose.config.load(config_details)

    broken_serialized = serialize.serialize_config(loaded_config)
    fixed_serialized = fix_merged_configs(broken_serialized)

    return fixed_serialized
Example #6
0
def update_image(filename, new_image, service_name='web'):
    """
    Update service image name to new_image.
    """

    path = os.path.dirname(filename)
    conf_file = ConfigFile.from_filename(filename)
    conf = load(ConfigDetails(path, [conf_file], None))

    # find service
    for i in range(len(conf.services)):
        service = conf.services[i]
        if service['name'] == service_name:
            conf.services[i]['image'] = new_image

            out = open(filename, 'w')
            out.write(serialize_config(conf))
            out.close()

            return filename
Example #7
0
def update_image(filename, new_image, service_name='web'):
    """
    Update service image name to new_image.
    """

    path = os.path.dirname(filename)
    conf_file = ConfigFile.from_filename(filename)
    conf = load(ConfigDetails(path, [conf_file], None))

    # find service
    for i in range(len(conf.services)):
        service = conf.services[i]
        if service['name'] == service_name:
            conf.services[i]['image'] = new_image

            out = open(filename, 'w')
            out.write(serialize_config(conf))
            out.close()

            return filename
Example #8
0
def build(filename, env_dict=None, output_path=None):
    """
    Build docker-compose.yml file from services & env.
    """

    path = os.path.dirname(filename)
    conf_file = ConfigFile.from_filename(filename)
    env = Environment(env_dict) if env_dict else None
    conf = load(ConfigDetails(path, [conf_file], env))

    output_path = output_path if output_path else path + '/docker-compose.yml'

    # try to make directory
    if os.path.dirname(output_path):
        os.makedirs(os.path.dirname(output_path))

    out = open(output_path, 'w')
    out.write(serialize_config(conf))
    out.close()

    return output_path
Example #9
0
def build(filename, env_dict=None, output_path=None):
    """
    Build docker-compose.yml file from services & env.
    """

    path = os.path.dirname(filename)
    conf_file = ConfigFile.from_filename(filename)
    env = Environment(env_dict) if env_dict else None
    conf = load(ConfigDetails(path, [conf_file], env))

    output_path = output_path if output_path else path + '/docker-compose.yml'

    # try to make directory
    if os.path.dirname(output_path):
        os.makedirs(os.path.dirname(output_path))

    out = open(output_path, 'w')
    out.write(serialize_config(conf))
    out.close()

    return output_path
        )
    )

    services = config.services
    for service in services:
        if 'deploy' not in service:
            service['deploy'] = {}
        service['deploy']['placement'] = {}
        service['deploy']['placement']['constraints'] = [
            'node.id == ' + node_id]
        service['deploy']['restart_policy'] = {}
        service['deploy']['restart_policy']['condition'] = 'none'

    final_file_path = os.path.join(WORKING_DIR, 'docker-compose-final.yml')
    with open(final_file_path, 'w', encoding='UTF-8') as f:
        f.write(serialize_config(config))

    logger.info("Number of services: {}".format(str(len(services))))

    subprocess.call(
        ["docker", "stack", "deploy", "-c", final_file_path, manager_uid])
    time.sleep(15)

    # FIXME: Currently API doesn't support stacks. The following code assumes
    # that all objects related to a stack have a label com.docker.stack.namespace=<stack_name>
    # This is the current assumption of Docker CLI.
    while len(client.api.tasks(
            filters={
                "label": "com.docker.stack.namespace={}".format(manager_uid)}
    )) < len(services):
        time.sleep(0.5)
Example #11
0
        WORKDIR) else path
    if result in REPLACE_MOUNTS:
        result = REPLACE_MOUNTS[result]
    return result


print('Preprocessing config')
for service in cfg.services:
    print(f'\tPreprocessing service: {service["name"]}')
    if 'build' in service:
        service.pop('build')

    for i, volume in enumerate(service['volumes']):
        service['volumes'][i] = volume._replace(
            internal=relativize(volume.internal),
            external=relativize(volume.external))

print(f'Writing composer file')
with open(os.path.join(OUTPUT_DIR, 'docker-compose.yml'), 'w') as f:
    f.write(serialize_config(cfg, None, False))

copyfile(
    os.path.join(WORKDIR, './rendertron-config.json'),
    os.path.join(OUTPUT_DIR, './rendertron-config.json'),
)

copyfile(
    os.path.join(WORKDIR, './.env.example'),
    os.path.join(OUTPUT_DIR, './.env.example'),
)