Skip to content

Commit

Permalink
chore: remove regional ECR code
Browse files Browse the repository at this point in the history
  • Loading branch information
jericht committed Jan 20, 2021
1 parent 719a41b commit 240cc2e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 512 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ def main():
database=storage.database,
file_system=storage.file_system,
vpc=network.vpc,
docker_recipes_stage_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'stage'),
ubl_certs_secret_arn=config.ubl_certificate_secret_arn,
ubl_licenses=config.ubl_licenses,
root_ca=security.root_ca,
dns_zone=network.dns_zone,
version=config.deadline_version
deadline_version=config.deadline_version
)
service = service_tier.ServiceTier(app, 'ServiceTier', props=service_props, env=env)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class ServiceTierProps(StackProps):
database: DatabaseConnection
# The file system to install Deadline Repository to.
file_system: IMountableLinuxFilesystem
# The path to the directory where the staged Deadline Docker recipes are.
docker_recipes_stage_path: str
# The ARN of the secret containing the UBL certificates .zip file (in binary form).
ubl_certs_secret_arn: typing.Optional[str]
# The UBL licenses to configure
Expand All @@ -70,7 +68,7 @@ class ServiceTierProps(StackProps):
# Internal DNS zone for the VPC
dns_zone: IPrivateHostedZone
# Version of Deadline to use
version: str
deadline_version: str


class ServiceTier(Stack):
Expand Down Expand Up @@ -118,7 +116,7 @@ def __init__(self, scope: Construct, stack_id: str, *, props: ServiceTierProps,
self.version = VersionQuery(
self,
'Version',
version=props.version,
version=props.deadline_version,
)

repository = Repository(
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-rfdk/lib/deadline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ If you desire a specific version of Deadline, you can supply a version with:
```ts
// Specify a version of Deadline
const version = new VersionQuery(scope, 'Version', {
version: '10.1.11',
version: '10.1.12',
});

// This will provide Docker container images for the specified version of Deadline
Expand Down Expand Up @@ -284,7 +284,7 @@ _**Note:** This construct is not usable in any China region._
The following example outlines how to construct `UsageBasedLicensing`:

```ts
const version = VersionQuery.exactString(stack, 'Version', '1.2.3.4');
const version = new VersionQuery(stack, 'Version', '1.2.3.4');
const images = new ThinkboxDockerImages(stack, 'Images', {
version: version,
});
Expand Down
65 changes: 12 additions & 53 deletions packages/aws-rfdk/lib/deadline/lib/thinkbox-docker-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import { randomBytes } from 'crypto';
import * as path from 'path';

import {
Repository,
} from '@aws-cdk/aws-ecr';
import {
ContainerImage,
} from '@aws-cdk/aws-ecs';
Expand Down Expand Up @@ -36,12 +33,6 @@ import {
* Interface to specify the properties when instantiating a {@link ThinkboxDockerImages} instnace.
*/
export interface ThinkboxDockerImagesProps {
/**
* An optional region for the ECR repository.
* @default global
*/
readonly region?: string;

/**
* The Deadline version to obtain images for.
* @default latest
Expand All @@ -64,7 +55,7 @@ export interface ThinkboxDockerImagesProps {
* const app = new App();
* const stack = new Stack(app, 'Stack');
* const vpc = new Vpc(app, stack);
* const images = new ThinkboxDockerImages(stack, 'Image'});
* const images = new ThinkboxDockerImages(stack, 'Image');
* const repository = new Repository(stack, 'Repository', {
* vpc,
* version: recipes.version
Expand Down Expand Up @@ -119,7 +110,6 @@ export class ThinkboxDockerImages extends Construct {
const ecrProvider = new CustomResource(this, 'ThinkboxEcrProvider', {
serviceToken: lambdaFunc.functionArn,
properties: {
Region: props?.region,
// create a random string that will force the Lambda to always run on redeploys. Changes to its output will be
// propagated to any CloudFormation resource providers that reference the output ARN
ForceRun: this.forceRun(),
Expand All @@ -130,49 +120,18 @@ export class ThinkboxDockerImages extends Construct {
this.node.defaultChild = ecrProvider;

const versionString = this.versionString(props?.version);
const ecrBaseURI = ecrProvider.getAtt('EcrURIPrefix').toString();

if (props?.region) {
const ecrBaseArn = ecrProvider.getAtt('EcrArnPrefix').toString();

this.remoteConnectionServer = ContainerImage.fromEcrRepository(
this.regionalRepoForRecipe(
ecrBaseArn,
ThinkboxManagedDeadlineDockerRecipes.REMOTE_CONNECTION_SERVER,
),
versionString,
);

this.licenseForwarder = ContainerImage.fromEcrRepository(
this.regionalRepoForRecipe(
ecrBaseArn,
ThinkboxManagedDeadlineDockerRecipes.LICENSE_FORWARDER,
),
versionString,
);
} else {
const ecrBaseURI = ecrProvider.getAtt('EcrURIPrefix').toString();

this.remoteConnectionServer = this.globalImageForRecipe(
ecrBaseURI,
ThinkboxManagedDeadlineDockerRecipes.REMOTE_CONNECTION_SERVER,
versionString,
);
this.licenseForwarder = this.globalImageForRecipe(
ecrBaseURI,
ThinkboxManagedDeadlineDockerRecipes.LICENSE_FORWARDER,
versionString,
);
}
}

private regionalRepoForRecipe(
ecrBaseArn: string,
recipe: string,
) {
return Repository.fromRepositoryAttributes(this, `Repository${recipe}`, {
repositoryArn: `${ecrBaseArn}${recipe}`,
repositoryName: `deadline/${recipe}`,
});
this.remoteConnectionServer = this.globalImageForRecipe(
ecrBaseURI,
ThinkboxManagedDeadlineDockerRecipes.REMOTE_CONNECTION_SERVER,
versionString,
);
this.licenseForwarder = this.globalImageForRecipe(
ecrBaseURI,
ThinkboxManagedDeadlineDockerRecipes.LICENSE_FORWARDER,
versionString,
);
}

private globalImageForRecipe(
Expand Down
75 changes: 0 additions & 75 deletions packages/aws-rfdk/lib/deadline/test/thinkbox-docker-images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
*/

import {
ABSENT,
arrayWith,
expect as expectCDK,
haveResource,
haveResourceLike,
objectLike,
stringLike,
} from '@aws-cdk/assert';
import {
Repository,
} from '@aws-cdk/aws-ecr';
import {
Compatibility,
ContainerDefinition,
Expand Down Expand Up @@ -57,7 +52,6 @@ describe('ThinkboxDockerRecipes', () => {
// THEN
expectCDK(stack).to(haveResource('Custom::RFDK-EcrProvider', {
ForceRun: stringLike('*'),
Region: ABSENT,
}));
});

Expand Down Expand Up @@ -198,73 +192,4 @@ describe('ThinkboxDockerRecipes', () => {
});
});
});

describe('with region', () => {
// GIVEN
const region = 'us-west-2';

beforeEach(() => {
// GIVEN
app = new App();
stack = new Stack(app, 'Stack');

// WHEN
images = new ThinkboxDockerImages(stack, 'Images', {
region,
});
});

test('passes Region property', () => {
// THEN
expectCDK(stack).to(haveResourceLike('Custom::RFDK-EcrProvider', {
Region: region,
}));
});

describe('provides container images for', () => {
test.each<[string, () => ContainerImage, ThinkboxManagedDeadlineDockerRecipes]>([
[
'RCS',
() => {
return images.remoteConnectionServer;
},
ThinkboxManagedDeadlineDockerRecipes.REMOTE_CONNECTION_SERVER,
],
[
'License Forwarder',
() => {
return images.licenseForwarder;
},
ThinkboxManagedDeadlineDockerRecipes.LICENSE_FORWARDER,
],
])('%s', (_label, imageGetter, recipe) => {
// GIVEN
const taskDefStack = new Stack(app, 'TaskDefStack');
const image = imageGetter();
const taskDefinition = new TaskDefinition(taskDefStack, 'TaskDef', {
compatibility: Compatibility.EC2,
});
const ecrProvider = images.node.defaultChild as CustomResource;
const repo = Repository.fromRepositoryAttributes(taskDefStack, 'Repo', {
repositoryArn: `${ecrProvider.getAttString('EcrArnPrefix')}${recipe}`,
repositoryName: `deadline/${recipe}`,
});
const containerImage = ContainerImage.fromEcrRepository(repo);

// WHEN
new ContainerDefinition(taskDefStack, 'ContainerDef', {
image,
taskDefinition,
memoryReservationMiB: 1024,
});

// THEN
expectCDK(taskDefStack).to(haveResource('AWS::ECS::TaskDefinition', {
ContainerDefinitions: arrayWith(objectLike({
Image: taskDefStack.resolve(containerImage.imageName),
})),
}));
});
});
});
});
29 changes: 7 additions & 22 deletions packages/aws-rfdk/lib/lambdas/nodejs/ecr-provider/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import {
* The input to this Custom Resource
*/
export interface ThinkboxEcrProviderResourceProperties {
/**
* The desired ECR region. If not provided, the global ECR is used.
*/
readonly Region?: string;

/**
* A random string that forces the Lambda to run again and obtain the latest ECR.
*/
Expand All @@ -40,8 +35,8 @@ export interface ThinkboxEcrProviderResourceOutput {
}

/**
* This custom resource will parse and return the base ECR ARN or URI containing Thinkbox published Docker Images. A
* region can be specified to get a regional ECR base ARN. Otherwise, the global ECR base URI is returned.
* This custom resource will parse and return the base ECR ARN or URI containing Thinkbox published Docker Images.
* A global ECR base URI is returned.
*/
export class ThinkboxEcrProviderResource extends SimpleCustomResource {
readonly ecrProvider: ThinkboxEcrProvider;
Expand All @@ -67,18 +62,11 @@ export class ThinkboxEcrProviderResource extends SimpleCustomResource {
/**
* @inheritdoc
*/
public async doCreate(_physicalId: string, resourceProperties: ThinkboxEcrProviderResourceProperties): Promise<ThinkboxEcrProviderResourceOutput> {
public async doCreate(_physicalId: string, _resourceProperties: ThinkboxEcrProviderResourceProperties): Promise<ThinkboxEcrProviderResourceOutput> {
let result: any;
if (resourceProperties.Region) {
result = {
EcrArnPrefix: await this.ecrProvider.getRegionalEcrBaseArn(resourceProperties.Region),
};
}
else {
result = {
EcrURIPrefix: await this.ecrProvider.getGlobalEcrBaseURI(),
};
}
result = {
EcrURIPrefix: await this.ecrProvider.getGlobalEcrBaseURI(),
};
console.log('result = ');
console.log(JSON.stringify(result, null, 4));
return result;
Expand All @@ -100,10 +88,7 @@ export class ThinkboxEcrProviderResource extends SimpleCustomResource {
return val === undefined || typeof(val) == 'string';
}

return (
isOptionalString(value.Region) &&
isOptionalString(value.ForceRun)
);
return isOptionalString(value.ForceRun);
}
}

Expand Down
Loading

0 comments on commit 240cc2e

Please sign in to comment.