amazon-ecs-deploy-task-definition
amazon-ecs-deploy-task-definition copied to clipboard
force-new-deployment doesn't stop active deployment
I have force-new-deployment set to true, but in bursts of deployments, I'd expect an active CodeDeploy deployment to stop the active deployment and start a new one. Is that wrong? Scenario this is happening:
- Deployment is made to ECS cluster and CodeDeploy activates. Typically, there is a 1 hour stability check so the deployment is still in progress. If I deploy again within that hour, GitHub Actions says that there is an active deployment.
- I'd expect either the original task set to be terminated or
- The new task set to be terminated
But neither happens. Do I not have enough IAM policies attached?
Thanks!
The force-new-deployment option only applies to ECS services with deployment controller type of "ECS", and not "CodeDeploy" as can be seen here: https://github.com/aws-actions/amazon-ecs-deploy-task-definition/blob/6d9617324a68960435ba17bdbdde29406bafff4c/index.js#L308-L315
I would agree that it'd be a great option to be able to cancel any past deployments in favor of the current deployment request.
thanks @danwagoner
i created a script where it'll stop any active deployments and wait for it to stop. I also decided that, in the blue green deployment setting, we would not terminate the original task set (not sure if that's even possible) and simply rollback the deployment to ensure we always have a healthy task set ie the original.
Let me know if that sounds like the better approach: just stop any active deployments. If so, happy to open a PR for dev community
@Andrew-Chen-Wang I'm about to create a script to do exactly this, do you happen to have it on hand?
I had it at the previous company I worked for, so can't share it directly. I do plan on rewriting it for general purposes for future projects since the script I wrote was custom made for the set up they had. I can list the commands I wrote:
- Get all deployments
const deployments: CodeDeploy.ListDeploymentsOutput = await new CodeDeploy().listDeployments({applicationName: "AppECS-cluster-service", deploymentGroupName: "DgpECS-cluster-service" }).promise()
- Check if there's any deployments:
if (deployments.deployments.length) { /* Cancel deployment */ }
-
const latestDeploymentId = deployments.deployments[0]; const latestDeployment = await new CodeDeploy().getDeployment({ deploymentId: latestDeploymentId }).promise()
- Check if latest deployment already finished:
if (["Succeeded", "Failed", "Stopped", "Ready"].includes(latestDeployment.deploymentInfo.status)) { core.info("No active deployments"); return; }
- Stop deployment if not one of the statuses above:
await CodeDeploy().stopDeployment({ deploymentId: latestDeploymentId }).promise();
That should get you started. You can also wait for service stability, but I believe that code is somewhere in here (I think I ripped it straight out of the aws-actions ECS deployment repo).
@oliverbutler I forgot, the scripts are right here: https://github.com/joinbloomapp/stock-market-game/tree/main/packages/scripts/src Feel free to take a gander!