GithubHelp home page GithubHelp logo

gregbkr / myapp-ecs Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 755 KB

ECS deployed via CloudFormation in AWS, simple helloworld built to ECR, CI/CD Pipeline

Home Page: https://greg.satoshi.tech/ecs

Shell 82.49% Dockerfile 9.04% JavaScript 8.47%
ecs codepipeline aws ecr cloudformation

myapp-ecs's Introduction

MyApp: HA container in ECS

Overview

This setup will deploy a redundant helloworld container on ECS fargate, with automatic CI/CD from AWS.

More info: you can find an overview of that setup on my blog

Infra

Infra

  • Cloud: AWS
  • ECS: container orchestrator (on 2 availability zones for redundancy)
  • ECR: container registry to store hello image
  • App: a simple hello world in Nodejs (folder hello)
  • Code source: Github
  • Deployment: CloudFormation describe all component to be deployed. One command line will setup
  • CI/CD: CodePipeline to build and deploy the container in ECS the infra and return an url to access the application.

CI/CD flow diagram

CI/CD

A simple git push from a developer in Github will launch the whole CI/CD process. Docker image will build and ECS will update to run that new image without any downtime.

Deploy

Prerequisites

Please setup on your laptop:

  • AWS cli and AWS account to deploy in eu-west-1
  • Docker and Compose
  • Github personal token with admin:repo_hook, repo rights from here

Test app on your laptop

Check the app locally:

cd hello
docker-compose up -d
curl localhost 8080

Deploy to AWS

  • Set a unique project prefix and your github token:
cd cloudformation
export CF_DEMO_ENVIRONMENT=myapp-demo-ecs   <-- please change to your prefix!
export GITHUB_TOKEN=xxxx                    <-- You token here
  • Because CodePipeline needs to know the ECS ARN, and ECS needs CodePipeline to build the image to run an ECS task, we are deploying the infra in 2 steps

Step 1

  • Deploy infra with a dummy ECS Service Arn=REPLACE_AFTER_ECS_DEPLOYED
./deploy.sh ${CF_DEMO_ENVIRONMENT} [GH username] [GH repo] [GH branch] [GH token] [ECS Service Arn]

Ex:
./deploy.sh ${CF_DEMO_ENVIRONMENT} gregbkr myapp-ecs master ${GITHUB_TOKEN} REPLACE_AFTER_ECS_DEPLOYED
  • Wait for the script to complete. Check that image has been build in ERC, and that ECS service is running.

  • If it takes more than 20 minutes, check cloudformation waiting components in event. ECS may waiting for the container to be up. Please check that the build was successful and the image present in ECR.

  • Find the ServiceArn of the ECS:

export ECS_SERVICE_ARN=$(aws cloudformation \
   describe-stacks \
   --query 'Stacks[0].Outputs[?OutputKey==`EcsServiceArn`].OutputValue' \
   --stack-name ${CF_DEMO_ENVIRONMENT})

Step 2

  • Then update the stack, it will link CodeDeploy to the Ecs Service Arn
./deploy.sh ${CF_DEMO_ENVIRONMENT} gregbkr myapp-ecs master ${GITHUB_TOKEN} ${ECS_SERVICE_ARN}

Check

  • Wait for ECS to update the tasks, and check the app:
aws cloudformation \
   describe-stacks \
   --query 'Stacks[0].Outputs[?OutputKey==`WebServiceUrl`].OutputValue' \
   --stack-name ${CF_DEMO_ENVIRONMENT}
  • See the pipeline
aws cloudformation \
   describe-stacks \
   --query 'Stacks[0].Outputs[?OutputKey==`PipelineUrl`].OutputValue' \
   --stack-name ${CF_DEMO_ENVIRONMENT}

CI/CD

  • Change the output of the hello world here: nano hello/server.js
  • Push code in github
  • Check the status of CI/CD in your browser
  • Then check again your app

Destroy all

  • Destroy all stack: ./delete-stacks.sh ${CF_DEMO_ENVIRONMENT}

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.