Skip to content

Commit

Permalink
Merge pull request #170 from aws-samples/dev
Browse files Browse the repository at this point in the history
fix: couple's of issues.
  • Loading branch information
wchaws authored Oct 30, 2022
2 parents 0332228 + 8ce4d11 commit 26b94f6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
21 changes: 13 additions & 8 deletions src/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ export interface AutoScaleTask {
*
* @default - min + 5
*/
readonly max ?: number;
readonly max?: number;
/**
* The target cpu utilization for the service autoscaling
*
* @default 75
*/
readonly targetCpuUtilization ?: number;
readonly targetCpuUtilization?: number;
}

export interface KeyCloakProps {
Expand Down Expand Up @@ -501,15 +501,16 @@ export class ContainerService extends cdk.Construct {

const vpc = props.vpc;
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
cluster.node.addDependency(props.database);
const taskRole = new iam.Role(this, 'TaskRole', {
assumedBy: new iam.CompositePrincipal(
new iam.ServicePrincipal('ecs.amazonaws.com'),
new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
),
});
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
cpu: 1024,
memoryLimitMiB: 2048,
cpu: 4096,
memoryLimitMiB: 8192,
executionRole: taskRole,
});

Expand All @@ -527,6 +528,7 @@ export class ContainerService extends cdk.Construct {
DB_USER: 'admin',
DB_VENDOR: 'mysql',
// KEYCLOAK_LOGLEVEL: 'DEBUG',
PROXY_ADDRESS_FORWARDING: 'true',
JDBC_PARAMS: 'useSSL=false',
JGROUPS_DISCOVERY_PROTOCOL: 'JDBC_PING',
// We don't need to specify `initialize_sql` string into `JGROUPS_DISCOVERY_PROPERTIES` property,
Expand Down Expand Up @@ -572,7 +574,7 @@ export class ContainerService extends cdk.Construct {
const minCapacity = props.autoScaleTask.min ?? props.nodeCount ?? 2;
const scaling = this.service.autoScaleTaskCount({
minCapacity,
maxCapacity: props.autoScaleTask.max ?? minCapacity+5,
maxCapacity: props.autoScaleTask.max ?? minCapacity + 5,
});
scaling.scaleOnCpuUtilization('CpuScaling', {
targetUtilizationPercent: props.autoScaleTask.targetCpuUtilization ?? 75,
Expand All @@ -593,6 +595,9 @@ export class ContainerService extends cdk.Construct {

listener.addTargets('ECSTarget', {
targets: [this.service],
healthCheck: {
healthyThresholdCount: 3,
},
// set slow_start.duration_seconds to 60
// see https://docs.aws.amazon.com/cli/latest/reference/elbv2/modify-target-group-attributes.html
slowStart: cdk.Duration.seconds(60),
Expand Down Expand Up @@ -630,14 +635,14 @@ export class ContainerService extends cdk.Construct {
return imageMap.findInMap(cdk.Aws.PARTITION, 'uri');
} else {
if (stack.region.startsWith('cn-')) {
return map['aws-cn']+=version;
return map['aws-cn'] += version;
} else {
return map.aws+=version;
return map.aws += version;
}
}
}
private getKeyCloakDockerImageUri(version: string): string {
return this.getImageUriFromMap(KEYCLOAK_DOCKER_IMAGE_URI_MAP, version, 'KeycloakImageMap' );
return this.getImageUriFromMap(KEYCLOAK_DOCKER_IMAGE_URI_MAP, version, 'KeycloakImageMap');
}
}

Expand Down
18 changes: 16 additions & 2 deletions test/__snapshots__/integ.snapshot.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ test('with env', () => {
Name: 'DB_VENDOR',
Value: 'mysql',
},
{
Name: 'PROXY_ADDRESS_FORWARDING',
Value: 'true',
},
{
Name: 'JDBC_PARAMS',
Value: 'useSSL=false',
Expand Down Expand Up @@ -420,15 +424,15 @@ test('with env', () => {
],
},
],
Cpu: '1024',
Cpu: '4096',
ExecutionRoleArn: {
'Fn::GetAtt': [
'KeyCloakKeyCloakContainerSerivceTaskRole0658CED2',
'Arn',
],
},
Family: 'testingstackKeyCloakKeyCloakContainerSerivceTaskDef799BAD5B',
Memory: '2048',
Memory: '8192',
NetworkMode: 'awsvpc',
RequiresCompatibilities: [
'FARGATE',
Expand Down

0 comments on commit 26b94f6

Please sign in to comment.