Skip to content

Commit efe145a

Browse files
authored
FR - Multiple files for compose (#132)
* Working multi files merge
1 parent 0f0ff29 commit efe145a

File tree

14 files changed

+347
-264
lines changed

14 files changed

+347
-264
lines changed

README.rst

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ Usage
3030

3131
.. code-block:: bash
3232
33-
usage: ecs_composex [-h] {up,config,version,init} ...
33+
usage: ecs-composex [-h] {up,render,config,init,version} ...
3434
3535
positional arguments:
36-
{up,config,version,init}
37-
Command to execute.
36+
{up,render,config,init,version}
37+
3838
up Generates & Validates the CFN templates,
3939
Creates/Updates stack in CFN
40-
config Generates & Validates the CFN templates locally. No
41-
upload to S3.
42-
version ECS ComposeX Version
40+
render Generates & Validates the CFN templates locally. No
41+
upload to S3
42+
config Merges docker-compose files to provide with the final
43+
compose content version
4344
init Initializes your AWS Account with prerequisites
4445
settings for ECS
4546
version ECS ComposeX Version
@@ -48,21 +49,23 @@ Usage
4849
-h, --help show this help message and exit
4950
5051
Command 'up'
51-
usage: ecs_composex up [-h] -n NAME -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
52-
[--format {json,yaml,text}] [--region REGIONNAME]
53-
[--az ZONES] [-b BUCKETNAME] [--use-spot-fleet]
52+
usage: ecs-composex up [-h] -n NAME [--format {json,yaml,text}]
53+
[--region REGIONNAME] [--az ZONES] [-b BUCKETNAME]
54+
[--use-spot-fleet] -f DOCKERCOMPOSEXFILE
55+
[-d OUTPUTDIRECTORY]
5456
55-
Command 'config'
56-
usage: ecs_composex config [-h] -n NAME -f DOCKERCOMPOSEXFILE
57-
[-d OUTPUTDIRECTORY] [--format {json,yaml,text}]
57+
Command 'render'
58+
usage: ecs-composex render [-h] -n NAME [--format {json,yaml,text}]
5859
[--region REGIONNAME] [--az ZONES] [-b BUCKETNAME]
59-
[--use-spot-fleet]
60+
[--use-spot-fleet] -f DOCKERCOMPOSEXFILE
61+
[-d OUTPUTDIRECTORY]
62+
63+
Command 'config'
64+
usage: ecs-composex config [-h] -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
6065
61-
Command 'version'
62-
usage: ecs_composex version [-h]
6366
6467
65-
CLI for `up` and `config`
68+
CLI for `up` and `render`
6669

6770
.. code-block:: bash
6871
@@ -89,6 +92,21 @@ CLI for `up` and `config`
8992
--use-fargate, it will create an additional SpotFleet
9093
9194
95+
CLI for `config`
96+
97+
.. code-block:: bash
98+
99+
usage: ecs-composex config [-h] -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
100+
101+
optional arguments:
102+
-h, --help show this help message and exit
103+
-f DOCKERCOMPOSEXFILE, --docker-compose-file DOCKERCOMPOSEXFILE
104+
Path to the Docker compose file
105+
-d OUTPUTDIRECTORY, --output-dir OUTPUTDIRECTORY
106+
Output directory to write all the templates to.
107+
108+
109+
92110
AWS Resources support
93111
=====================
94112

docs/readme.rst

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ Usage
2929
=====
3030

3131
.. code-block:: bash
32-
:caption: Top level CLI
3332
34-
usage: ecs_composex [-h] {up,config,version,init} ...
33+
usage: ecs-composex [-h] {up,render,config,init,version} ...
3534
3635
positional arguments:
37-
{up,config,version,init}
36+
{up,render,config,init,version}
3837
Command to execute.
3938
up Generates & Validates the CFN templates,
4039
Creates/Updates stack in CFN
41-
config Generates & Validates the CFN templates locally. No
42-
upload to S3.
43-
version ECS ComposeX Version
40+
render Generates & Validates the CFN templates locally. No
41+
upload to S3
42+
config Merges docker-compose files to provide with the final
43+
compose content version
4444
init Initializes your AWS Account with prerequisites
4545
settings for ECS
4646
version ECS ComposeX Version
@@ -49,23 +49,24 @@ Usage
4949
-h, --help show this help message and exit
5050
5151
Command 'up'
52-
usage: ecs_composex up [-h] -n NAME -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
53-
[--format {json,yaml,text}] [--region REGIONNAME]
54-
[--az ZONES] [-b BUCKETNAME] [--use-spot-fleet]
52+
usage: ecs-composex up [-h] -n NAME [--format {json,yaml,text}]
53+
[--region REGIONNAME] [--az ZONES] [-b BUCKETNAME]
54+
[--use-spot-fleet] -f DOCKERCOMPOSEXFILE
55+
[-d OUTPUTDIRECTORY]
5556
56-
Command 'config'
57-
usage: ecs_composex config [-h] -n NAME -f DOCKERCOMPOSEXFILE
58-
[-d OUTPUTDIRECTORY] [--format {json,yaml,text}]
57+
Command 'render'
58+
usage: ecs-composex render [-h] -n NAME [--format {json,yaml,text}]
5959
[--region REGIONNAME] [--az ZONES] [-b BUCKETNAME]
60-
[--use-spot-fleet]
60+
[--use-spot-fleet] -f DOCKERCOMPOSEXFILE
61+
[-d OUTPUTDIRECTORY]
6162
62-
Command 'version'
63-
usage: ecs_composex version [-h]
63+
Command 'config'
64+
usage: ecs-composex config [-h] -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
6465
6566
6667
6768
.. code-block:: bash
68-
:caption: Up/Config CLI
69+
:caption: CLI for up and render
6970
7071
usage: ecs_composex up [-h] -n NAME -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
7172
[--format {json,yaml,text}] [--region REGIONNAME]
@@ -90,6 +91,20 @@ Usage
9091
--use-fargate, it will create an additional SpotFleet
9192
9293
94+
.. code-block:: bash
95+
:caption: CLI for config
96+
97+
usage: ecs-composex config [-h] -f DOCKERCOMPOSEXFILE [-d OUTPUTDIRECTORY]
98+
99+
optional arguments:
100+
-h, --help show this help message and exit
101+
-f DOCKERCOMPOSEXFILE, --docker-compose-file DOCKERCOMPOSEXFILE
102+
Path to the Docker compose file
103+
-d OUTPUTDIRECTORY, --output-dir OUTPUTDIRECTORY
104+
Output directory to write all the templates to.
105+
106+
107+
93108
.. note::
94109
95110
Each component can also use the docker-compose file but be deployed on its own, allowing, for production workloads,

ecs_composex/cli.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def __call__(self, parser, namespace, values, option_string=None):
4949
]
5050
for subparsers_action in subparsers_actions:
5151
for choice, subparser in list(subparsers_action.choices.items()):
52-
if choice in [cmd["name"] for cmd in ComposeXSettings.commands]:
52+
if choice in [
53+
cmd["name"] for cmd in ComposeXSettings.active_commands
54+
] or choice in [
55+
cmd["name"] for cmd in ComposeXSettings.validation_commands
56+
]:
5357
print(f"Command '{choice}'")
5458
print(subparser.format_usage())
5559

@@ -66,22 +70,16 @@ def main_parser():
6670
dest=ComposeXSettings.command_arg, help="Command to execute."
6771
)
6872
base_command_parser = argparse.ArgumentParser(add_help=False)
69-
base_command_parser.add_argument(
70-
"-n",
71-
"--name",
72-
help="Name of your stack",
73-
required=True,
74-
type=str,
75-
dest=ComposeXSettings.name_arg,
76-
)
77-
base_command_parser.add_argument(
73+
files_parser = argparse.ArgumentParser(add_help=False)
74+
files_parser.add_argument(
7875
"-f",
7976
"--docker-compose-file",
8077
dest=ComposeXSettings.input_file_arg,
8178
required=True,
8279
help="Path to the Docker compose file",
80+
action="append",
8381
)
84-
base_command_parser.add_argument(
82+
files_parser.add_argument(
8583
"-d",
8684
"--output-dir",
8785
required=False,
@@ -90,6 +88,14 @@ def main_parser():
9088
dest=ComposeXSettings.output_dir_arg,
9189
default=ComposeXSettings.default_output_dir,
9290
)
91+
base_command_parser.add_argument(
92+
"-n",
93+
"--name",
94+
help="Name of your stack",
95+
required=True,
96+
type=str,
97+
dest=ComposeXSettings.name_arg,
98+
)
9399
base_command_parser.add_argument(
94100
"--format",
95101
help="Defines the format you want to use.",
@@ -132,10 +138,17 @@ def main_parser():
132138
help="Runs spotfleet for EC2. If used in combination "
133139
"of --use-fargate, it will create an additional SpotFleet",
134140
)
135-
for command in ComposeXSettings.commands:
141+
for command in ComposeXSettings.active_commands:
136142
cmd_parsers.add_parser(
137-
name=command["name"], help=command["help"], parents=[base_command_parser]
143+
name=command["name"],
144+
help=command["help"],
145+
parents=[base_command_parser, files_parser],
138146
)
147+
for command in ComposeXSettings.validation_commands:
148+
cmd_parsers.add_parser(
149+
name=command["name"], help=command["help"], parents=[files_parser]
150+
)
151+
139152
for command in ComposeXSettings.neutral_commands:
140153
cmd_parsers.add_parser(name=command["name"], help=command["help"])
141154
return parser
@@ -151,6 +164,7 @@ def main():
151164
parser.print_help()
152165
sys.exit()
153166
args = parser.parse_args()
167+
LOG.debug(args)
154168
settings = ComposeXSettings(**vars(args))
155169
settings.set_bucket_name_from_account_id()
156170
settings.set_azs_from_api()

0 commit comments

Comments
 (0)