Code Monkey home page Code Monkey logo

ecs-cicd-demo's Introduction

ecs-cicd-demo

AWS ECS CI/CD Demo with Code*

Prepare your environment

Setup your github repo

git clone <this repo>
cp * <your dir>
git push <your repo>

Setup your docker runtime

Setup ECR

make sure you can login ECR

$(aws ecr get-login --no-include-email --region us-west-2)

build your images

docker build -t 211752457047.dkr.ecr.us-west-2.amazonaws.com/apidemo80:1 .
docker push 211752457047.dkr.ecr.us-west-2.amazonaws.com/apidemo80:1

Setup Task definition

In Add container step, make sure you specify the image & image tag, NOT ':latest', it Named your container, the name will be used in CodeBuild

Setup ECS cluster

Choose either Fargate or EC2

Setup ALB for ECS service

Before setup ECS service, create an ALB & target group without target group targets Setup a proper health check intervals and other timing parameters, otherwise the service update process could be very long.

Setup ECS service

Specify Task definition defined in previous step For Fargate, dynamic port mapping for ALB is not available, container port & service port should be the same, make sure you set the correct container port in DockerFIle.

Ensure ECS service works

curl <ALB entry>

Ensure ECS service update works

build a new image
#update api.py to another version
#build a new images with new tag
docker build -t 211752457047.dkr.ecr.us-west-2.amazonaws.com/apidemo80:2 .
docker push 211752457047.dkr.ecr.us-west-2.amazonaws.com/apidemo80:2
define a new task definition

update task definition with new container definition click update service and point to another task definition

Create a pipeline

Source

Choose github and follow the instructions

Build

Choose CodeBuild

For buildspec file, set use the buildspec.yml in the repo root dir. Pay attention to the variables in buildspec.yml Configure Advanced options Setup environment variables AWS_ACCOUNT_ID e.g. 211752457047 AWS_DEFAULT_REGION e.g. us-west-2 IMAGE_REPO_NAME e.g. apidemo80 CONTAINER_NAME e.g. apidemo80(you defined it in Task definition)

By CodeBuild create a role for you automatically, however this role does not have permission to access ECR. Add AmazonEC2ContainerRegistryFullAccess policy to this role manually.

Deploy

Choose Amazon ECS For image file, use imagedefinitions.json, it is defined in the buildspec.yml, in this line, printf '[{"name":"$CONTAINER_NAME","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json

Test run

It would run the pipeline automatically right after you create the pipeline. If encounter any error, refer to the error message and details for troubleshooting. After that, update the version attribute in api.py then push

ecs-cicd-demo's People

Contributors

totorochina avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.