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

infra: migrate ASG to CDK #8507

Merged
merged 56 commits into from
Aug 23, 2023
Merged

infra: migrate ASG to CDK #8507

merged 56 commits into from
Aug 23, 2023

Conversation

cemms1
Copy link
Contributor

@cemms1 cemms1 commented Aug 8, 2023

⚠️ N.B This PR must be merged after #8566
Please test both of these changes on CODE env thoroughly before removing the DO NOT MERGE label and merging.

What does this change?

Migrates the LaunchConfig and AutoscalingGroup from Cloudformation to CDK.

Why?

Resolves #7632 and #7633, as part of our migration to CDK

@cemms1 cemms1 changed the title infra: migrate asg to cdk and cleanup cloudformation template infra: migrate ASG to CDK and clean up Cloudformation template Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Size Change: 0 B

Total Size: 678 kB

ℹ️ View Unchanged
Filename Size
dotcom-rendering/dist/1076.modern.********************.js 3.09 kB
dotcom-rendering/dist/1149.modern.********************.js 2.92 kB
dotcom-rendering/dist/1168.modern.********************.js 19.3 kB
dotcom-rendering/dist/1244.modern.********************.js 869 B
dotcom-rendering/dist/1294.modern.********************.js 5.36 kB
dotcom-rendering/dist/1406.modern.********************.js 5.14 kB
dotcom-rendering/dist/1465.modern.********************.js 3.32 kB
dotcom-rendering/dist/1486.modern.********************.js 747 B
dotcom-rendering/dist/1848.modern.********************.js 647 B
dotcom-rendering/dist/1970.modern.********************.js 13.3 kB
dotcom-rendering/dist/1987.modern.********************.js 3.13 kB
dotcom-rendering/dist/1997.modern.********************.js 747 B
dotcom-rendering/dist/2071.modern.********************.js 748 B
dotcom-rendering/dist/21.modern.********************.js 762 B
dotcom-rendering/dist/2113.modern.********************.js 29.6 kB
dotcom-rendering/dist/2126.modern.********************.js 887 B
dotcom-rendering/dist/2149.modern.********************.js 4.22 kB
dotcom-rendering/dist/2187.modern.********************.js 6.48 kB
dotcom-rendering/dist/2201.modern.********************.js 778 B
dotcom-rendering/dist/2228.modern.********************.js 903 B
dotcom-rendering/dist/2339.modern.********************.js 781 B
dotcom-rendering/dist/2494.modern.********************.js 778 B
dotcom-rendering/dist/2619.modern.********************.js 3.62 kB
dotcom-rendering/dist/275.modern.********************.js 699 B
dotcom-rendering/dist/3024.modern.********************.js 624 B
dotcom-rendering/dist/3146.modern.********************.js 6.53 kB
dotcom-rendering/dist/3239.modern.********************.js 5.02 kB
dotcom-rendering/dist/3358.modern.********************.js 639 B
dotcom-rendering/dist/3549.modern.********************.js 21.3 kB
dotcom-rendering/dist/356.modern.********************.js 830 B
dotcom-rendering/dist/3960.modern.********************.js 621 B
dotcom-rendering/dist/3968.modern.********************.js 3.79 kB
dotcom-rendering/dist/4113.modern.********************.js 760 B
dotcom-rendering/dist/4306.modern.********************.js 6.37 kB
dotcom-rendering/dist/4593.modern.********************.js 1.67 kB
dotcom-rendering/dist/4603.modern.********************.js 3.9 kB
dotcom-rendering/dist/4734.modern.********************.js 761 B
dotcom-rendering/dist/4811.modern.********************.js 2.56 kB
dotcom-rendering/dist/4896.modern.********************.js 2.17 kB
dotcom-rendering/dist/5021.modern.********************.js 967 B
dotcom-rendering/dist/5071.modern.********************.js 944 B
dotcom-rendering/dist/5169.modern.********************.js 3.86 kB
dotcom-rendering/dist/5210.modern.********************.js 913 B
dotcom-rendering/dist/5211.modern.********************.js 2.92 kB
dotcom-rendering/dist/5225.modern.********************.js 6.59 kB
dotcom-rendering/dist/524.modern.********************.js 5.12 kB
dotcom-rendering/dist/5431.modern.********************.js 2.81 kB
dotcom-rendering/dist/5474.modern.********************.js 622 B
dotcom-rendering/dist/5974.modern.********************.js 745 B
dotcom-rendering/dist/6118.modern.********************.js 682 B
dotcom-rendering/dist/640.modern.********************.js 713 B
dotcom-rendering/dist/6437.modern.********************.js 871 B
dotcom-rendering/dist/6534.modern.********************.js 578 B
dotcom-rendering/dist/6541.modern.********************.js 817 B
dotcom-rendering/dist/6840.modern.********************.js 4.7 kB
dotcom-rendering/dist/7039.modern.********************.js 25.8 kB
dotcom-rendering/dist/7133.modern.********************.js 702 B
dotcom-rendering/dist/7305.modern.********************.js 889 B
dotcom-rendering/dist/7401.modern.********************.js 691 B
dotcom-rendering/dist/7498.modern.********************.js 3.64 kB
dotcom-rendering/dist/7688.modern.********************.js 817 B
dotcom-rendering/dist/786.modern.********************.js 480 B
dotcom-rendering/dist/8112.modern.********************.js 3.37 kB
dotcom-rendering/dist/8165.modern.********************.js 929 B
dotcom-rendering/dist/8170.modern.********************.js 492 B
dotcom-rendering/dist/8268.modern.********************.js 5.66 kB
dotcom-rendering/dist/8447.modern.********************.js 965 B
dotcom-rendering/dist/8505.modern.********************.js 559 B
dotcom-rendering/dist/8555.modern.********************.js 691 B
dotcom-rendering/dist/8622.modern.********************.js 862 B
dotcom-rendering/dist/8638.modern.********************.js 836 B
dotcom-rendering/dist/9490.modern.********************.js 829 B
dotcom-rendering/dist/9568.modern.********************.js 5.37 kB
dotcom-rendering/dist/9724.modern.********************.js 5.03 kB
dotcom-rendering/dist/9812.modern.********************.js 2.78 kB
dotcom-rendering/dist/992.modern.********************.js 3.03 kB
dotcom-rendering/dist/AlreadyVisited-importable.modern.********************.js 416 B
dotcom-rendering/dist/AppsFooter-importable.modern.********************.js 2.43 kB
dotcom-rendering/dist/atomIframe.modern.********************.js 514 B
dotcom-rendering/dist/AudioAtomWrapper-importable.modern.********************.js 3.28 kB
dotcom-rendering/dist/AustralianTerritorySwitcher-importable.modern.********************.js 4.09 kB
dotcom-rendering/dist/Branding-importable.modern.********************.js 2.2 kB
dotcom-rendering/dist/braze-web-sdk-core.modern.********************.js 36.9 kB
dotcom-rendering/dist/BrazeMessaging-importable.modern.********************.js 5.47 kB
dotcom-rendering/dist/CalloutBlockComponent-importable.modern.********************.js 6.48 kB
dotcom-rendering/dist/CalloutEmbedBlockComponent-importable.modern.********************.js 5.82 kB
dotcom-rendering/dist/CardCommentCount-importable.modern.********************.js 2.71 kB
dotcom-rendering/dist/Carousel-importable.modern.********************.js 5.32 kB
dotcom-rendering/dist/CarouselForNewsletters-importable.modern.********************.js 5.58 kB
dotcom-rendering/dist/ChartAtomWrapper-importable.modern.********************.js 476 B
dotcom-rendering/dist/CommentCount-importable.modern.********************.js 2.88 kB
dotcom-rendering/dist/discussion.modern.********************.js 397 B
dotcom-rendering/dist/DiscussionContainer-importable.modern.********************.js 23.6 kB
dotcom-rendering/dist/DiscussionMeta-importable.modern.********************.js 3.74 kB
dotcom-rendering/dist/DocumentBlockComponent-importable.modern.********************.js 2.73 kB
dotcom-rendering/dist/EmbedBlockComponent-importable.modern.********************.js 3.27 kB
dotcom-rendering/dist/embedIframe.modern.********************.js 519 B
dotcom-rendering/dist/EnhancePinnedPost-importable.modern.********************.js 1.94 kB
dotcom-rendering/dist/FetchOnwardsData-importable.modern.********************.js 2.01 kB
dotcom-rendering/dist/FilterKeyEventsToggle-importable.modern.********************.js 3.31 kB
dotcom-rendering/dist/FocusStyles-importable.modern.********************.js 511 B
dotcom-rendering/dist/FollowWrapper-importable.modern.********************.js 3.47 kB
dotcom-rendering/dist/frameworks.modern.********************.js 20.8 kB
dotcom-rendering/dist/GetCricketScoreboard-importable.modern.********************.js 3.26 kB
dotcom-rendering/dist/GetMatchNav-importable.modern.********************.js 12.4 kB
dotcom-rendering/dist/GetMatchStats-importable.modern.********************.js 357 B
dotcom-rendering/dist/GetMatchTabs-importable.modern.********************.js 2.31 kB
dotcom-rendering/dist/guardian-braze-components-banner.modern.********************.js 13.4 kB
dotcom-rendering/dist/guardian-braze-components-end-of-article.modern.********************.js 9.01 kB
dotcom-rendering/dist/GuideAtomWrapper-importable.modern.********************.js 4.88 kB
dotcom-rendering/dist/HeaderTopBar-importable.modern.********************.js 10.9 kB
dotcom-rendering/dist/index.modern.********************.js 38.5 kB
dotcom-rendering/dist/InstagramBlockComponent-importable.modern.********************.js 2.8 kB
dotcom-rendering/dist/InteractiveBlockComponent-importable.modern.********************.js 5.75 kB
dotcom-rendering/dist/InteractiveContentsBlockComponent-importable.modern.********************.js 3.79 kB
dotcom-rendering/dist/InteractiveSupportButton-importable.modern.********************.js 4.15 kB
dotcom-rendering/dist/KeyEventsCarousel-importable.modern.********************.js 2.22 kB
dotcom-rendering/dist/KnowledgeQuizAtomWrapper-importable.modern.********************.js 483 B
dotcom-rendering/dist/LatestLinks-importable.modern.********************.js 1.56 kB
dotcom-rendering/dist/LightboxHash-importable.modern.********************.js 425 B
dotcom-rendering/dist/LightboxJavascript-importable.modern.********************.js 4.39 kB
dotcom-rendering/dist/LiveBlogEpic-importable.modern.********************.js 4.95 kB
dotcom-rendering/dist/LiveblogRightMultipleAdSlots-importable.modern.********************.js 1.02 kB
dotcom-rendering/dist/Liveness-importable.modern.********************.js 3.53 kB
dotcom-rendering/dist/ManyNewsletterSignUp-importable.modern.********************.js 6.52 kB
dotcom-rendering/dist/MapEmbedBlockComponent-importable.modern.********************.js 5.34 kB
dotcom-rendering/dist/Metrics-importable.modern.********************.js 2.7 kB
dotcom-rendering/dist/MostViewedFooter-importable.modern.********************.js 5.38 kB
dotcom-rendering/dist/MostViewedFooterData-importable.modern.********************.js 7.61 kB
dotcom-rendering/dist/MostViewedRightWrapper-importable.modern.********************.js 3.7 kB
dotcom-rendering/dist/newsletterEmbedIframe.modern.********************.js 625 B
dotcom-rendering/dist/OnwardsUpper-importable.modern.********************.js 3.59 kB
dotcom-rendering/dist/PersonalityQuizAtomWrapper-importable.modern.********************.js 483 B
dotcom-rendering/dist/ProfileAtomWrapper-importable.modern.********************.js 480 B
dotcom-rendering/dist/PulsingDot-importable.modern.********************.js 746 B
dotcom-rendering/dist/QandaAtomWrapper-importable.modern.********************.js 478 B
dotcom-rendering/dist/ReaderRevenueDev-importable.modern.********************.js 463 B
dotcom-rendering/dist/readerRevenueDevUtils.modern.********************.js 3.02 kB
dotcom-rendering/dist/ReaderRevenueLinks-importable.modern.********************.js 4.91 kB
dotcom-rendering/dist/RecipeMultiplier-importable.modern.********************.js 3.23 kB
dotcom-rendering/dist/relativeTime.modern.********************.js 989 B
dotcom-rendering/dist/RichLinkComponent-importable.modern.********************.js 5.92 kB
dotcom-rendering/dist/SecureSignupIframe-importable.modern.********************.js 4.52 kB
dotcom-rendering/dist/SendAMessage-importable.modern.********************.js 4.39 kB
dotcom-rendering/dist/sentry.modern.********************.js 773 B
dotcom-rendering/dist/SetABTests-importable.modern.********************.js 4.08 kB
dotcom-rendering/dist/SetAdTargeting-importable.modern.********************.js 541 B
dotcom-rendering/dist/ShareCount-importable.modern.********************.js 2.93 kB
dotcom-rendering/dist/shimport.modern.********************.js 2.79 kB
dotcom-rendering/dist/ShowHideContainers-importable.modern.********************.js 638 B
dotcom-rendering/dist/ShowMore-importable.modern.********************.js 5.46 kB
dotcom-rendering/dist/SignInGateMain.modern.********************.js 1.26 kB
dotcom-rendering/dist/SignInGateMainCheckoutComplete.modern.********************.js 2.04 kB
dotcom-rendering/dist/SignInGateSelector-importable.modern.********************.js 3.67 kB
dotcom-rendering/dist/SlotBodyEnd-importable.modern.********************.js 3.1 kB
dotcom-rendering/dist/Snow-importable.modern.********************.js 3.02 kB
dotcom-rendering/dist/SpotifyBlockComponent-importable.modern.********************.js 5.19 kB
dotcom-rendering/dist/StickyBottomBanner-importable.modern.********************.js 4.01 kB
dotcom-rendering/dist/SubNav-importable.modern.********************.js 2.36 kB
dotcom-rendering/dist/SupportTheG-importable.modern.********************.js 5.01 kB
dotcom-rendering/dist/TableOfContents-importable.modern.********************.js 2.79 kB
dotcom-rendering/dist/TimelineAtomWrapper-importable.modern.********************.js 479 B
dotcom-rendering/dist/TweetBlockComponent-importable.modern.********************.js 1.01 kB
dotcom-rendering/dist/UnsafeEmbedBlockComponent-importable.modern.********************.js 2.81 kB
dotcom-rendering/dist/VideoFacebookBlockComponent-importable.modern.********************.js 5.36 kB
dotcom-rendering/dist/VineBlockComponent-importable.modern.********************.js 2.67 kB
dotcom-rendering/dist/WeatherWrapper-importable.modern.********************.js 4.96 kB
dotcom-rendering/dist/YoutubeBlockComponent-importable.modern.********************.js 293 B

compressed-size-action

default: `/${stack}/${stage.toLowerCase()}/logstash.stream.name`,
});

const userData = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing like-for-like here, but perhaps we could move this script to a separate file and load it in our CDK code, if we get round to optimisations in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea ✨ I've moved this to a different file

stage: 'PROD',
minCapacity: 15,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future optimisation note to parameterise these values


export class DotcomRendering extends GuStack {
constructor(scope: App, id: string, props: DCRProps) {
super(scope, id, props);

const { app, region, stack, stage } = props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful destructuring here

Copy link
Contributor

@DanielCliftonGuardian DanielCliftonGuardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* Fetches user data configuration for instances in the rendering app ASG
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
*/
export const getUserData = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a really cool idea! For now I'm going to leave the user data as a string since we are sticking to migrating the stack as is, without any changes. This is because the GuUserData abstraction is designed for a slightly more simple use case. We could definitely simplify our user data definition in the future but this would be a distinct change to the cloudformation template, which we are trying to keep fairly constant in this migration

type UserDataProps = Pick<DCRProps, 'app' | 'region' | 'stage'> & {
elkStreamId: string;
};

Copy link
Contributor

@ParisaTork ParisaTork Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future optimisation note for us to move towards launch templates, as launch configurations are deprecated:
Screenshot 2023-08-10 at 16 57 42

Copy link
Contributor Author

@cemms1 cemms1 Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already use launch templates :)
GuAutoscalingGroup does it for us here

I realise maybe the file name of this is confusing? I can call it user data if that's better. I personally find "user data" an unintuitive term, hence why I went for "launch config" as this explains to me much more directly what this is for (the config we supply for launching instances). User data is only part of the story for launch configuration though, so I'm open to suggestions!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're completely right - when I saw launch-config.ts, I assumed we were still using launch configurations, but you're entirely right that the GuAutoscalingGroup has a value for launch templates - in light of this, would we maybe want to change the filename to launch-template.tsor user-data.ts as you've already wonderfully suggested?

@cemms1 cemms1 changed the base branch from main to cemms1/cdk-change-lb-definition August 14, 2023 13:36
# Keep the Node version in sync with `.nvmrc`
Recipe: dotcom-rendering-ARM-jammy-node-18.17.0
BuiltBy: amigo
AmigoStage: PROD
rendering:
type: autoscaling
parameters:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add an asgMigrationInProgress param here, like so: https://github.com/guardian/amigo/pull/632/files#diff-8bd759df9f9dfeeb4ba5ee57a1c7a0a3563f8281a526b49854ecb6972102aaa8R10

Suggested change
parameters:
parameters:
asgMigrationInProgress: true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, not at this stage - but when we do migrate our load balancer to an ALB this might be necessary

@@ -175,6 +186,40 @@ export class DotcomRendering extends GuStack {
reason: 'Retaining a stateful resource previously defined in YAML',
});

const asg = new GuAutoScalingGroup(this, 'AutoscalingGroup', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ParisaTork this is really useful documentation, thanks for finding it and linking it. We are trying to migrate the code here (from the Cloudformation YAML to CDK) rather than the resources themselves so as long as we don't add/remove the stateful resources here, I don't think we need to "migrate" as set out in that doc.

Having said that, when I chatted to DevX last week, they hinted that this migration strategy (the dual stack approach) might have been a better choice for us rather than the way that we did it - which was a piece by piece method. Since we've already done most of this, it makes sense to continue this way unless we encounter any more large blockers to moving forward.

Base automatically changed from cemms1/cdk-change-lb-definition to main August 17, 2023 14:56
`mkdir /var/log/dotcom-rendering`,
`chown -R dotcom-rendering:frontend /var/log/dotcom-rendering`,

`make start-prod`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to consider #8640 before merging as this PR moves the definition of user data out of the cloudformation.yaml file

@cemms1 cemms1 merged commit 1f63771 into main Aug 23, 2023
@cemms1 cemms1 deleted the cemms1/cdk-migrate-asg branch August 23, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotcom-rendering run_chromatic Runs chromatic when label is applied
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDK: LaunchConfig Migration
3 participants