Skip to content

shell_scripts

create_cache_script(pr_num, docker_registry)

Create a script to retrieve cache for an image.

Parameters:

Name Type Description Default
pr_num str

The pull request number where to pull the cache from.

required
docker_registry str

The docker registry where the images are located.

required

Returns:

Type Description
str

A script to find the cache.

Source code in m/ci/docker/shell_scripts.py
def create_cache_script(pr_num: str, docker_registry: str) -> str:
    """Create a script to retrieve cache for an image.

    Args:
        pr_num: The pull request number where to pull the cache from.
        docker_registry: The docker registry where the images are located.

    Returns:
        A script to find the cache.
    """
    pulls = ['pullCache "$1" master', 'echo "NO CACHE FOUND"']
    if pr_num:
        pulls.insert(0, f'pullCache "$1" "pr{pr_num}"')
    find_cache_implementation = ' || '.join(pulls)
    replacements = {
        'docker_registry': docker_registry,
        'find_cache_implementation': find_cache_implementation,
    }
    return FIND_CACHE_SCRIPT.format(**replacements)

create_push_script(docker_registry)

Create a script to push an image.

Parameters:

Name Type Description Default
docker_registry str

The docker registry where the images will be pushed.

required

Returns:

Type Description
str

A script to push an image.

Source code in m/ci/docker/shell_scripts.py
def create_push_script(docker_registry: str) -> str:
    """Create a script to push an image.

    Args:
        docker_registry: The docker registry where the images will be pushed.

    Returns:
        A script to push an image.
    """
    return PUSH_SCRIPT.format(docker_registry=docker_registry)

create_push_script_tags(docker_registry, m_tag)

Create a script to push an image.

This is meant to be used when building for a single architecture.

Parameters:

Name Type Description Default
docker_registry str

The docker registry where the images will be pushed.

required
m_tag str

The unique tag for the image.

required

Returns:

Type Description
str

A script to push an image.

Source code in m/ci/docker/shell_scripts.py
def create_push_script_tags(docker_registry: str, m_tag: str) -> str:
    """Create a script to push an image.

    This is meant to be used when building for a single architecture.

    Args:
        docker_registry: The docker registry where the images will be pushed.
        m_tag: The unique tag for the image.

    Returns:
        A script to push an image.
    """
    if not m_tag and os.environ.get('CI') != 'true':
        logger.warning('M_TAG not found in non-CI environment. Using 1.1.1')
        m_tag = '1.1.1'
    tags = [m_tag, *docker_tags(m_tag)]
    tagged_images = '\n'.join([
        f'docker tag staged-image:latest "{docker_registry}/$imageName:{tag}"'
        for tag in tags
    ])
    return PUSH_SCRIPT_TAGS.format(
        docker_registry=docker_registry,
        tag_images=tagged_images,
    )