Git Product home page Git Product logo

go-ecs-deploy's Introduction

go-ecs-deploy

Overview

A small library to take make deploying to AWS ECS from remote systems (like CI servers) a little easier. It supports deploying both long running services attached to a load balancer as well as one-shot tasks that should run then exit.

Services

A service is specifically an ECS Service. It is expected to start and remain running indefinitely.

Oneshots

A oneshot service is expected to run and exit. It uses ECS RunTask under the hood. Oneshots are useful for running stand-alone database migration containers, or other ad-hoc one off tasks.

CLI Tool

The included CLI tool loads a config file and a template. The template file is first executed with the variables in the execution environment, then again with the specified config files. Values set in the config file will override values set in the environment.

Default templates are located in the templates/ directory, with some example config files under example/

Usage

AWS credentials must be available in the usual ways (metadata endpoint, credentials file, environment vars).

Note: the CLI tool does not yet support profiles, as the intended place to run is a CI job that most likely has env vars or an instance profile set.

Deploy a service:

Use only values in the config file:

go run src/main.go -config example/service-a/service-full.json -template templates/service.json.tpl -type service

Set some vars in the environment and the rest in a config file. This is useful for substituting runtime CI variables that change frequently.

ImageTag=sometag Image=registry/image go run src/main.go -config example/service-a/service-full.json -template templates/service.json.tpl -type service

The above commands will:

  • replace any template vars with environment variables first, then the config file.
  • register a new task definition
  • create a new service or update an existing matching service
    • If the service already exists the service template InitialCount will be changed to match the DesiredCount in ECS, so as to not undo any manual or auto scaling actions.
  • block waiting for the service to be stable

Config Examples

A full service config.

{
    "ServiceName": "service-a",
    "Cluster": "some-cluster",
    "SchedulerIAMRoleArn": "arn",
    "TaskIAMRoleArn": "arn",
    "TargetGroupArn": "arn",
    "InitialCount": 2,
    "Image": "registry/container",
    "ImageTag": "xyz",
    "MemoryReservation": 128,
    "CPUReservation": 128,
    "AWSLogsGroupName": "name",
    "AWSLogsRegion": "region",
    "Environment": [
        {
            "name": "ENVIRONMENT",
            "value": "dev"
        }
    ]
}

A partial service config that will require the missing vars to be set in the environment. Note that Image and ImageTag are omitted.

{
    "ServiceName": "service-a",
    "Cluster": "some-cluster",
    "SchedulerIAMRoleArn": "arn",
    "TaskIAMRoleArn": "arn",
    "TargetGroupArn": "arn",
    "InitialCount": 2,
    "MemoryReservation": 128,
    "CPUReservation": 128,
    "AWSLogsGroupName": "name",
    "AWSLogsRegion": "region",
    "Environment": [
        {
            "name": "ENVIRONMENT",
            "value": "dev"
        }
    ]
}

Included templates

The templates in templates/ are very opinionated and made for common workflows that we have. Specifically:

  • templates/migration.json.tpl for running a container with golang-/migrate. Note the command override.
  • templates/service.json.tpl for running services with some default settings.

Notes

Currently this tool assumes only 1 container definition per task:

  • the health check waiters only inspect the first container in the service.
  • the environment []map[string]string is only overridden for the first container def

go-ecs-deploy's People

Contributors

chtorr avatar

Watchers

Joe Leonard avatar James Cloos avatar Kyle Boorky avatar

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.