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

adds stubbing for ecs deployment msgs #36

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/api/ecs/deployment-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from '~/src/config'

import { ecsDeploymentEvent } from '~/src/api/ecs/payloads/ecs-deployment-event'
import { lambdaDeploymentUpdate } from '~/src/api/ecs/payloads/lambda-deployment-update'
import { ecsDeployStatusChangeEvent } from '~/src/api/ecs/payloads/ecs-deploy-status-change-event'

const logger = createLogger()

Expand All @@ -22,7 +23,7 @@ async function deploymentHandler(sqs, payload) {
const instanceCount = msg?.desired_count

const deploymentId = msg?.deployed_by?.deployment_id
const lamdaId = crypto.randomUUID()
const lamdaId = `ecs-svc/${crypto.randomUUID()}`
const taskId = Math.floor(Math.random() * 1000000)

// Lamba update
Expand Down Expand Up @@ -62,6 +63,15 @@ async function deploymentHandler(sqs, payload) {
await send(sqs, payload, deploymentFlow[j].delay)
}
}

const deployStatusChangeEvent = ecsDeployStatusChangeEvent(
awsAccount,
new Date(),
lamdaId,
'SERVICE_DEPLOYMENT_COMPLETED',
`ECS deployment ${lamdaId} completed.`
)
await send(sqs, deployStatusChangeEvent, 5)
}

async function send(sqs, payload, delay = 0) {
Expand Down
28 changes: 28 additions & 0 deletions src/api/ecs/payloads/ecs-deploy-status-change-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function ecsDeployStatusChangeEvent(
awsAccountId,
now,
deploymentId,
eventName,
reason
) {
return {
version: '0',
id: crypto.randomUUID(),
'detail-type': 'ECS Deployment State Change',
source: 'aws.ecs',
account: awsAccountId,
time: now,
region: 'eu-west-2',
resources: [
`arn:aws:ecs:eu-west-2:${awsAccountId}:task/dev-ecs-public/f8bec92bed774ee4b27711702a862de5`
],
detail: {
eventType: 'INFO',
eventName,
deploymentId,
updatedAt: now,
reason
}
}
}
export { ecsDeployStatusChangeEvent }
2 changes: 1 addition & 1 deletion src/api/ecs/payloads/ecs-deployment-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function ecsDeploymentEvent(
pullStartedAt: now,
pullStoppedAt: now,
startedAt: now,
startedBy: `ecs-svc/${lambdaId}`,
startedBy: lambdaId,
taskArn: `arn:aws:ecs:eu-west-2:000000000000:task/dev-ecs-public/${taskArn}`,
taskDefinitionArn: `arn:aws:ecs:eu-west-2:000000000000:task-definition/${service}:${taskId}`,
updatedAt: now,
Expand Down
2 changes: 1 addition & 1 deletion src/api/ecs/payloads/lambda-deployment-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function lambdaDeploymentUpdate(
detail: {
eventType: 'INFO',
eventName: 'IN_PROGRESS',
deploymentId: `ecs-svc/${lambdaId}`,
deploymentId: lambdaId,
reason: `Deployment arn:aws:ecs:eu-west-2:${awsAccountId}:service/infra-dev-ecs-public/${service} successfully updated`
},
deployed_by: 'Test, User',
Expand Down
Loading