Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecs): Add ECS cluster and task to CDK #3

Open
wants to merge 5 commits into
base: feat/spotfleet-mgmt-ui
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env
10 changes: 8 additions & 2 deletions DeadlineStack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ These instructions assume that your working directory is `examples/deadline/SIC-
npx --package=aws-rfdk@${RFDK_VERSION} stage-deadline --output stage ${RFDK_DEADLINE_VERSION}
```

5. Deploy all the stacks:
5. Deploy ECR repository and push Spotfleet Mgmt UI related Docker image to it. Run the script like this:

```bash
./deploy_spotfleet_mgmt_ui.sh -a YOUR_AWS_ACCOUNT_ID -r YOUR_AWS_REGION -p YOUR_AWS_PROFILE
```

6. Deploy all the stacks:

```bash
cdk deploy "*"
```

6. Once you are finished with the sample app, you can tear it down by running:
7. Once you are finished with the sample app, you can tear it down by running:

**Note:** Any resources created by the Spot Event Plugin will not be deleted with `cdk destroy`. Make sure that all such resources (e.g. Spot Fleet Request or Fleet Instances) are cleaned up, before destroying the stacks. Disable the Spot Event Plugin by setting 'state' property to 'SpotEventPluginState.DISABLED' or via Deadline Monitor, ensure you shutdown all Pulse instances and then terminate any Spot Fleet Requests in the AWS EC2 Instance Console.

Expand Down
52 changes: 52 additions & 0 deletions DeadlineStack/deploy_spotfleet_mgmt_ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

# Script parameters for AWS account, region, and profile
while getopts a:r:p: flag; do
case "${flag}" in
a)
AWS_ACCOUNT=${OPTARG}
;;
r)
REGION=${OPTARG}
;;
p)
PROFILE=${OPTARG:-default}
;;
*) echo "Invalid option: -$flag" ;;
esac
done

# Function to create ECR repository if it doesn't exist
create_ecr_repo() {
repo_name="spotfleet-mgmt-ui"
echo "Checking if the ECR repository '${repo_name}' exists..."

if ! aws ecr describe-repositories --region "${REGION}" --repository-names "${repo_name}" > /dev/null 2>&1; then
echo "Repository does not exist. Creating '${repo_name}' repository..."
aws ecr create-repository --region "${REGION}" --repository-name "${repo_name}"
else
echo "Repository '${repo_name}' already exists. Skipping creation."
fi
}

# Create the ECR repository
create_ecr_repo

# Define repository URL
SpotfleetMgmtUiRepository="${AWS_ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com/spotfleet-mgmt-ui"

# Build the Docker image for spotfleet-mgmt-ui
echo "Building the spotfleet-mgmt-ui Docker image..."
docker build -t "${SpotfleetMgmtUiRepository}":latest ./spotfleet-mgmt-ui

# Login to AWS ECR
echo "Logging in to AWS ECR..."
aws ecr get-login-password --region "${REGION}" | docker login --username AWS --password-stdin "${AWS_ACCOUNT}".dkr.ecr."${REGION}".amazonaws.com

# Push the image to the ECR repository
echo "Pushing the spotfleet-mgmt-ui image to ECR..."
docker push "${SpotfleetMgmtUiRepository}":latest

# Output the Docker image URI
echo "Docker image pushed successfully."
echo "Docker Image URI: ${SpotfleetMgmtUiRepository}:latest"
40 changes: 17 additions & 23 deletions DeadlineStack/package/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
Mapping,
)


class AppConfig:
"""
Configuration values for the sample app.

TODO: Fill these in with your own values.
"""

def __init__(self):
# A map of regions to Deadline Client Linux AMIs. As an example, the base Linux Deadline 10.1.19.4 AMI ID
# from us-west-2 is filled in. It can be used as-is, added to, or replaced. Ideally the version here
# should match the one used for staging the render queue and usage based licensing recipes.
self.deadline_client_linux_ami_map: Mapping[str, str] = {'us-west-2': 'ami-067d780e98fe3b09f'}
self.deadline_client_linux_ami_map: Mapping[str, str] = {
'eu-west-3': 'ami-08afbca41a57b6e72'}

# Whether the DeadlineResourceTrackerAccessRole IAM role required by Deadline's Resource Tracker should be created in this CDK app.
#
Expand All @@ -33,17 +36,17 @@ def __init__(self):
# Note: Deadline's Resource Tracker only supports being used by a single Deadline Repository per AWS account.
self.create_resource_tracker_role: bool = True
# AWS region deadline is deployed into (ex: "us-west-2")
self.aws_region:str = ""
self.aws_region: str = "eu-west-3"
# Deadline VPC CIDR required (ex:"172.0.0.0/16")
self.vpc_cidr: str = ""
self.vpc_cidr: str = "10.2.0.0/16"
# Bucket for workers script
self.s3_bucket_workers: str = ""
self.s3_bucket_workers: str = "deadline-workers-scripts-test"
# S3 bucket worker region (verifiy this on S3 service)
self.s3_bucket_workers_region: str = ""
self.s3_bucket_workers_region: str = "eu-west-3"
# EC2 test instance AMI
self.custom_ami_id: str = ""
self.custom_ami_id: str = "ami-0c75d0e0e7489cfbe"
# EC2 test instance key pair
self.ec2_key_pair_name: str = ""
self.ec2_key_pair_name: str = "deadlinetest"

# Spot instance fleet configuration
# For each fleet, use those parameters:
Expand All @@ -56,23 +59,14 @@ def __init__(self):
# "user_data_script" expecting filename (sh for Linux, ps1 for Windows) is an additional script file you uploaded to the worker S3 bucket
self.fleet_config: dict = {
"fleet1": {
"name":"Blender",
"is_linux":1,
"name": "Blender",
"is_linux": 1,
# "instance_types":[InstanceType.of(InstanceClass.BURSTABLE3, InstanceSize.LARGE)],
"instance_types":["m5.large","m5.2xlarge"],
"worker_machine_image":"",
"max_capacity":1,
"allocation_strategy":SpotFleetAllocationStrategy.CAPACITY_OPTIMIZED,
"user_data_script":""
},
"fleet2": {
"name":"Maya",
"is_linux":1,
"instance_types":["m5.large","m5.2xlarge"],
"worker_machine_image":"",
"max_capacity":1,
"allocation_strategy":SpotFleetAllocationStrategy.CAPACITY_OPTIMIZED,
"user_data_script":""
"instance_types": ["m5.large", "m5.2xlarge"],
"worker_machine_image": "ami-08afbca41a57b6e72",
"max_capacity": 1,
"allocation_strategy": SpotFleetAllocationStrategy.CAPACITY_OPTIMIZED,
"user_data_script": ""
}
}

Expand Down
Loading