demitas

package module
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 11 Imported by: ? 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

demitas

Wrapper for ecspresso that creates task definitions at run time.

Usage

demitas - Wrapper for ecspresso that creates task definitions at run time.

  Flags:
       --version         Displays the program version string.
    -h --help            Displays help with available flag, subcommand, and positional value parameters.
       --ecsp-cmd        ecspresso command path. (default: ecspresso)
    -d --conf-dir        Configuration file base directory. (default: ~/.demitas)
    -p --profile         Configuration profile directory.
    -E --ecsp-conf-src   ecspresso config source path. (default: ~/.demitas/ecspresso.yml)
    -S --svr-def-src     ECS service definition source path. (default: ~/.demitas/ecs-service-def.jsonnet)
    -T --task-def-src    ECS task definition source path. (default: ~/.demitas/ecs-task-def.jsonnet)
    -C --cont-def-src    ECS container definition source path. (default: ~/.demitas/ecs-container-def.jsonnet)
    -e --ecsp-conf-ovr   JSON/YAML string that overrides ecspresso config source.
    -s --svr-def-ovr     JSON/YAML string that overrides ECS service definition source.
    -t --task-def-ovr    JSON/YAML string that overrides ECS task definition source.
    -c --cont-def-ovr    JSON/YAML string that overrides ECS container definition source.
    -n --print-conf      Display configs only.

  Trailing Arguments:
    Arguments after "--" is passed to "ecspresso run".
    e.g. demitas -c 'image: ...' -- --color --wait-until=running --debug
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Environment Variables:
    DMTS_CONF_DIR (--conf-dir)   Configuration file base directory.  (default: ~/.demitas)
    DMTS_PROFILE  (--profile)    Configuration profile directory.
                                 If "database" is set, configs file will be read from "$DMTS_CONF_DIR/database/..."

Installation

NOTE: Requires ecspresso.

brew tap winebarrel/ecs-exec-pf
brew install ecs-exec-pf
brew tap winebarrel/demitas
brew install demitas

Example Configurations

~/.demitas/ecspresso.yml
region: ap-northeast-1
cluster: my-cluster
service: my-service
~/.demitas/ecs-service-def.jsonnet
{
  launchType: 'FARGATE',
  networkConfiguration: {
    awsvpcConfiguration: {
      assignPublicIp: 'DISABLED',
      securityGroups: ['sg-xxx'],
      subnets: ['subnet-xxx'],
    },
  },
  enableExecuteCommand: true,
  //capacityProviderStrategy: [
  //  {
  //    capacityProvider: 'FARGATE_SPOT',
  //    weight: 1,
  //  },
  //],
}
~/.demitas/ecs-task-def.jsonnet
{
  family: 'my-oneshot-task',
  cpu: '256',
  memory: '512',
  networkMode: 'awsvpc',
  taskRoleArn: 'arn:aws:iam::xxx:role/my-role',
  executionRoleArn: 'arn:aws:iam::xxx:role/my-exec-role',
  requiresCompatibilities: ['FARGATE'],
}
~/.demitas/ecs-container-def.jsonnet
{
  name: 'oneshot',
  cpu: 0,
  essential: true,
  logConfiguration: {
    logDriver: 'awslogs',
    options: {
      'awslogs-group': '/ecs/oneshot',
      'awslogs-region': 'ap-northeast-1',
      'awslogs-stream-prefix': 'ecs',
    },
  },
}

Execution Example

$ demitas \
  -e 'service: my-service2' \
  -s 'networkConfiguration: {awsvpcConfiguration: {securityGroups: [sg-zzz]}}' \
  -c '{image: "public.ecr.aws/runecast/busybox:1.33.1", command: [echo, hello]}' \
  -- --dry-run

2021/10/10 22:33:44 my-service2/my-cluster Running task
2021/10/10 22:33:44 my-service2/my-cluster task definition:
{
  "containerDefinitions": [
    {
      "command": [
        "echo",
        "hello"
      ],
      "cpu": 0,
      "essential": true,
      "image": "public.ecr.aws/runecast/busybox:1.33.1",
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/busybox",
          "awslogs-region": "ap-northeast-1",
          "awslogs-stream-prefix": "ecs"
        }
      },
      "name": "oneshot"
    }
  ],
  "cpu": "256",
  "executionRoleArn": "arn:aws:iam::xxx:role/my-role",
  "family": "my-oneshot-task",
  "memory": "512",
  "networkMode": "awsvpc",
  "requiresCompatibilities": [
    "FARGATE"
  ],
  "taskRoleArn": "arn:aws:iam::xxx:role/my-exec-role",
}
2021/10/10 22:33:44 my-service2/my-cluster DRY RUN OK
Port forwarding

NOTE: Please install ecs-exec-pf in advance.

$ demitas-pf
Usage: demitas-pf [-p PROFILE] [-c CLUSTER] -h REMOTE_HOST -r REMOTE_PORT -l LOCAL_PORT
$ demitas-pf -p my-profile -h my-db -r 5432 -l 15432
Start ECS task for port forwarding...
ECS task is running: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Start port forwarding...

Starting session with SessionId: user-xxxxxxxxxxxxxxxxx
Port 15432 opened for sessionId user-xxxxxxxxxxxxxxxxx.
Waiting for connections...
$ nc -vz localhost 15432
Connection to localhost port 15432 [tcp/*] succeeded!
ECS Exec with new container
$ demitas-exec -p pool-app-stg-db
Start ECS task...
ECS task is running: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.


Starting session with SessionId: ecs-execute-command-xxxxxxxxxxxxxxxxx
root@ip-10-10-10-10:/#

Documentation

Index

Constants

View Source
const (
	ContainerDefinitionName = "ecs-container-def.json"
)
View Source
const (
	EcspressoConfigName = "ecspresso.yml"
)
View Source
const (
	ServiceDefinitionName = "ecs-service-def.json"
)
View Source
const (
	TaskDefinitionName = "ecs-task-def.json"
)

Variables

This section is empty.

Functions

func RunTask

func RunTask(opts *RunOptions, ecsConf *EcspressoConfig, svrDef *ServiceDefinition, taskDef *TaskDefinition) (err error)

Types

type BuildOptions

type BuildOptions struct {
	EcspressoConfigSrc       string
	ServiceDefSrc            string
	TaskDefSrc               string
	ContainerDefSrc          string
	EcspressoConfigOverrides []byte
	ServiceDefOverrides      []byte
	TaskDefOverrides         []byte
	ContainerDefOverrides    []byte
}

type ContainerDefinition

type ContainerDefinition struct {
	Content []byte
}

func BuildContainerDefinition

func BuildContainerDefinition(path string, taskDefPath string, overrides []byte) (*ContainerDefinition, error)

func NewContainerDefinition

func NewContainerDefinition(path string, taskDefPath string) (*ContainerDefinition, error)

func (*ContainerDefinition) Patch

func (containerDef *ContainerDefinition) Patch(overrides []byte) error

type EcspressoConfig

type EcspressoConfig struct {
	Content []byte
}

func BuildEcspressoConfig

func BuildEcspressoConfig(path string, overrides []byte) (*EcspressoConfig, error)

func NewEcspressoConfig

func NewEcspressoConfig(path string) (*EcspressoConfig, error)

func (*EcspressoConfig) Patch

func (ecsConf *EcspressoConfig) Patch(overrides []byte) error

func (*EcspressoConfig) Print

func (ecsConf *EcspressoConfig) Print()

type RunOptions

type RunOptions struct {
	EcspressoPath    string
	EcspressoOptions []string
	PrintConfig      bool
}

type Runner

type Runner struct {
	*RunOptions
}

type ServiceDefinition

type ServiceDefinition struct {
	Content []byte
}

func BuildServiceDefinition

func BuildServiceDefinition(path string, overrides []byte) (*ServiceDefinition, error)

func NewServiceDefinition

func NewServiceDefinition(path string) (*ServiceDefinition, error)

func (*ServiceDefinition) Patch

func (svrDef *ServiceDefinition) Patch(overrides []byte) error

func (*ServiceDefinition) Print

func (svrDef *ServiceDefinition) Print()

type TaskDefinition

type TaskDefinition struct {
	Content []byte
}

func BuildTaskDefinition

func BuildTaskDefinition(path string, overrides []byte, containerDef *ContainerDefinition) (*TaskDefinition, error)

func NewTaskDefinition

func NewTaskDefinition(path string) (*TaskDefinition, error)

func (*TaskDefinition) Patch

func (taskDef *TaskDefinition) Patch(overrides []byte, containerDef *ContainerDefinition) error

func (*TaskDefinition) Print

func (taskDef *TaskDefinition) Print()

Directories

Path Synopsis
cmd
demitas command

Jump to

Keyboard shortcuts

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