Skip to content

Assignment 9

Merritt Lawrenson edited this page Mar 8, 2017 · 23 revisions

Assignment 9 - Deploy a Service to Elastic Container Service (ECS)

Prerequisites

  • Student has Docker installed locally
  • Student has Github account
  • Student has an AWS account
  • Student has completed Assignment 8

Assignment Outline

Concepts Introduced

  • Infrastructure as Code
  • CloudFormation
  • Elastic Container Service
  • Auto Scaling Groups

Goals

  • Stand up a CloudFormation stack
  • Build a Docker container image via Travis
  • Deploy that container image to CloudFormation

Step 0 - Bootstrap your ECS environment

You will need to build an ECS CloudFormation instance that will host the results of Steps 1+.

  • Fork the HackOregon AWS Infrastructure and follow the steps in Assignment 8

  • Update services/homeless-service/service.yaml with your own Docker Hub user/repo (line 62).

  • Upload your modified service.yaml to your own S3 bucket and make sure service.yaml is set to public.

  • Update master.yaml with your own bucket location to service.yaml (line 76).

  • Update master.yaml with your S3 bucket name (line 82)

  • Create /integration folder in your S3 bucket and copy project_config.py there. Make sure project_config.py is private!

  • Open the AWS console. Go to Services > EC2 > Key Pairs (it's under Network & Security in the list on the left).

  • Click "Create Key Pair" and give it a name. It should download a .pem file.

  • Now, create your stack. Services > CloudFormation > Create Stack. Choose a template, upload a template to S3. Use your updated master.yaml. Click next.

  • On the next screen, give your stack a name. Under Parameters, enter the name of the keypair you created earlier under "Key Pair Name". Click next.

  • This screen doesn't need any input or changes. Click next.

  • Make sure you've checked the box labelled "I acknowledge that AWS CloudFormation might create IAM resources with custom names." Click create.

  • Switch the bottom half of the window to the Events tab to watch your stack get created and find any error messages.

Step 1 - Fork the HackOregon Backend Services Pattern

Step 2 - Read through the steps in the readme

Step 3 - Make sure you've got a local configuration file

  • Ensure you've got the project_config.py file

Step 4 - Build your docker project

  • Inspect build-proj.sh - understand what it does
  • Execute build-proj.sh

Step 5 - Start your docker project

  • Inspect start-proj.sh - understand what it does
  • Execute start-proj.sh
  • Ensure your swagger interfaces definitions comes up http://localhost:8000/homeless

Step 6 - Hook up your repo and configure travis-ci.org

  • Enable the assignment9 repo in Travis and add the following ENVIRONMENT variables:
 DOCKER_REPO            # Your docker repository
 DOCKER_IMAGE           # endpoint-service
 DOCKER_USERNAME        # Your Docker Repository user name
 DOCKER_PASSWORD        # Your Docker Repository password
 ECS_CLUSTER            # The name of your ECS cluster
 ECS_SERVICE_NAME       # The name of the ECS service your deploying to
 DEPLOY_TARGET          # The deployment environment. Valid values: integration,production
 PROJ_SETTINGS_DIR      # the directory where we will place configuration files(s)
 CONFIG_BUCKET          # The s3 configuration bucket
 AWS_DEFAULT_REGION     # THE AWS region where your cluster is located
 AWS_ACCESS_KEY_ID      # The service deployer keyid for your service
 AWS_SECRET_ACCESS_KEY  # The service deployer secret key for your service

IMPORTANT: Make sure that you don't store AWS or Docker repository credentials in your github repo or expose them in travis

Step 10 - Push some code and watch it build and deploy

  • Make a trivial change and watch Travis build and deploy

Step 11 - confirm your deployment went as planned

  • find your ALB URL in the output of the ALB Cloudformation stack and browse to see if the /homeless/ endpoint is responding
  • look in ECS Container Service > cluster > homeless-service > task - which container image is your cluster using for the homeless-service task?

Step 12 - Cleanup

  • IMPORTANT: Tear down your ECS cluster, by deleting the master stack
Clone this wiki locally