Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Use GuEc2AppExperimental from guardian/cdk#2417
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1810 committed Aug 22, 2024
1 parent ba9909b commit 57e418c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 12 deletions.
104 changes: 98 additions & 6 deletions lib/__snapshots__/testing-asg-rolling-update.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`The TestingAsgRollingUpdate stack matches the snapshot 1`] = `
"GuVpcParameter",
"GuSubnetListParameter",
"GuSubnetListParameter",
"GuPlayApp",
"GuEc2AppExperimental",
"GuDistributionBucketParameter",
"GuCertificate",
"GuInstanceRole",
Expand Down Expand Up @@ -73,8 +73,46 @@ exports[`The TestingAsgRollingUpdate stack matches the snapshot 1`] = `
},
},
"Resources": {
"AsgReplacingUpdatePolicy78CF34D5": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "cloudformation:SignalResource",
"Effect": "Allow",
"Resource": {
"Ref": "AWS::StackId",
},
},
{
"Action": "elasticloadbalancing:DescribeTargetHealth",
"Effect": "Allow",
"Resource": "*",
},
],
"Version": "2012-10-17",
},
"PolicyName": "AsgReplacingUpdatePolicy78CF34D5",
"Roles": [
{
"Ref": "InstanceRoleTestingasgrollingupdate9C94CB64",
},
],
},
"Type": "AWS::IAM::Policy",
},
"AutoScalingGroupTestingasgrollingupdateASGC3E6DA11": {
"CreationPolicy": {
"AutoScalingCreationPolicy": {
"MinSuccessfulInstancesPercent": 100,
},
"ResourceSignal": {
"Count": 1,
"Timeout": "PT5M",
},
},
"Properties": {
"DesiredCapacity": "1",
"HealthCheckGracePeriod": 120,
"HealthCheckType": "ELB",
"LaunchTemplate": {
Expand All @@ -92,10 +130,6 @@ exports[`The TestingAsgRollingUpdate stack matches the snapshot 1`] = `
"MetricsCollection": [
{
"Granularity": "1Minute",
"Metrics": [
"GroupTotalInstances",
"GroupInServiceInstances",
],
},
],
"MinSize": "1",
Expand Down Expand Up @@ -158,6 +192,18 @@ exports[`The TestingAsgRollingUpdate stack matches the snapshot 1`] = `
},
},
"Type": "AWS::AutoScaling::AutoScalingGroup",
"UpdatePolicy": {
"AutoScalingRollingUpdate": {
"MaxBatchSize": 2,
"MinInstancesInService": 1,
"MinSuccessfulInstancesPercent": 100,
"SuspendProcesses": [],
"WaitOnResourceSignals": true,
},
"AutoScalingScheduledAction": {
"IgnoreUnmodifiedGroupSizeProperties": true,
},
},
},
"CertificateTestingasgrollingupdateB9B60CB2": {
"DeletionPolicy": "Retain",
Expand Down Expand Up @@ -883,13 +929,59 @@ exports[`The TestingAsgRollingUpdate stack matches the snapshot 1`] = `
"",
[
"#!/bin/bash
function exitTrap(){
exitCode=$?
cfn-signal --stack ",
{
"Ref": "AWS::StackId",
},
" --resource AutoScalingGroupTestingasgrollingupdateASGC3E6DA11 --region ",
{
"Ref": "AWS::Region",
},
" --exit-code $exitCode || echo 'Failed to send Cloudformation Signal'
}
trap exitTrap EXIT
mkdir -p $(dirname '/testing-asg-rolling-update/testing-asg-rolling-update_ABC.deb')
aws s3 cp 's3://",
{
"Ref": "DistributionBucketName",
},
"/playground/TEST/testing-asg-rolling-update/testing-asg-rolling-update_ABC.deb' '/testing-asg-rolling-update/testing-asg-rolling-update_ABC.deb'
dpkg -i /testing-asg-rolling-update/testing-asg-rolling-update_ABC.deb",
dpkg -i /testing-asg-rolling-update/testing-asg-rolling-update_ABC.deb
# GuEc2AppExperimental UserData Start
INSTANCE_ID=$(ec2metadata --instance-id)
STATE=$(aws elbv2 describe-target-health --target-group-arn ",
{
"Ref": "TargetGroupTestingasgrollingupdateC5208046",
},
" --region ",
{
"Ref": "AWS::Region",
},
" --targets Id=$INSTANCE_ID,Port=9000 --query "TargetHealthDescriptions[0].TargetHealth.State")
until [ "$STATE" == "\\"healthy\\"" ]; do
echo "Instance not yet healthy within target group. Current state $STATE. Sleeping..."
sleep 5
STATE=$(aws elbv2 describe-target-health --target-group-arn ",
{
"Ref": "TargetGroupTestingasgrollingupdateC5208046",
},
" --region ",
{
"Ref": "AWS::Region",
},
" --targets Id=$INSTANCE_ID,Port=9000 --query "TargetHealthDescriptions[0].TargetHealth.State")
done
echo "Instance is healthy in target group."
# GuEc2AppExperimental UserData End",
],
],
},
Expand Down
5 changes: 3 additions & 2 deletions lib/testing-asg-rolling-update.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GuPlayApp } from '@guardian/cdk';
import { AccessScope } from '@guardian/cdk/lib/constants';
import type { GuStackProps } from '@guardian/cdk/lib/constructs/core';
import { GuStack } from '@guardian/cdk/lib/constructs/core';
import { GuCname } from '@guardian/cdk/lib/constructs/dns';
import { GuEc2AppExperimental } from '@guardian/cdk/lib/experimental/patterns/ec2-app';
import type { App } from 'aws-cdk-lib';
import { Duration, Tags } from 'aws-cdk-lib';
import { InstanceClass, InstanceSize, InstanceType } from 'aws-cdk-lib/aws-ec2';
Expand All @@ -20,7 +20,8 @@ export class TestingAsgRollingUpdate extends GuStack {
const app = 'testing-asg-rolling-update';
const domainName = `${app}.code.dev-gutools.co.uk`;

const { loadBalancer, autoScalingGroup } = new GuPlayApp(this, {
const { loadBalancer, autoScalingGroup } = new GuEc2AppExperimental(this, {
applicationPort: 9000,
app,
instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.MICRO),
access: { scope: AccessScope.PUBLIC },
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"diff": "cdk diff --path-metadata false --version-reporting false"
},
"devDependencies": {
"@guardian/cdk": "59.2.4",
"@guardian/cdk": "github:guardian/cdk#aa/ec2-AutoScalingReplacingUpdate",
"@guardian/eslint-config-typescript": "8.0.0",
"@guardian/prettier": "5.0.0",
"@guardian/tsconfig": "^1.0.0",
Expand Down

0 comments on commit 57e418c

Please sign in to comment.