def _add_service()

in ebcli/containers/compose.py [0:0]


def _add_service(services, definition, volume_map, host_log, high_priority_env):
    realname = definition[CONTAINER_DEF_NAME_KEY]
    img = definition[CONTAINER_DEF_IMG_KEY]
    links = definition.get(CONTAINER_DEF_LINKS_KEY, [])
    command = definition.get(CONTAINER_DEF_CMD_KEY, [])
    dockerrun_port_mappings = definition.get(CONTAINER_DEF_PORT_MAPPINGS_KEY, [])
    ports = _get_port_maps(dockerrun_port_mappings)
    remote_mountpoints = definition.get(MOUNT_POINTS, [])
    definition_env = EnvvarCollector(_get_definition_envvars(definition))
    merged_envvars = definition_env.merge(high_priority_env).filtered().map
    privileged = definition.get(CONTAINER_DEF_PRIVILEGED_KEY, None)

    service = {COMPOSE_IMG_KEY: img}

    if command:
        service[COMPOSE_CMD_KEY] = command

    if ports:
        service[COMPOSE_PORTS_KEY] = ports

    if links:
        service[COMPOSE_LINKS_KEY] = ['{}:{}'.format(_fakename(n), n)
                                      for n in links]
    if merged_envvars:
        service[COMPOSE_ENV_KEY] = merged_envvars

    if privileged is not None:
        service[CONTAINER_DEF_PRIVILEGED_KEY] = privileged

    volumes = []
    for mp in remote_mountpoints:
        src_vol = mp[SOURCE_VOLUME_KEY]
        container_path = mp[CONTAINER_PATH_KEY]
        read_only = mp.get(READ_ONLY_KEY)

        if src_vol in volume_map:
            src_path = volume_map[src_vol]

        elif src_vol.startswith(AWSEB_LOGS):
            dirname = src_vol[len(AWSEB_LOGS):]
            src_path = os.path.join(host_log, dirname)

            os.makedirs(src_path)
        else:
            continue

        volume = '{}:{}'.format(src_path, container_path)
        if read_only:
            volume += READ_ONLY_VOLUME
        volumes.append(volume)

    if volumes:
        service[COMPOSE_VOLUMES_KEY] = volumes

    # alias the container names because '-' character is not allowed for service
    # names in docker-compose.yml
    services[_fakename(realname)] = service