Skip to main content

After the hard work has been done during previous sections, now it's time to hook up the final steps to complete the end-to-end Continuous Development (CD) workflow ensuring that the images, that we have created, tested and pushed can then be deployed into our Cluster, replacing the previous image.

Finalise automated deployments

Wow, this is getting tiring but the end is within sight! 

Currently, we can push new deployment images to ECR. We can also trigger new deployments manually in the ECS service page. However, what we want is to automatically trigger a deployment straight after pushing our new image to ECR.

For this, we need to make a copy of the task-definition JSON. In the ECS console for your service, click on the task definition link, then click the ‘JSON’ tab.

Copy this JSON into a new file ‘task-definition.json’ in the root of your code directory.

The atlassian/aws-ecs-deploy:1.2.0 will complain if it finds any variables in this file with a null value, so go through this file and just delete all null variables.

Save it, then edit your bitbucket-pipelines.yml file. Add or uncomment the final step to include:

- step:
  name: Deploy to ECS
  script:
    - export IMAGE_NAME="${AWS_URI}"
    - pipe: atlassian/aws-ecs-deploy:1.2.0
      variables:
        AWS_ACCESS_KEY_ID: ${AWS_KEY}
        AWS_SECRET_ACCESS_KEY: ${AWS_SECRET}
        AWS_DEFAULT_REGION: ${AWS_REGION}
        CLUSTER_NAME: 'example-cluster'
        SERVICE_NAME: 'example-container-service'
        TASK_DEFINITION: 'task-definition.json'
        WAIT: 'True'

Make sure CLUSTER_NAME and SERVICE_NAME match what you have set.

If you commit and push these changes to develop branch, it will probably still fail with some errors such as :

Unknown parameter in input: "compatibilities", must be one of: family, taskRoleArn, executionRoleArn, networkMode, containerDefinitions, volumes, placementConstraints, requiresCompatibilities, cpu, memory, tags, pidMode, ipcMode, proxyConfiguration, inferenceAccelerators

Unknown parameter in input: "taskDefinitionArn", must be one of: family, taskRoleArn, executionRoleArn, networkMode, containerDefinitions, volumes, placementConstraints, requiresCompatibilities, cpu, memory, tags, pidMode, ipcMode, proxyConfiguration, inferenceAccelerators

Unknown parameter in input: "requiresAttributes", must be one of: family, taskRoleArn, executionRoleArn, networkMode, containerDefinitions, volumes, placementConstraints, requiresCompatibilities, cpu, memory, tags, pidMode, ipcMode, proxyConfiguration, inferenceAccelerators

Unknown parameter in input: "revision", must be one of: family, taskRoleArn, executionRoleArn, networkMode, containerDefinitions, volumes, placementConstraints, requiresCompatibilities, cpu, memory, tags, pidMode, ipcMode, proxyConfiguration, inferenceAccelerators

Unknown parameter in input: "status", must be one of: family, taskRoleArn, executionRoleArn, networkMode, containerDefinitions, volumes, placementConstraints, requiresCompatibilities, cpu, memory, tags, pidMode, ipcMode, proxyConfiguration, inferenceAccelerators

Delete each of the referenced fields from the task-definition.json file such as ‘compatibilities’

Commit and Push!

Successful bitbucket to AWS deployment

Fingers crossed that it successfully pushes and deploys your new image, if you view the ‘Tasks’ tab of your ECS cluster you should notice one task shut down and a new one get provisioned.

 

Previous section: Setup AWS Infrastructure

Next section: Appendix

For more information on this topic, to ask questions, or to find out how we might be able to help you.

Please feel free to email: info@citywebconsultants.co.uk

 

 

Want to join our team?

Copyright © City Web Consultants Ltd. 2017. All Rights Reserved
Company number: 27234161

Want to start something?

Fantastic! We'd love to hear from you, whethere it's a pitch, an idea or just saying hello!

Feel free to get in touch.

 

Drop us an email?

info@citywebconsultants.co.uk

 

Or give us a call?

+44 (0) 191 691 1296

 

Playing hard to get? We'll contact you