-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
Co-authored-by: DanielCliftonGuardian [email protected] Co-authored-by: Charlotte [email protected]
Size Change: 0 B Total Size: 678 kB ℹ️ View Unchanged
|
default: `/${stack}/${stage.toLowerCase()}/logstash.stream.name`, | ||
}); | ||
|
||
const userData = ` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful destructuring here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use this construct here https://github.com/guardian/cdk/blob/1d5918085d533513de0b165be815019f98e880ad/src/constructs/autoscaling/user-data.ts#L23C14-L23C24
* 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 = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use this construct here https://github.com/guardian/cdk/blob/1d5918085d533513de0b165be815019f98e880ad/src/constructs/autoscaling/user-data.ts#L23C14-L23C24
There was a problem hiding this comment.
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
Co-Authored-By: Charlotte Emms <[email protected]>
Co-Authored-By: Charlotte Emms <[email protected]> Co-Authored-By: Daniel Clifton <[email protected]>
…-rendering into cdk/InternalLoadBalancer
Co-Authored-By: Parisa Tork <[email protected]> Co-Authored-By: Charlotte Emms <[email protected]>
Co-Authored-By: Parisa Tork <[email protected]> Co-Authored-By: Charlotte Emms <[email protected]>
type UserDataProps = Pick<DCRProps, 'app' | 'region' | 'stage'> & { | ||
elkStreamId: string; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.ts
or user-data.ts
as you've already wonderfully suggested?
# 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: |
There was a problem hiding this comment.
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
parameters: | |
parameters: | |
asgMigrationInProgress: true |
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
dotcom-rendering/cdk/lib/userData.ts
Outdated
`mkdir /var/log/dotcom-rendering`, | ||
`chown -R dotcom-rendering:frontend /var/log/dotcom-rendering`, | ||
|
||
`make start-prod`, |
There was a problem hiding this comment.
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
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