-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathdeploy-aws
More file actions
executable file
·231 lines (194 loc) · 7.29 KB
/
deploy-aws
File metadata and controls
executable file
·231 lines (194 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env python3
# region copyright
# Copyright 2023-2026 NVIDIA Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# endregion
import os
import sys
import click
from src.python.aws import aws_validate_credentials
from src.python.config import c as config
from src.python.debug import debug_break, debug_start # noqa
from src.python.deploy_command import DeployCommand
from src.python.deployer import Deployer
from src.python.utils import (
colorize_error,
colorize_info,
colorize_prompt,
shell_command,
)
class DeployAWSCommand(DeployCommand):
"""
Defines options specific for "deploy-aws" command.
"""
# supported AWS instance types for DRIVE Sim/Isaac Sim
# @see https://aws.amazon.com/ec2/instance-types/g5/
AWS_OVKIT_INSTANCE_TYPES = [
# T4 - https://aws.amazon.com/ec2/instance-types/g4/
"g4dn.2xlarge",
"g4dn.4xlarge",
"g4dn.8xlarge",
"g4dn.16xlarge",
"g4dn.12xlarge",
"g4dn.metal",
# A10G - https://aws.amazon.com/ec2/instance-types/g5/
"g5.2xlarge",
"g5.4xlarge",
"g5.8xlarge",
"g5.16xlarge",
"g5.12xlarge",
"g5.24xlarge",
"g5.48xlarge",
# L4 - https://aws.amazon.com/ec2/instance-types/g6
"g6.2xlarge",
"g6.4xlarge",
"g6.8xlarge",
"g6.16xlarge",
"gr6.4xlarge",
"gr6.8xlarge",
"g6.12xlarge",
"g6.24xlarge",
"g6.48xlarge",
# AWS L40S - https://aws.amazon.com/ec2/instance-types/g6e/
"g6e.xlarge",
"g6e.2xlarge",
"g6e.4xlarge",
"g6e.8xlarge",
"g6e.12xlarge",
"g6e.16xlarge",
"g6e.24xlarge",
"g6e.48xlarge",
]
@staticmethod
def ovkit_instance_type_callback(ctx, param, value):
"""
Called after parsing --instance-type option
"""
# warn of "g5.xlarge" being too small
if "g5.xlarge" == value:
raise click.BadParameter(colorize_error("g5.xlarge is not supported. "))
# warn of other unsupported types
if value not in DeployAWSCommand.AWS_OVKIT_INSTANCE_TYPES:
raise click.BadParameter(
colorize_error(
f"Invalid instance type: {value}. Choose one of: "
+ ", ".join(DeployAWSCommand.AWS_OVKIT_INSTANCE_TYPES)
+ "."
)
)
return value
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# --instance-type
self.params.insert(
# insert before --ingress-cidrs option
self.param_index("ingress_cidrs"),
click.core.Option(
(
"--instance-type",
"--isaac-workstation-instance-type",
"isaac_workstation_instance_type",
),
prompt=colorize_prompt(
"* Instance Type "
+ "(G5, G4dn, G6 and G6e are supported, see https://docs.aws.amazon.com/dlami/latest/devguide/gpu.html)"
),
show_default=True,
default=config["aws_default_isaac_workstation_instance_type"],
callback=DeployAWSCommand.ovkit_instance_type_callback,
help="Instance type. Currently supported: "
+ ", ".join(self.AWS_OVKIT_INSTANCE_TYPES)
+ ".",
),
)
# --region
self.params.insert(
# insert before --ingres-cidrs option
self.param_index("ingress_cidrs"),
click.core.Option(
("--region",),
show_default=True,
default="US East 1",
help="AWS Region. Can be entered as 'us-east-1' or 'US East 1'."
" See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/",
prompt=colorize_prompt(
"* AWS Region (e.g. us-east-1 or US East 1,"
" see https://aws.amazon.com/about-aws/global-infrastructure/regions_az/)"
),
callback=lambda ctx, param, value: value.lower().replace(" ", "-"),
),
)
# defaults
self.params[self.param_index("from_image")].default = config[
"aws_default_from_image"
]
class AWSDeployer(Deployer):
"""
Deploys stuff to Azure
"""
def __init__(self, params, config):
super().__init__(params, config)
def _output_deployment_info(self, print_text=True):
extra_info = ""
self.output_deployment_info(extra_text=extra_info, print_text=print_text)
def main(self):
# ask what to do if deployment already exists
self.ask_existing_behavior()
# update region in AWS config if specified
if self.params.get("region"):
from src.python.aws import aws_cli_set
aws_cli_set("region", self.params["region"], verbose=self.params["debug"])
if self.existing_behavior != "run_ansible":
# create tfvars file, deal with existing deployment
self.create_tfvars(
{
"region": self.params["region"],
}
)
# run terraform
click.echo(colorize_info("* Running Terraform..."))
self.initialize_terraform(cwd=f"{config['terraform_dir']}/aws")
self.run_terraform(cwd=f"{config['terraform_dir']}/aws")
# display selected AMI
ami_id = self.tf_output("isaac_workstation_ami_id", default="")
ami_name = self.tf_output("isaac_workstation_ami_name", default="")
if ami_id:
click.echo(colorize_info(f"* Base image: {ami_id} ({ami_name})"))
# export ssh key from terraform
self.export_ssh_key()
# create ansible inventory file
self.create_ansible_inventory()
# save instructions
self._output_deployment_info(print_text=False)
# run ansible
self.run_all_ansible()
# upload user data
if self.params["upload"]:
self.upload_user_data()
# print info for the user
self._output_deployment_info()
@click.command(cls=DeployAWSCommand)
def main(**params):
AWSDeployer(params, config).main()
if __name__ == "__main__":
if os.path.exists("/.dockerenv"):
# set DEBUG env var if --debug option is used, so that pre-click code can also see debug mode
debug = "--debug" in sys.argv or os.environ.get("DEBUG", "0") == "1"
# validate AWS credentials and prompt for new ones if needed
aws_validate_credentials(verbose=debug)
# run command
main()
else:
# we're outside, start docker container first
shell_command(f"./run '{' '.join(sys.argv)}'", verbose=True)