API Documentation

ECSTransformer

class container_transform.ecs.ECSTransformer(filename=None)

A transformer for ECS Tasks

To use this class:

transformer = ECSTransformer('./task.json')
output = transformer.ingest_containers()
print(json.dumps(output, indent=4))
__init__(filename=None)

We override .__init__() on purpose, we need to get the volume data.

Parameters:filename (str) – The file to be loaded
add_volume(volume)

Add a volume to self.volumes if it isn’t already present

emit_containers(containers, verbose=True)
Parameters:
  • containers (list of dict) – List of the container definitions
  • verbose (bool) – Print out newlines and indented JSON
Returns:

The text output

Return type:

str

ingest_port_mappings(port_mappings)

Transform the ECS mappings to base schema mappings

Parameters:port_mappings (list of dict) – The ECS port mappings
Returns:The base schema mappings
Return type:list of dict
ingest_volumes_param(volumes)

This is for ingesting the “volumes” of a task description

ComposeTransformer

class container_transform.compose.ComposeTransformer(filename=None)

A transformer for docker-compose

To use this class:

transformer = ComposeTransformer('./docker-compose.yml')
normalized_keys = transformer.ingest_containers()
__init__(filename=None)
Parameters:filename (str) – The file to be loaded
emit_port_mappings(port_mappings)
Parameters:port_mappings (list of dict) – the base schema port_mappings
Returns:
Return type:list of str
ingest_containers(containers=None)

Transform the YAML into a dict with normalized keys

ingest_memory(memory)

Transform the memory into bytes

Parameters:memory (str) – Compose memory definition. (1g, 24k)
Returns:The memory in bytes
Return type:int
ingest_port_mappings(port_mappings)

Transform the docker-compose port mappings to base schema port_mappings

Parameters:port_mappings (list) – The compose port mappings
Returns:the base schema port_mappings
Return type:list of dict

FigTransformer

class container_transform.fig.FigTransformer(filename=None)

A transformer for Fig

To use this class:

transformer = FigTransformer('./fig.yml')
normalized_keys = transformer.ingest_containers()
__init__(filename=None)
Parameters:filename (str) – The file to be loaded
emit_port_mappings(port_mappings)
Parameters:port_mappings (list of dict) – the base schema port_mappings
Returns:
Return type:list of str
ingest_containers(containers=None)

Transform the YAML into a dict with normalized keys

ingest_memory(memory)

Transform the memory into bytes

Parameters:memory (str) – Fig memory definition. (1g, 24k)
Returns:The memory in bytes
Return type:int
ingest_port_mappings(port_mappings)

Transform the fig port mappings to base schema port_mappings

Parameters:port_mappings (list) – The fig port mappings
Returns:the base schema port_mappings
Return type:list of dict

BaseTransformer

class container_transform.transformer.BaseTransformer(filename=None)

The base class for Transformer classes to inherit from.

Basic usage should look like

transformer = MyTransformer('./my-file.txt')
normalized_keys = transformer.ingest_containers()
__init__(filename=None)
Parameters:filename (str) – The file to be loaded
ingest_containers(containers=None)

Ingest self.stream and return a list of un-converted container definitions dictionaries.

This is to normalize where all the container information is. For example, Fig places the container name outside the rest of the container definition. We need to have a ‘name’ key in the container definition.

Return type:list of dict
static validate(container)

Validate that the container has all essential parameters and add any if possible

Parameters:container (dict) – The converted container
Returns:The container with all valid parameters
Return type:dict