Skip to content

Commit

Permalink
fix: support new 'ECS' deployment type rather than relying on a null …
Browse files Browse the repository at this point in the history
…value (#387)

* revert to working build and add check

* Support nil for deployment controller as well

* package

* check `type`

* add a test

Co-authored-by: Braden Simpson <bradensimpsons@gmail.com>
  • Loading branch information
dannyrandall and bradens authored Sep 30, 2022
1 parent 82ada25 commit b74b034
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ async function run() {
throw new Error(`Service is ${serviceResponse.status}`);
}

if (!serviceResponse.deploymentController) {
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
// Service uses the 'ECS' deployment controller, so we can call UpdateService
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment);
} else if (serviceResponse.deploymentController.type == 'CODE_DEPLOY') {
} else if (serviceResponse.deploymentController.type === 'CODE_DEPLOY') {
// Service uses CodeDeploy, so we should start a CodeDeploy deployment
await createCodeDeployDeployment(codedeploy, clusterName, service, taskDefArn, waitForService, waitForMinutes);
} else {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ async function run() {
throw new Error(`Service is ${serviceResponse.status}`);
}

if (!serviceResponse.deploymentController) {
if (!serviceResponse.deploymentController || !serviceResponse.deploymentController.type || serviceResponse.deploymentController.type === 'ECS') {
// Service uses the 'ECS' deployment controller, so we can call UpdateService
await updateEcsService(ecs, clusterName, service, taskDefArn, waitForService, waitForMinutes, forceNewDeployment);
} else if (serviceResponse.deploymentController.type == 'CODE_DEPLOY') {
} else if (serviceResponse.deploymentController.type === 'CODE_DEPLOY') {
// Service uses CodeDeploy, so we should start a CodeDeploy deployment
await createCodeDeployDeployment(codedeploy, clusterName, service, taskDefArn, waitForService, waitForMinutes);
} else {
Expand Down
35 changes: 35 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ describe('Deploy to ECS', () => {
expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=fake-region#/clusters/cluster-789/services/service-456/events");
});

test('registers the task definition contents and updates the service if deployment controller type is ECS', async () => {
mockEcsDescribeServices.mockImplementation(() => {
return {
promise() {
return Promise.resolve({
failures: [],
services: [{
status: 'ACTIVE',
deploymentController: {
type: 'ECS'
}
}]
});
}
};
});

await run();
expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(mockEcsRegisterTaskDef).toHaveBeenNthCalledWith(1, { family: 'task-def-family'});
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'task-definition-arn', 'task:def:arn');
expect(mockEcsDescribeServices).toHaveBeenNthCalledWith(1, {
cluster: 'cluster-789',
services: ['service-456']
});
expect(mockEcsUpdateService).toHaveBeenNthCalledWith(1, {
cluster: 'cluster-789',
service: 'service-456',
taskDefinition: 'task:def:arn',
forceNewDeployment: false
});
expect(mockEcsWaiter).toHaveBeenCalledTimes(0);
expect(core.info).toBeCalledWith("Deployment started. Watch this deployment's progress in the Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=fake-region#/clusters/cluster-789/services/service-456/events");
});

test('prints Chinese console domain for cn regions', async () => {
const originalRegion = config.region;
config.region = 'cn-fake-region';
Expand Down

0 comments on commit b74b034

Please sign in to comment.