Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Commit

Permalink
feat: add port mapping for containers
Browse files Browse the repository at this point in the history
Allows the ports specified to be mapped directly into the container.

Closes #24
  • Loading branch information
bbangert committed Mar 20, 2017
1 parent 2856cab commit af054af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
53 changes: 34 additions & 19 deletions ardere/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,43 @@ def create_service(self, step):

# ECS wants a family name for task definitions, no spaces, 255 chars
family_name = step["name"] + "-" + self._plan_uuid

# Setup the container definition
container_def = {
"name": step["name"],
"image": step["container_name"],
"cpu": step["cpu_units"],
# use host network mode for optimal performance
"networkMode": "host",

# using only memoryReservation sets no hard limit
"memoryReservation": 256,
"environment": env_vars,
"entryPoint": cmd,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": self.container_log_group,
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ardere-{}".format(
self.plan_uuid
)
}
}
}

if "port_mapping" in step:
ports = []
for port_map in step["port_mapping"].split(","):
ports.append({
"containerPort": int(port_map)
})
container_def["portMappings"] = ports

task_response = self._ecs_client.register_task_definition(
family=family_name,
containerDefinitions=[
{
"name": step["name"],
"image": step["container_name"],
"cpu": step["cpu_units"],
# using only memoryReservation sets no hard limit
"memoryReservation": 256,
"environment": env_vars,
"entryPoint": cmd,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": self.container_log_group,
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ardere-{}".format(
self.plan_uuid
)
}
}
}
container_def
],
placementConstraints=[
# Ensure the service is confined to the right instance type
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"environment_data": [
"SOME_VAR=great-value"
],
"port_mapping": "8000,4000",
"container_name": "bbangert/ap-loadtester:latest",
"additional_command_args": "./apenv/bin/aplt_testplan wss://autopush.stage.mozaws.net 'aplt.scenarios:notification_forever,1000,1,0'"
}
Expand All @@ -28,7 +29,7 @@
"run_max_time": 140,
"cpu_units": 2048,
"container_name": "bbangert/pushgo:1.5rc4",
"port_mapping": "8080:8090,8081:8081,3000:3000,8082:8082",
"port_mapping": "8080,8081,3000,8082",
"load_balancer": {
"env_var": "TEST_CLUSTER",
"ping_path": "/status/health",
Expand Down
5 changes: 5 additions & 0 deletions tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def test_create_service(self):
eq_(step["serviceArn"], "arn:of:some:service::")
ecs._ecs_client.register_task_definition.assert_called()

_, kwargs = ecs._ecs_client.register_task_definition.call_args
container_def = kwargs["containerDefinitions"][0]
ok_("portMappings" in container_def)
eq_(container_def["networkMode"], "host")

def test_create_services(self):
ecs = self._make_FUT()
ecs.create_service = mock.Mock()
Expand Down

0 comments on commit af054af

Please sign in to comment.