ecschedule

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 24 Imported by: 0

README

ecschedule

Test Status MIT License GoDoc

ecschedule is a tool to manage ECS Scheduled Tasks.

Synopsis

% ecschedule [dump|apply|run|diff] -conf ecschedule.yaml -rule $ruleName

Description

The ecschedule manages ECS Schedule tasks using a YAML configuration file like following.

region: us-east-1
cluster: clusterName
rules:
- name: taskName1
  description: task 1
  scheduleExpression: cron(30 15 ? * * *)
  taskDefinition: taskDefName
  containerOverrides:
  - name: containerName
    command: [subcommand1, arg]
    environment:
      HOGE: foo
      FUGA: {{ must_env `APP_FUGA` }}
- name: taskName2
  description: task2
  scheduleExpression: cron(30 16 ? * * *)
  taskDefinition: taskDefName2
  containerOverrides:
  - name: containerName2
    command: [subcommand2, arg]

Installation

% go install github.com/Songmu/ecschedule/cmd/ecschedule@latest
GitHub Actions

Action Songmu/ecschedule@main installs ecschedule binary for Linux into /usr/local/bin. This action runs install only.

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: Songmu/ecschedule@main
        with:
          version: v0.3.1
      - run: |
          ecschedule -conf ecschedule.yaml apply -all

Quick Start

dump configuration YAML
% ecschedule dump --cluster clusterName --region us-east-1 > ecschedule.yaml

edit and adjust configuration file after it.

apply new or updated rule
% ecschedule -conf ecschedule.yaml apply -rule $ruleName

Before you apply it, you can check the diff in the following way.

% ecschedule -conf ecschedule.yaml diff -rule $ruleName
run rule

Execute run subcommand when want execute arbitrary timing.

% ecschedule -conf ecschedule.yaml run -rule $ruleName

Functions

You can use following functions in the configuration file.

  • env
    • expand environment variable or using default value
    • {{ env "ENV_NAME" "DEFAULT_VALUE" }}
  • must_env
    • expand environment variable
    • {{ must_env "ENV_NAME" }}

inspired by ecspresso.

Plugins

tfstate

tfstate plugin introduces a template function tfstate.

region: us-east-1
cluster: api
role: ecsEventsRole
rules:
- name: hoge-task-name
  description: hoge description
  scheduleExpression: cron(0 0 * * ? *)
  taskDefinition: task1
  group: xxx
  platform_version: 1.4.0
  launch_type: FARGATE
  network_configuration:
    aws_vpc_configuration:
      subnets:
      - {{ tfstate `aws_subnet.private-a.id` }}
      - {{ tfstate `aws_subnet.private-c.id` }}
      security_groups:
      - {{ tfstatef `data.aws_security_group.default['%s'].id` `first` }}
      - {{ tfstatef `data.aws_security_group.default['%s'].id` `second` }}
      assign_public_ip: ENABLED
  containerOverrides:
  - name: container1
    command: ["subcmd", "argument"]
    environment:
      HOGE_ENV: {{ env "DUMMY_HOGE_ENV" "HOGEGE" }}
  dead_letter_config:
    sqs: queue1
  propagateTags: TASK_DEFINITION
plugins:
- name: tfstate
  config:
    path: testdata/terraform.tfstate    # path to tfstate file
      # or url: s3://my-bucket/terraform.tfstate

{{ tfstate "resource_type.resource_name.attr" }} will expand to an attribute value of the resource in tfstate.

{{ tfstatef "resource_type.resource_name['%s'].attr" "index" }} is similar to {{ tfstatef "resource_type.resource_name['index'].attr" }}.
This function is useful to build a resource address with environment variables.

{{ tfstatef `aws_subnet.ecs['%s'].id` (must_env `SERVICE`) }}

Author

Songmu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAWSAccountID

func GetAWSAccountID(sess *session.Session) (string, error)

GetAWSAccountID returns id

func Run

func Run(argv []string, outStream, errStream io.Writer) error

Run the ecschedule

Types

type AwsVpcConfiguration added in v0.3.0

type AwsVpcConfiguration struct {
	Subnets        []string `yaml:"subnets"`
	SecurityGroups []string `yaml:"security_groups,omitempty"`
	AssinPublicIP  string   `yaml:"assign_public_ip,omitempty"`
}

AwsVpcConfiguration represents AWS VPC configuration

type BaseConfig

type BaseConfig struct {
	Region    string `yaml:"region"`
	Cluster   string `yaml:"cluster"`
	AccountID string `yaml:"-"`
}

BaseConfig baseconfig

type Config

type Config struct {
	Role        string `yaml:"role,omitempty"`
	*BaseConfig `yaml:",inline"`
	Rules       []*Rule   `yaml:"rules"`
	Plugins     []*Plugin `yaml:"plugins,omitempty"`
	// contains filtered or unexported fields
}

Config config

func LoadConfig

func LoadConfig(r io.Reader, accountID string, confPath string) (*Config, error)

LoadConfig loads config

func (*Config) GetRuleByName

func (c *Config) GetRuleByName(name string) *Rule

GetRuleByName gets rule by name

type ContainerOverride

type ContainerOverride struct {
	Name        string            `yaml:"name"`
	Command     []string          `yaml:"command,flow"` // ,flow
	Environment map[string]string `yaml:"environment,omitempty"`
}

ContainerOverride overrids container

type DeadLetterConfig added in v0.4.0

type DeadLetterConfig struct {
	Sqs string `yaml:"sqs"`
}

A DeadLetterConfig object that contains information about a dead-letter queue configuration.

type NetworkConfiguration added in v0.3.0

type NetworkConfiguration struct {
	AwsVpcConfiguration *AwsVpcConfiguration `yaml:"aws_vpc_configuration"`
}

NetworkConfiguration represents ECS network configuration

type Plugin added in v0.5.0

type Plugin struct {
	Name   string                 `yaml:"name"`
	Config map[string]interface{} `yaml:"config"`
}

Plugin the plugin

type Rule

type Rule struct {
	Name               string `yaml:"name"`
	Description        string `yaml:"description,omitempty"`
	ScheduleExpression string `yaml:"scheduleExpression"`
	Disabled           bool   `yaml:"disabled,omitempty"` // ENABLE | DISABLE
	*Target            `yaml:",inline"`

	*BaseConfig `yaml:",inline,omitempty"`
}

Rule the rule

func (*Rule) Apply

func (r *Rule) Apply(ctx context.Context, sess *session.Session, dryRun bool) error

Apply the rule

func (*Rule) PutRuleInput

func (r *Rule) PutRuleInput() *cloudwatchevents.PutRuleInput

PutRuleInput puts rule input

func (*Rule) PutTargetsInput

func (r *Rule) PutTargetsInput() *cloudwatchevents.PutTargetsInput

PutTargetsInput puts targets input

func (*Rule) Run

func (r *Rule) Run(ctx context.Context, sess *session.Session, noWait bool) error

Run the rule

type Target

type Target struct {
	TargetID             string                `yaml:"targetId,omitempty"`
	TaskDefinition       string                `yaml:"taskDefinition"`
	TaskCount            int64                 `yaml:"taskCount,omitempty"`
	ContainerOverrides   []*ContainerOverride  `yaml:"containerOverrides,omitempty"`
	Role                 string                `yaml:"role,omitempty"`
	Group                string                `yaml:"group,omitempty"`
	LaunchType           string                `yaml:"launch_type,omitempty"`
	PlatformVersion      string                `yaml:"platform_version,omitempty"`
	NetworkConfiguration *NetworkConfiguration `yaml:"network_configuration,omitempty"`
	DeadLetterConfig     *DeadLetterConfig     `yaml:"dead_letter_config,omitempty"`
	PropagateTags        string                `yaml:"propagateTags,omitempty"`
}

Target cluster

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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