Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
/ deployables Public archive

🗑️ a basket of deploy scripts

Notifications You must be signed in to change notification settings

firstlookmedia/deployables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deployables

A basket of deploy scripts.

Initially developed for building docker images and deploying updated task definitions to ECS via CircleCI.

Also supports deploying scheduled lambda function.

ECS Examples

Standard deploy for develop and master branches and release tags
machine:
   environment:
        DEPLOY_APP_NAME: "myapp"
        DEPLOY_ECR_HOST: "1234567890.dkr.ecr.us-east-1.amazonaws.com"
        DEPLOY_ECR_ACCOUNT: "1234567890"
        DEPLOY_DOCKER_LOCAL_TAG: "myapp:local"
        DEPLOY_AWS_ROLE: "ops-admin"
        DEPLOY_TASK_DEF_TEMPLATE: "./taskdefs/myapp.txt"
        DEPLOY_SHA1: "${CIRCLE_SHA1}"

dependencies:
    override:
        - npm install -g https://github.com/firstlookmedia/deployables

deployment:

    develop:
        branch: develop
        commands:
            - $( npm bin )/deployables docker_build
            - >
                DEPLOY_AWS_ACCOUNT="321987654"
                $( npm bin )/deployables ecs_deploy


    staging:
        branch: master
        commands:
            - $( npm bin )/deployables docker_build
            - >
                DEPLOY_AWS_ACCOUNT="9876543210"
                DEPLOY_PUSH_SECONDARY_TAG="master"
                $( npm bin )/deployables ecs_deploy

    release:
        tag: /release-.*/
        commands:
            - >
                DEPLOY_AWS_ACCOUNT="654987321"
                DEPLOY_RETAG_AND_PUSH=1
                DEPLOY_RETAG_REMOTE_TAG="master"
                DEPLOY_RETAG_TARGET_TAG="release"
                $( npm bin )/deployables ecs_deploy

Deploy one image to multiple service targets

This version uses DEPLOY_ECS_FAMILIES to specify multiple child tasks definitions.

machine:
   environment:
        DEPLOY_APP_NAME: "myapp"
        DEPLOY_ECS_FAMILIES: "foo bar"
        DEPLOY_ECR_HOST: "1234567890.dkr.ecr.us-east-1.amazonaws.com"
        DEPLOY_ECR_ACCOUNT: "1234567890"
        DEPLOY_SHA1: "${CIRCLE_SHA1}"

dependencies:
    override:
        - npm install -g https://github.com/firstlookmedia/deployables

deployment:

    develop:
        branch: develop
        commands:
            - $( npm bin )/deployables docker_build
            - >
                DEPLOY_DEBUG=1
                DEPLOY_AWS_ACCOUNT="321987654"
                DEPLOY_PUSH_SECONDARY_TAG="master"
                DEPLOY_TASK_DEF_TEMPLATE="./taskdefs/myapp-master-FAMILY.txt"
                $( npm bin )/deployables ecs_deploy

Note: The -FAMILY- in DEPLOY_TASK_DEF_TEMPLATE will be replaced by the values of DEPLOY_ECS_FAMILIES.

In other words, the example above will load ./taskdefs/myapp-master-foo.txt and ./taskdefs/myapp-master-bar.txt.

Lambda Example

Basic lambda deploy for develop and master branches
machine:
    environment:
        DEPLOY_LAMBDA_FUNCTION_NAME: "AwesomeLambdaFunction"
        DEPLOY_LAMBDA_FUNCTION_DESCRIPTION: "Do Something Awesome"
        DEPLOY_LAMBDA_FUNCTION_ROLE: "lambda_role"
        DEPLOY_LAMBDA_FUNCTION_ENV_TEMPLATE: "./environment.txt"
        DEPLOY_LAMBDA_EVENT_RULE: "rate(5 minutes)"

[...]

deployment:

    develop:
        branch: develop
        commands:
            - >
                DEPLOY_AWS_ACCOUNT="321987654"
                $( npm bin )/deployables deploy_lambda


    staging:
        branch: master
        commands:
            - >
                DEPLOY_AWS_ACCOUNT="9876543210"
                $( npm bin )/deployables deploy_lambda

Public Functions

docker_build

  • Uses DEPLOY_DOCKERFILE and DEPLOY_DOCKER_LOCAL_TAG to call docker build ...

ecs_deploy

  • Used for tagging docker images and deploying updated ECS task definitions

deploy_lambda

  • Used for deploying lambda functions

Environment Variables Reference

Global Variables

DEPLOY_AWS_ACCOUNT
AWS account number used for deploy, e.g. "123456789"
DEPLOY_AWS_CONFIG
Path to aws config file for appending profile info, default "~/.aws/config"
DEPLOY_AWS_PROFILE
AWS profile name used to make awscli calls, default "deployables"
DEPLOY_AWS_REGION
AWS region used for deploys, default "us-east-1"
DEPLOY_AWS_ROLE
Pre-existing AWS role used for deploys, default "ops-admin"
DEPLOY_AWS_SOURCE_PROFILE:
`source_profile` for `DEPLOY_AWS_PROFILE`, default "default"
DEPLOY_DEBUG
Enable verbose output of scripts using bash's `set -x`, e.g. "1"
DEPLOY_GITHUB_MACHINE_USER_KEY_FINGERPRINT
Fingerprint of Circle SSH key to use for Github requests

ECS Variables

DEPLOY_APP_NAME
Name of the application and ECS service, e.g. "myapp"
DEPLOY_DOCKERFILE
Path to Dockerfile used by `docker_build`, default "./Dockerfile"
DEPLOY_DOCKER_LOCAL_TAG
Tag used by `docker_build` for local image, default: `$DEPLOY_APP_NAME`
DEPLOY_ECR_HOST
Hostname for ECR repository, e.g. "1234567890.dkr.ecr.us-east-1.amazonaws.com"
DEPLOY_ECR_ACCOUNT
ECR repository's AWS account number, e.g. "1234567890"
DEPLOY_ECS_CLUSTER_NAME
Name of the target ECS cluster, default `$DEPLOY_APP_NAME`
DEPLOY_ECS_FAMILIES
Used to deploy one image to multiple task definitions
DEPLOY_PUSH_SECONDARY_TAG
Tag and push the local image with a secondary tag, e.g. "master"
DEPLOY_RETAG_AND_PUSH
Pull and retag a remote image, and then deploy that tag, e.g. "1"
DEPLOY_RETAG_REMOTE_TAG
Existing remote tag pulled when using `DEPLOY_RETAG_AND_PUSH`, e.g. "master"
DEPLOY_RETAG_TARGET_TAG
New tag used when using `DEPLOY_RETAG_AND_PUSH`, e.g. "release"
DEPLOY_SHA1
Typically set to commit hash using `$CIRCLE_SHA1`, default `$( date +%s | md5 )`
DEPLOY_TASK_ROLE_ARN
IAM Role to assign to the ECS Service, e.g. "bumblebee"
DEPLOY_TASK_DEF_TEMPLATE
Path to task definition templates, e.g. `./taskdefs/myapp.txt`

ECS Task Definition Template Variables

Variables set by ecs_deploy_task() when running envsubst against DEPLOY_TASK_DEF_TEMPLATE.

DEPLOY_IMAGE_NAME
The name of the Docker image passed in to `ecs_deploy_task()`
DEPLOY_SUBFAMILY
The subfamily of the service passed in to `ecs_deploy_task()`

Lambda Variables

DEPLOY_LAMBDA_EVENT_RULE
Used to schedule a lambda function, see AWS's Schedule Expressions for Rules
DEPLOY_LAMBDA_FUNCTION_DESCRIPTION
Description of the lambda function, optional
DEPLOY_LAMBDA_FUNCTION_ENV_TEMPLATE
Path to lambda environment template, default `environment.txt`
DEPLOY_LAMBDA_FUNCTION_HANDLER
Function handler, default `index.handler`
DEPLOY_LAMBDA_FUNCTION_NAME
Function name, e.g. `AwesomeLambdaFunction`
DEPLOY_LAMBDA_FUNCTION_ROLE
Function role, e.g. `lambda_role`
DEPLOY_LAMBDA_FUNCTION_RUNTIME
Function runtime, default `nodejs4.3`
DEPLOY_LAMBDA_FUNCTION_TIMEOUT
Function timeout in seconds, default `3`
DEPLOY_LAMBDA_FUNCTION_SOURCE_DIR
Directory that contains the lambda function, default `.`