Skip to content

Commit

Permalink
infra: blue/green deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
geclos committed Sep 26, 2024
1 parent 8fad1a4 commit ee0c68b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
needs: [lint, test]
strategy:
matrix:
app: [gateway, web, websockets, workers]
app: [gateway, websockets, workers]
uses: ./.github/workflows/deploy-app.yml
with:
app-name: ${{ matrix.app }}
Expand Down
94 changes: 71 additions & 23 deletions apps/infra/src/deployments/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const taskDefinition = pulumi
}),
)

const targetGroup = new aws.lb.TargetGroup('LatitudeLLMAppTg', {
const greenTargetGroup = new aws.lb.TargetGroup('LatitudeLLMAppTg', {
port: 8080,
vpcId,
protocol: 'HTTP',
Expand All @@ -157,46 +157,94 @@ const targetGroup = new aws.lb.TargetGroup('LatitudeLLMAppTg', {

const defaultListenerArn = coreStack.requireOutput('defaultListenerArn')

new aws.lb.ListenerRule('LatitudeLLMAppListenerRule', {
listenerArn: defaultListenerArn,
actions: [
{
type: 'forward',
targetGroupArn: targetGroup.arn,
},
],
conditions: [
{
hostHeader: {
values: [DNS_ADDRESS],
},
},
],
})

const cluster = coreStack.requireOutput('cluster') as pulumi.Output<Cluster>
new aws.ecs.Service('LatitudeLLMApp', {

const ecsService = new aws.ecs.Service('LatitudeLLMApp', {
cluster: cluster.arn,
taskDefinition: taskDefinition.arn,
desiredCount: 2,
launchType: 'FARGATE',
forceNewDeployment: true,
enableExecuteCommand: true,
deploymentController: {
type: 'CODE_DEPLOY',
},
networkConfiguration: {
subnets: privateSubnets.ids,
assignPublicIp: false,
securityGroups: [ecsSecurityGroup],
},
loadBalancers: [
{
targetGroupArn: targetGroup.arn,
targetGroupArn: greenTargetGroup.arn,
containerName,
containerPort: 8080,
},
],
triggers: {
digest: image.repoDigest,
coreDigest: coreImage.repoDigest,
})

const blueTargetGroup = new aws.lb.TargetGroup('LatitudeLLMAppBlueTg', {
port: 8080,
vpcId,
protocol: 'HTTP',
targetType: 'ip',
healthCheck: {
path: '/api/health',
interval: 5,
timeout: 2,
healthyThreshold: 2,
unhealthyThreshold: 2,
},
deregistrationDelay: 5,
})

const codeDeployApp = new aws.codedeploy.Application(
'LatitudeLLMCodeDeployApp',
{
computePlatform: 'ECS',
},
)

new aws.codedeploy.DeploymentGroup('LatitudeLLMDeploymentGroup', {
appName: codeDeployApp.name,
serviceRoleArn: ecsTaskExecutionRole,
deploymentConfigName: 'CodeDeployDefault.ECSAllAtOnce',
deploymentGroupName: 'LatitudeLLMDeploymentGroup',
ecsService: {
clusterName: cluster.name,
serviceName: ecsService.name,
},
autoRollbackConfiguration: {
enabled: true,
events: ['DEPLOYMENT_FAILURE'],
},
blueGreenDeploymentConfig: {
deploymentReadyOption: {
actionOnTimeout: 'CONTINUE_DEPLOYMENT',
waitTimeInMinutes: 0,
},
terminateBlueInstancesOnDeploymentSuccess: {
action: 'TERMINATE',
terminationWaitTimeInMinutes: 5,
},
},
deploymentStyle: {
deploymentOption: 'WITH_TRAFFIC_CONTROL',
deploymentType: 'BLUE_GREEN',
},
loadBalancerInfo: {
targetGroupPairInfo: {
prodTrafficRoute: {
listenerArns: [defaultListenerArn],
},
testTrafficRoute: {
listenerArns: [defaultListenerArn],
},
targetGroups: [
{ name: blueTargetGroup.name },
{ name: greenTargetGroup.name },
],
},
},
})

Expand Down

0 comments on commit ee0c68b

Please sign in to comment.