Sign inSign up

smithmicro/ecs

By smithmicro

Updated over 4 years ago

Image
0

1.3K

smithmicro/ecs repository overview

ECS

A handy Elastic Container Services Toolkit in a Docker Image

Functions

FunctionAction
create-clusterCreate an ECS Cluster with EC2 instances
create-elbCreate an Elastic Load Balancer for HTTPS
create-fargateCreate a Fargate Cluster
create-rolesCreate required ECS Roles for the Parameter Store
destroy-clusterDestroys a cluster - proceed with caution
downPerform a Dompose Down
get-login-passwordGet ECR login password for username AWS
loginOutput a string to log into Elastic Container Registry (ECS)
psList Containers running in the cluster
schedule-taskCreate an ECS Task that runs on a CRON schedule
upPerform a Compose Up
updatePerform a Compose Down/Up
up-elbPerform a Compose Up using an ELB
update-elbPerform a Compose Down/Up using an ELB

Example

To deploy a docker-compose.yml file in the current working directory into an existing cluster, run:

docker run \
    -v $PWD:/deploy \
    --env CLUSTER=my-cluster \
    --env PROJECT_NAME=my-service-and-task-name \
    --env AWS_DEFAULT_REGION=us-west-1 \
    --env AWS_ACCESS_KEY_ID=ABCDEFG \
    --env AWS_SECRET_ACCESS_KEY=HIJKLMNOP \
    smithmicro/ecs:latest up

Environment Variables

The following varaiables are used by the Docker image to perform various operations.

VariableDefaultFunctionNotes
AWS_DEFAULT_REGIONAllAWS Region (e.g. us-east-1)
AWS_ACCESS_KEY_IDAllAWS Access Key
AWS_SECRET_ACCESS_KEYAllAWS Secret Key
PROJECT_NAMEcreate-elb, schedule-task
CONTAINER_NAMEup-elb, update-elb
CERTIFICATE_ARNcreate-elb
SECURITY_GROUP_HTTPScreate-elbAWS Secuirty group that allows ports 443/tcp from amywhere
SECURITY_GROUPcreate-clusterAWS Secuirty group that allows ports 80/tcp from anywhere
KEY_NAMEcreate-clusterAWS Security Key Pair .pem file (do not specify the .pem extension)
INSTANCE_TYPEt3.smallcreate-cluster
VPC_IDcreate-elb, create-cluster
CLUSTERcreate-elb, create-cluster, schedule-task, up(any), downName that appears in ECS Console
COMPOSEdocker-compose.ymlschedule-task, up, update, up-elb, update-elb
TARGET_GROUP_ARNup-elb, update-elb
CONTAINER_PORTup-elb, update-elbPort inside the Container to connect to ELB
SCHEDULE_HOUR0schedule-taskHour (UTC) to run the job daily. Use CRON_EXPRESSION if you want to customize further.
CRON_EXPRESSIONcron(0 0 * * ? *)schedule-taskCRON Expression for ECS Task - Default: Daily at midnight UTC

Scheduling Tasks

In order to use the schedule-task feature, you will need to create the ecsEventsRole role. Run the following command:

docker run \
    --env AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
    --env AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
    --env AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
    smithmicro/ecs:latest create-roles

SSM Parameter Store support

This image supports setting secrets in a ecs-param.yml file in the same format supported by ecs-cli. There are only two steps:

  1. Create the requried ecsTaskExecutionRole Role to support Parameter Store, ECR and CLoudWatch access.
docker run \
    --env AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
    --env AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
    --env AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
    smithmicro/ecs:latest create-roles
  1. Create a ecs-parans.yml file in the same directory as docker-compose.yml:
version: 1
task_definition:
  task_execution_role: ecsTaskExecutionRole
  services:
    paramstore-test:
      secrets:
        - value_from: NAME_OF_SECRET_IN_PARAMETER_STORE
          name: NAME_OF_SECRET_IN_CONTAINER
        - value_from: MY_APP_PGPASSWORD
          name: PGPASSWORD

The next time you run update, this file will be picked up and used automatically.

ECR Login Example

You can use the ecs-cli command directly to issue log into AWS ECS, but if you don't want the dependencies of the ecs-cli, you can also this operation with smithmicro/ecs.

Example:

ECR_PASSWORD=$(docker run \
    --env AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
    --env AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
    --env AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
    smithmicro/ecs:latest get-login-password)

ACCOUNT_ID=<your account>

echo -n $ECR_PASSWORD | docker login -u AWS --password-stdin https://$ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

Tag summary

Content type

Image

Digest

Size

137.6 MB

Last updated

over 4 years ago

docker pull smithmicro/ecs