Skip to content

Commit

Permalink
feat: add aws govcloud support for det-deploy (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanghphan authored Mar 5, 2021
1 parent 79134e5 commit fc7fee6
Show file tree
Hide file tree
Showing 5 changed files with 797 additions and 3 deletions.
10 changes: 9 additions & 1 deletion deploy/determined_deploy/aws/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import boto3

from determined_deploy.aws import aws, constants
from determined_deploy.aws.deployment_types import base, secure, simple, vpc
from determined_deploy.aws.deployment_types import base, govcloud, secure, simple, vpc


def validate_spot_max_price() -> Callable:
Expand Down Expand Up @@ -282,6 +282,7 @@ def deploy_aws(args: argparse.Namespace) -> None:
constants.deployment_types.VPC: vpc.VPC,
constants.deployment_types.EFS: vpc.EFS,
constants.deployment_types.FSX: vpc.FSx,
constants.deployment_types.GOVCLOUD: govcloud.Govcloud,
} # type: Dict[str, Union[Type[base.DeterminedDeployment]]]

if args.deployment_type != constants.deployment_types.SIMPLE:
Expand All @@ -292,6 +293,13 @@ def deploy_aws(args: argparse.Namespace) -> None:
f"deployment-type={args.deployment_type}."
)

if args.deployment_type == constants.deployment_types.GOVCLOUD:
if args.region not in ["us-gov-east-1", "us-gov-west-1"]:
raise ValueError(
"When deploying to GovCloud, set the region to either us-gov-east-1 "
"or us-gov-west-1."
)

master_tls_cert = master_tls_key = ""
if args.master_tls_cert:
with open(args.master_tls_cert, "rb") as f:
Expand Down
5 changes: 4 additions & 1 deletion deploy/determined_deploy/aws/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class deployment_types:
VPC = "vpc"
EFS = "efs"
FSX = "fsx"
DEPLOYMENT_TYPES = [SIMPLE, SECURE, VPC, EFS, FSX]
GOVCLOUD = "govcloud"
DEPLOYMENT_TYPES = [SIMPLE, SECURE, VPC, EFS, FSX, GOVCLOUD]


class defaults:
Expand Down Expand Up @@ -74,4 +75,6 @@ class misc:
"us-east-1",
"us-east-2",
"us-west-2",
"us-gov-east-1",
"us-gov-west-1",
]
72 changes: 72 additions & 0 deletions deploy/determined_deploy/aws/deployment_types/govcloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import boto3

from determined_deploy.aws import aws, constants
from determined_deploy.aws.deployment_types import base


class Govcloud(base.DeterminedDeployment):
ssh_command = "SSH to master Instance: ssh -i <pem-file> ubuntu@{master_ip}"
det_ui = (
"Configure the Determined CLI: export DET_MASTER={master_ip}\n"
"View the Determined UI: http://{master_ip}:8080\n"
"View Logs at: https://{region}.console.amazonaws-us-gov.com/cloudwatch/home?"
"region={region}#logsV2:log-groups/log-group/{log_group}"
)

template = "govcloud.yaml"

template_parameter_keys = [
constants.cloudformation.ENABLE_CORS,
constants.cloudformation.MASTER_TLS_CERT,
constants.cloudformation.MASTER_TLS_KEY,
constants.cloudformation.MASTER_CERT_NAME,
constants.cloudformation.KEYPAIR,
constants.cloudformation.MASTER_INSTANCE_TYPE,
constants.cloudformation.CPU_AGENT_INSTANCE_TYPE,
constants.cloudformation.GPU_AGENT_INSTANCE_TYPE,
constants.cloudformation.INBOUND_CIDR,
constants.cloudformation.VERSION,
constants.cloudformation.DB_PASSWORD,
constants.cloudformation.MAX_IDLE_AGENT_PERIOD,
constants.cloudformation.MAX_AGENT_STARTING_PERIOD,
constants.cloudformation.MAX_CPU_CONTAINERS_PER_AGENT,
constants.cloudformation.MAX_DYNAMIC_AGENTS,
constants.cloudformation.SPOT_ENABLED,
constants.cloudformation.SPOT_MAX_PRICE,
constants.cloudformation.SUBNET_ID_KEY,
constants.cloudformation.SCHEDULER_TYPE,
constants.cloudformation.PREEMPTION_ENABLED,
constants.cloudformation.CPU_ENV_IMAGE,
constants.cloudformation.GPU_ENV_IMAGE,
constants.cloudformation.LOG_GROUP_PREFIX,
constants.cloudformation.RETAIN_LOG_GROUP,
]

def deploy(self) -> None:
cfn_parameters = self.consolidate_parameters()
self.before_deploy_print()
with open(self.template_path) as f:
template = f.read()

aws.deploy_stack(
stack_name=self.parameters[constants.cloudformation.CLUSTER_ID],
template_body=template,
keypair=self.parameters[constants.cloudformation.KEYPAIR],
boto3_session=self.parameters[constants.cloudformation.BOTO3_SESSION],
parameters=cfn_parameters,
)
self.print_results(
self.parameters[constants.cloudformation.CLUSTER_ID],
self.parameters[constants.cloudformation.BOTO3_SESSION],
)

def print_results(self, stack_name: str, boto3_session: boto3.session.Session) -> None:
output = aws.get_output(stack_name, boto3_session)
master_ip = output[constants.cloudformation.DET_ADDRESS]
region = output[constants.cloudformation.REGION]
log_group = output[constants.cloudformation.LOG_GROUP]
ui_command = self.det_ui.format(master_ip=master_ip, region=region, log_group=log_group)
print(ui_command)

ssh_command = self.ssh_command.format(master_ip=master_ip)
print(ssh_command)
Loading

0 comments on commit fc7fee6

Please sign in to comment.