-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for networks: and mapping to additional subnets. (#282)
* Added support for extra subnets definitions and mapping to service families * Added unit-testing and support from Use
- Loading branch information
1 parent
ba4ed5c
commit cabd793
Showing
14 changed files
with
313 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.. _compose_networks_syntax_reference: | ||
|
||
========================= | ||
networks | ||
========================= | ||
|
||
In docker-compose one can define diffent subnets which would use different properties, as documented | ||
`here <https://docs.docker.com/compose/compose-file/#network-configuration-reference>`__ | ||
|
||
This allows you to logically bind services on different networks etc, very useful in many scenarios. | ||
|
||
In ECS ComposeX, we have added support to allow you to define these networks and logically associate them with AWS VPC Subnets. | ||
|
||
Refer to :ref:`vpc_syntax_reference` for a full review of ECS ComposeX syntax definition for subnets mappings. | ||
|
||
|
||
You can now define extra subnet groups based on different tags and map them to your services for override when using | ||
**Lookup** or **Use** | ||
|
||
.. code-block:: yaml | ||
:caption: Extra subnets definition | ||
x-vpc: | ||
Lookup: | ||
VpcId: {} | ||
AppSubnets: {} | ||
StorageSubnets: {} | ||
PublicSubnets: {} | ||
Custom01: | ||
Tags: {} | ||
.. code-block:: yaml | ||
:caption: define compose networks and associate to a Subnet category | ||
networks: | ||
custom01: | ||
x-vpc: Custom01 | ||
.. code-block:: yaml | ||
:caption: Map a compose defined network to a service | ||
services: | ||
serviceA: | ||
networks: | ||
- custom01 | ||
serviceB: | ||
networks: | ||
custom01: {} | ||
.. note:: | ||
|
||
As per docker-compose config, the rendered networks in a service is a map / object. But it also can be a list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
# ECS ComposeX <https://github.com/lambda-my-aws/ecs_composex> | ||
# Copyright (C) 2020 John Mille <john@lambda-my-aws.io> | ||
# # | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# # | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# # | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
""" | ||
Class and functions to interact with the networks: defined in compose files. | ||
""" | ||
|
||
import re | ||
|
||
from ecs_composex.common import keyisset, LOG | ||
from ecs_composex.vpc.vpc_params import ( | ||
APP_SUBNETS, | ||
STORAGE_SUBNETS, | ||
PUBLIC_SUBNETS, | ||
SUBNETS_TYPE, | ||
VPC_ID, | ||
) | ||
|
||
|
||
def match_networks_services_config(service, vol_config, networks): | ||
""" | ||
Function to map network config in services and top-level networks | ||
:param service: | ||
:param vol_config: | ||
:param networks: | ||
:raises LookupError: | ||
""" | ||
for network in networks: | ||
if network.name == vol_config["source"]: | ||
network.services.append(service) | ||
vol_config["network"] = network | ||
service.networks.append(vol_config) | ||
LOG.info(f"Mapped {network.name} to {service.name}") | ||
return | ||
raise LookupError( | ||
f"Volume {vol_config['source']} was not found in {[vol.name for vol in networks]}" | ||
) | ||
|
||
|
||
class ComposeNetwork(object): | ||
""" | ||
Class to keep track of the Docker-compose Volumes | ||
""" | ||
|
||
main_key = "networks" | ||
driver_opts_key = "driver" | ||
|
||
def __init__(self, name, definition, subnets_list): | ||
self.name = name | ||
self.subnet_name = name | ||
if keyisset("name", definition): | ||
self.subnet_name = definition["name"] | ||
elif ( | ||
not keyisset("name", definition) | ||
and keyisset("x-vpc", definition) | ||
and isinstance(definition["x-vpc"], str) | ||
): | ||
self.subnet_name = definition["x-vpc"] | ||
subnet_names = [subnet.title for subnet in subnets_list] | ||
if self.subnet_name not in subnet_names: | ||
raise KeyError(f"No subnet {self.name} defined. Valid options are", subnet_names) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.