Skip to content

Assignment 7

Dan Carr edited this page Feb 28, 2017 · 1 revision

Assignment 7 - Deploy to ECS

Prerequisites

  • Student has Github account
  • Student has a DockerHub account
  • Student has an AWS account
  • Student has Docker installed.
  • Adequate bandwidth. This is not a cafe exercise.
  • Student has completed Assignment 6

Concepts Introduced

  • EC2 Container Service Deployment

Step 0 - Fork the repo

  • Delete current repo if you have it already
  • Go to this repo and Fork it
https://github.com/pdxdiver/ecs-push
  • Copy the link of your forked copy of the repo and clone it
git clone https://github.com/[YOUR_USERNAME]/ecs-push.git
cd ecs-push

Step 1 - Create Docker Hub account

  • Sign up for Docker Hub account @ https://hub.docker.com
  • Create a repository called django-web
  • Remember your repository name, username and password

Step 2 - Setup your environment files

  • Create secrets environment variables script mv secrets.template.sh secrets.sh - Change to your credentials
  • Create environment variables script mv env.template.sh env.sh - change:

DOCKER_REPO to your docker repo

DOCKER_USERNAME to your docker username

AWS_KEY_PAIR to your AWS Keypair

  • From the project root directory source your secrets config script
source ./bin/secrets.sh
  • From the project root directory run the ecs-cli config script
./bin/config-ecs-cli.sh
  • Verify that the CLI is working properly: ecs-cli --version

  • Then initiate the tests:

./bin/test-proj.sh

Step 3 - Stand up your ECS Cluster

  • From the project root directory run the ecs-cli config script ./bin/standup-ecs-cluster.sh

Wait for the script to finish:

  • Go to the AWS Console|Compute|EC2 Container Service and inspect your ECS Cluster
  • Go to the AWS Console|Management Tools|Cloudformation and check to see that your stack assign-7-hacko has been created with a status of CREATE_COMPLETE

Step 4 - Configure Travis

  1. Go to https://travis-ci.org
  2. Hook up your repo to Travis
  3. Click on + next to "My Repositories"
  4. Click on the "gear" icon next to your repository
  5. Configure environment variables

Create the following environment variables:

ECS CLUSTER replacing with assign7-hacko

DOCKER_USERNAME with your docker hub user name

DOCKER_PASSWORD with your docker hub password

AWS_ACCESS_KEY_ID with your aws access key id

AWS_SECRET_ACCESS_KEY with your aws secret access key

NOTE: Make sure that your AWS and Docker Hub credentials are not visible.

Step 5 - Deploy

Check your code in:

git add .
git commit -m 'some random ecs deploy test'
git push

Watch the travis console. When it completes swap over to your AWS Console|Compute|ECS Cluster

  • Click on the assign7-hacko cluster
  • Click on the assign7 service
  • Click on the assign7:1 task definition
  • Click on the web container
  • Click on the external link address and you should see your DRF API up and running

Step 8 Destroy your cluster

ecs-cli down --force

Clone this wiki locally