ecsdeploy

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2018 License: Apache-2.0 Imports: 50 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ECS deploy

ECS Deploy is a REST API server written in Go that can be used to deploy services on ECS from anywhere. It typically is executed as part of your deployment pipeline. Continuous Integration software (like Jenkins, CircleCI, Bitbucket or others) often don't have proper integration with ECS. This API server can be deployed on ECS and will be used to provide continuous deployment on ECS.

  • Registers services in DynamoDB
  • Creates ECR repository
  • Creates necessary IAM roles
  • Creates ALB target and listener rules
  • Creates and updates ECS Services based on JSON input
  • SAML supported Web UI to redeploy/rollback versions, add/update/delete parameters, examine event/container logs, scale, and run manual tasks
  • Support to scale out and scale in ECS Container Instances

Quick Usage

$ curl -X POST http://localhost:8080/ecs-deploy/api/v1/deploy/myservice -H 'Content-type: application/json' -H "Authorization:Bearer $TOKEN" -d \
'{
  "cluster": "mycluster",
  "servicePort": 80,
  "serviceProtocol": "HTTP",
  "desiredCount": 1,
  "containers": [
    {
      "containerName": "myservice",
      "containerImage": "nginx",
      "containerURI": "index.docker.io/nginx:alpine",
      "containerPort": 80,
      "memoryReservation": 128,
      "essential": true
    }
  ],
  "healthCheck": {
    "healthyThreshold": 3,
    "unhealthyThreshold": 3,
    "path": "/",
    "interval": 60,
    "matcher": "200,301"
  }
}'

How to install

  • Deploy the docker image as a service on ECS
    • See examples/ecs-deploy.tf for a terraform deploy script
      • This script creates an ALB with the same name as the ECS cluster
      • Adds the IAM policy from examples/iam-policy.json
      • Adds dynamodb table with history of deployments

Environment variables

AWS Specific variables:
  • AWS_REGION=region # mandatory
Authentication variables;
  • JWT_SECRET=secret # mandatory
  • DEPLOY_PASSWORD=deploy # mandatory
  • DEVELOPER_PASSWORD=developer # mandatory
Service specific variables

These will be used when deploying services

  • AWS_ACCOUNT_ENV=staging
  • PARAMSTORE_ENABLED=yes
  • PARAMSTORE_PREFIX=mycompany
  • PARAMSTORE_KMS_ARN=
  • CLOUDWATCH_LOGS_ENABLED=yes
  • CLOUDWATCH_LOGS_PREFIX=mycompany
  • LOADBALANCER_DOMAIN=mycompany.com
DynamoDB specific variables
  • DYNAMODB_TABLE=Services
SAML

SAML can be enabled using the following environment variables

To create a new key and certificate, the following openssl command can be used:

openssl req -x509 -newkey rsa:2048 -keyout myservice.key -out myservice.cert -days 3650 -nodes -subj "/CN=myservice.mycompany.com"

Web UI

  • PARAMSTORE_ASSUME_ROLE=arn # arn to assume when querying the parameter store

License

Copyright 2017 in4it BVBA

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ALB

type ALB struct {
	// contains filtered or unexported fields
}

ALB struct

type API

type API struct {
	// contains filtered or unexported fields
}

API struct

func (*API) Launch

func (a *API) Launch() error

type AutoScaling

type AutoScaling struct {
}

ECR struct

type CloudWatch

type CloudWatch struct{}

type CloudWatchLog

type CloudWatchLog struct {
	NextBackwardToken string               `json:"nextBackwardToken"`
	NextForwardToken  string               `json:"nextForwardToken"`
	LogEvents         []CloudWatchLogEvent `json:"logEvents"`
}

type CloudWatchLogEvent

type CloudWatchLogEvent struct {
	IngestionTime time.Time `json:"ingestionTime"`
	Message       string    `json:"message"`
	Timestamp     time.Time `json:"timestamp"`
}

type ContainerDefinition

type ContainerDefinition struct {
	Name      string `json:"name"`
	Essential bool   `json:"essential"`
}

type ContainerInstance

type ContainerInstance struct {
	ContainerInstanceArn string
	Ec2InstanceId        string
	PendingTasksCount    int64
	RegisteredAt         time.Time
	RegisteredResources  []ContainerInstanceResource
	RemainingResources   []ContainerInstanceResource
	RunningTasksCount    int64
	Status               string
	Version              int64
}

containerInstance

type ContainerInstanceResource

type ContainerInstanceResource struct {
	DoubleValue    float64  `json:"doubleValue"`
	IntegerValue   int64    `json:"integerValue"`
	Name           string   `json:"name"`
	StringSetValue []string `json:"stringSetValue"`
	Type           string   `json:"type"`
}

type Controller

type Controller struct {
}

Controller struct

func (*Controller) Bootstrap

func (c *Controller) Bootstrap(b *Flags) error

func (*Controller) DeleteCluster

func (c *Controller) DeleteCluster(b *Flags) error

func (*Controller) Resume

func (c *Controller) Resume() error

func (*Controller) SetDeployDefaults

func (c *Controller) SetDeployDefaults(d *Deploy)

type Deploy

type Deploy struct {
	Cluster               string                      `json:"cluster" binding:"required"`
	ServiceName           string                      `json:"serviceName"`
	ServicePort           int64                       `json:"servicePort"`
	ServiceProtocol       string                      `json:"serviceProtocol" binding:"required"`
	DesiredCount          int64                       `json:"desiredCount" binding:"required"`
	MinimumHealthyPercent int64                       `json:"minimumHealthyPercent"`
	MaximumPercent        int64                       `json:"maximumPercent"`
	Containers            []*DeployContainer          `json:"containers" binding:"required,dive"`
	HealthCheck           DeployHealthCheck           `json:"healthCheck"`
	RuleConditions        []*DeployRuleConditions     `json:"ruleConditions`
	NetworkMode           string                      `json:"networkMode"`
	NetworkConfiguration  DeployNetworkConfiguration  `json:"networkConfiguration"`
	PlacementConstraints  []DeployPlacementConstraint `json:"placementConstraints"`
	LaunchType            string                      `json:"launchType"`
	DeregistrationDelay   int64                       `json:"deregistrationDelay"`
	Stickiness            DeployStickiness            `json:"stickiness"`
}

type DeployContainer

type DeployContainer struct {
	ContainerName     string    `json:"containerName" binding:"required"`
	ContainerTag      string    `json:"containerTag" binding:"required"`
	ContainerPort     int64     `json:"containerPort"`
	ContainerCommand  []*string `json:"containerCommand"`
	ContainerImage    string    `json:"containerImage`
	ContainerURI      string    `json:"containerURI"`
	Essential         bool      `json:"essential"`
	Memory            int64     `json:"memory"`
	MemoryReservation int64     `json:"memoryReservation"`
	CPU               int64     `json:"cpu"`
	CPUReservation    int64     `json:"cpuReservation"`
}

type DeployHealthCheck

type DeployHealthCheck struct {
	HealthyThreshold   int64  `json:"healthyThreshold"`
	UnhealthyThreshold int64  `json:"unhealthyThreshold"`
	Path               string `json:"path"`
	Port               string `json:"port"`
	Protocol           string `json:"protocol"`
	Interval           int64  `json:"interval"`
	Matcher            string `json:"matcher"`
	Timeout            int64  `json:"timeout"`
	GracePeriodSeconds int64  `json:"gracePeriodSeconds"`
}

type DeployNetworkConfiguration

type DeployNetworkConfiguration struct {
	AssignPublicIp string   `json:"assignPublicIp"`
	SecurityGroups []string `json:"securityGroups"`
	Subnets        []string `json:"subnets"`
}

type DeployPlacementConstraint

type DeployPlacementConstraint struct {
	Expression string `json:"expression"`
	Type       string `json:"type"`
}

type DeployResult

type DeployResult struct {
	ServiceName       string    `json:"serviceName"`
	ClusterName       string    `json:"clusterName"`
	TaskDefinitionArn string    `json:"taskDefinitionArn"`
	Status            string    `json:"status"`
	DeployError       string    `json:"deployError"`
	DeploymentTime    time.Time `json:"deploymentTime"`
}

type DeployRuleConditions

type DeployRuleConditions struct {
	Listeners   []string `json:"listeners"`
	PathPattern string   `json:"pathPattern"`
	Hostname    string   `json:"hostname"`
}

type DeployServiceParameter

type DeployServiceParameter struct {
	Name      string `json:"name" binding:"required"`
	Value     string `json:"value" binding:"required"`
	Encrypted bool   `json:"encrypted"`
}

type DeployServices

type DeployServices struct {
	Services []Deploy `json:"services" binding:"required"`
}

deploy binding from JSON

type DeployStickiness

type DeployStickiness struct {
	Enabled  bool  `json:"enabled"`
	Duration int64 `json:"duration"`
}

type DynamoCluster

type DynamoCluster struct {
	Identifier         string    `dynamo:"ServiceName,hash"`
	Time               time.Time `dynamo:"Time,range"`
	ContainerInstances []DynamoClusterContainerInstance
	ScalingOperation   DynamoClusterScalingOperation
	ExpirationTime     time.Time
}

dynamo cluster struct

type DynamoClusterContainerInstance

type DynamoClusterContainerInstance struct {
	ClusterName         string
	ContainerInstanceId string
	FreeMemory          int64
	FreeCpu             int64
	Status              string
}

type DynamoClusterScalingOperation

type DynamoClusterScalingOperation struct {
	ClusterName string
	Action      string
}

type DynamoDeployment

type DynamoDeployment struct {
	ServiceName       string    `dynamo:"ServiceName,hash"`
	Time              time.Time `dynamo:"Time,range" index:"DayIndex,range" index:"MonthIndex,range"`
	Day               string    `index:"DayIndex,hash"`
	Month             string    `index:"MonthIndex,hash"`
	Status            string
	DeployError       string
	Tag               string
	Scaling           DynamoDeploymentScaling
	ManualTasksArns   []string
	TaskDefinitionArn *string
	DeployData        *Deploy
	Version           int64
}

type DynamoDeploymentScaling

type DynamoDeploymentScaling struct {
	DesiredCount int64
}

type DynamoServices

type DynamoServices struct {
	ServiceName string `dynamo:"ServiceName,hash"`
	Services    []*DynamoServicesElement
	Time        string `dynamo:"Time,range"`
	Version     int64
	ApiVersion  string
}

dynamo services struct

type DynamoServicesElement

type DynamoServicesElement struct {
	C                 string
	S                 string
	MemoryLimit       int64 `dynamo:"ML"`
	MemoryReservation int64 `dynamo:"MR"`
	CpuLimit          int64 `dynamo:"CL"`
	CpuReservation    int64 `dynamo:"CR"`
	L                 []string
}

type ECR

type ECR struct {
	// contains filtered or unexported fields
}

ECR struct

type ECS

type ECS struct {
	// contains filtered or unexported fields
}

ECS struct

type EcsVersionInfo

type EcsVersionInfo struct {
	AgentHash     string `json:"agentHash"`
	AgentVersion  string `json:"agentVersion"`
	DockerVersion string `json:"dockerVersion"`
}

version info

type Export

type Export struct {
	// contains filtered or unexported fields
}

type ExportedApps

type ExportedApps map[string]string

type Flags

type Flags struct {
	Bootstrap             bool
	DisableEcsDeploy      bool
	Profile               string
	Region                string
	ClusterName           string
	Environment           string
	AlbSecurityGroups     string
	EcsSubnets            string
	CloudwatchLogsPrefix  string
	CloudwatchLogsEnabled bool
	KeyName               string
	InstanceType          string
	EcsSecurityGroups     string
	EcsMinSize            string
	EcsMaxSize            string
	EcsDesiredSize        string
	ParamstoreEnabled     bool
	ParamstoreKmsArn      string
	ParamstorePrefix      string
	LoadbalancerDomain    string
	Server                bool
	DeleteCluster         string
}

func NewFlags

func NewFlags() *Flags

type FreeInstanceResource

type FreeInstanceResource struct {
	InstanceId string
	Status     string
	FreeMemory int64
	FreeCpu    int64
}

free instance resource

type IAM

type IAM struct {
	// contains filtered or unexported fields
}

IAM struct

type ListenerRule

type ListenerRule struct {
	ListenerRuleArn string                  `json:"listenerRuleArn"`
	TargetGroupArn  string                  `json:"targetGroupArn" binding:"dive"`
	Conditions      []ListenerRuleCondition `json:"conditions" binding:"dive"`
}

type ListenerRuleCondition

type ListenerRuleCondition struct {
	Field  string `json:"field" binding:"dive"`
	Values string `json:"values" binding:"dive"`
}

type ListenerRuleExport

type ListenerRuleExport struct {
	RuleKeys RulePriority           `json:"ruleKeys" binding:"dive"`
	Rules    map[int64]ListenerRule `json:"rules" binding:"dive"`
}

type Migration

type Migration struct {
}

Migration struct

type Parameter

type Parameter struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Value   string `json:"value"`
	Version int64  `json:"version"`
}

parameter type

type Paramstore

type Paramstore struct {
	// contains filtered or unexported fields
}

Paramstore struct

func (*Paramstore) RetrieveKeys

func (p *Paramstore) RetrieveKeys() error

type RegisteredInstanceResource

type RegisteredInstanceResource struct {
	InstanceId       string
	RegisteredMemory int64
	RegisteredCpu    int64
}

registered instance resource

type RulePriority

type RulePriority []int64

func (RulePriority) Len

func (a RulePriority) Len() int

func (RulePriority) Less

func (a RulePriority) Less(i, j int) bool

func (RulePriority) Swap

func (a RulePriority) Swap(i, j int)

type RunTask

type RunTask struct {
	StartedBy          string                     `json:"startedBy"`
	ContainerOverrides []RunTaskContainerOverride `json:"containerOverrides"`
}

"Run ad-hoc task" type

type RunTaskContainerOverride

type RunTaskContainerOverride struct {
	Name    string   `json:"name"`
	Command []string `json:"command"`
}

type RunningService

type RunningService struct {
	ServiceName  string                     `json:"serviceName"`
	ClusterName  string                     `json:"clusterName"`
	RunningCount int64                      `json:"runningCount"`
	PendingCount int64                      `json:"pendingCount"`
	DesiredCount int64                      `json:"desiredCount"`
	Status       string                     `json:"status"`
	Events       []RunningServiceEvent      `json:"events"`
	Deployments  []RunningServiceDeployment `json:"deployments"`
	Tasks        []RunningTask              `json:"tasks"`
}

type RunningServiceDeployment

type RunningServiceDeployment struct {
	Status         string    `json:"status"`
	RunningCount   int64     `json:"runningCount"`
	PendingCount   int64     `json:"pendingCount"`
	DesiredCount   int64     `json:"desiredCount"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
	TaskDefinition string    `json:"taskDefinition"`
}

type RunningServiceEvent

type RunningServiceEvent struct {
	CreatedAt time.Time `json:"createdAt"`
	Id        string    `json:"id"`
	Message   string    `json:"message"`
}

type RunningTask

type RunningTask struct {
	ContainerInstanceArn string                 `json:"containerInstanceArn"`
	Containers           []RunningTaskContainer `json:"containers"`
	Cpu                  string                 `json:"cpu"`
	CreatedAt            time.Time              `json:"createdAt"`
	DesiredStatus        string                 `json:"desiredStatus"`
	ExecutionStoppedAt   time.Time              `json:"executionStoppedAt"`
	Group                string                 `json:"group"`
	LastStatus           string                 `json:"lastStatus"`
	LaunchType           string                 `json:"launchType"`
	Memory               string                 `json:"memory"`
	PullStartedAt        time.Time              `json:"pullStartedAt"`
	PullStoppedAt        time.Time              `json:"pullStoppedAt"`
	StartedAt            time.Time              `json:"startedAt"`
	StartedBy            string                 `json:"startedBy"`
	StoppedAt            time.Time              `json:"stoppedAt"`
	StoppedReason        string                 `json:"stoppedReason"`
	StoppingAt           time.Time              `json:"stoppingAt"`
	TaskArn              string                 `json:"taskArn"`
	TaskDefinitionArn    string                 `json:"taskDefinitionArn"`
	Version              int64                  `json:"version"`
}

type RunningTaskContainer

type RunningTaskContainer struct {
	ContainerArn string `json:"containerArn"`
	ExitCode     int64  `json:"exitCode"`
	LastStatus   string `json:"lastStatus"`
	Name         string `json:"name"`
	Reason       string `json:"reason"`
}

type SAML

type SAML struct {
	AllowIDPInitiated bool
	TimeFunc          func() time.Time
	// contains filtered or unexported fields
}

type SNSPayload

type SNSPayload struct {
	Message          string `json:"Message"`
	MessageId        string `json:"MessageId"`
	Signature        string `json:"Signature"`
	SignatureVersion string `json:"SignatureVersion"`
	SigningCertURL   string `json:"SigningCertURL"`
	SubscribeURL     string `json:"SubscribeURL"`
	Subject          string `json:"Subject"`
	Timestamp        string `json:"Timestamp"`
	Token            string `json:"Token"`
	TopicArn         string `json:"TopicArn"`
	Type             string `json:"Type" binding:"required"`
	UnsubscribeURL   string `json:"UnsubscribeURL"`
}

SNS payload

type SNSPayloadEcs

type SNSPayloadEcs struct {
	Version    string              `json:"version"`
	Id         string              `json:"id"`
	DetailType string              `json:"detail-type" binding:"required"`
	Source     string              `json:"source"`
	Account    string              `json:"account"`
	Time       string              `json:"time"`
	Region     string              `json:"region"`
	Resources  []string            `json:"resources"`
	Detail     SNSPayloadEcsDetail `json:"detail"`
}

ECS SNS Event

type SNSPayloadEcsDetail

type SNSPayloadEcsDetail struct {
	ClusterArn           string                      `json:"clusterArn"`
	ContainerInstanceArn string                      `json:"containerInstanceArn"`
	Ec2InstanceId        string                      `json:"ec2InstanceId"`
	RegisteredResources  []ContainerInstanceResource `json:"registeredResources"`
	RemainingResources   []ContainerInstanceResource `json:"remainingResources"`
	Status               string                      `json:"status"`
	Version              int64                       `json:"version"`
	VersionInfo          EcsVersionInfo              `json:"versionInfo"`
	UpdatedAt            string                      `json:"updatedAt"`
	RegisteredAt         string                      `json:"registeredAt"`
}

type SNSPayloadGeneric

type SNSPayloadGeneric struct {
	Version    string `json:"version"`
	Id         string `json:"id"`
	DetailType string `json:"detail-type" binding:"required"`
}

generic payload (to check detail type)

type SNSPayloadLifecycle

type SNSPayloadLifecycle struct {
	Version    string                    `json:"version"`
	Id         string                    `json:"id"`
	DetailType string                    `json:"detail-type" binding:"required"`
	Source     string                    `json:"source"`
	Account    string                    `json:"account"`
	Time       string                    `json:"time"`
	Region     string                    `json:"region"`
	Resources  []string                  `json:"resources"`
	Detail     SNSPayloadLifecycleDetail `json:"detail"`
}

lifecycle event

type SNSPayloadLifecycleDetail

type SNSPayloadLifecycleDetail struct {
	LifecycleActionToken string `json:"LifecycleActionToken"`
	AutoScalingGroupName string `json:"AutoScalingGroupName"`
	LifecycleHookName    string `json:"LifecycleHookName"`
	EC2InstanceId        string `json:"EC2InstanceId"`
	LifecycleTransition  string `json:"LifecycleTransition"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

type ServiceVersion

type ServiceVersion struct {
	ImageName  string    `json:"imageName"`
	Tag        string    `json:"tag"`
	ImageId    string    `json:"imageId"`
	LastDeploy time.Time `json:"lastDeploy"`
}

type TaskDefinition

type TaskDefinition struct {
	Family               string                `json:"family"`
	Revision             int64                 `json:"revision"`
	ExecutionRoleArn     string                `json:"executionRole"`
	ContainerDefinitions []ContainerDefinition `json:"containerDefinitions"`
}

Task definition and Container definition

Directories

Path Synopsis
cmd
ecs-client command
ecs-deploy command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL