internal

package
v0.0.0-...-53b33ef Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BundlePrefix          string = "bundles/"
	ActiveBundleKeyPrefix string = "active_bundle_"
	MaxKeepBundles        int    = 100
)
View Source
const (
	FinishRetry   = true
	ContinueRetry = false
)

Variables

View Source
var CancellationError = errors.New("CancellationError")
View Source
var RetryTimeout = errors.New("RetryTimeout")

Functions

func All

func All[T any](items []T, cond func(*T) bool) bool

func Any

func Any[T any](items []T, cond func(*T) bool) bool

func AskToContinue

func AskToContinue() bool

func Contains

func Contains[T comparable](items []T, value *T) bool

func Count

func Count[T any](items []T, cond func(*T) bool) int

func Delete

func Delete[T any](items []T, cond func(*T) bool) []T

func FastDelete

func FastDelete[T any](items []T, cond func(*T) bool) []T

FastDelete Fast deletion (order is no longer guaranteed) see: https://zenn.dev/mattn/articles/31dfed3c89956d#%E9%A0%86%E3%82%92%E8%80%83%E3%81%88%E3%81%AA%E3%81%84%E5%89%8A%E9%99%A4(%E3%81%8A%E3%81%BE%E3%81%91)

func Filter

func Filter[T any](items []T, cond func(*T) bool) []T

func FirstOrDefault

func FirstOrDefault[T any](items []T, cond func(*T) bool) *T

func FirstOrNil

func FirstOrNil[T any](items []T, cond func(*T) bool) *T

func GetEnv

func GetEnv(key string, fallback string) string

func Map

func Map[T, V any](items []T, conv func(i int, t *T) *V) []V

Types

type AwsClient

type AwsClient interface {
	Region() string

	ListS3BucketObjects(ctx context.Context, bucket string, prefix string) ([]s3Types.Object, error)
	HeadS3Bucket(ctx context.Context, bucket string) error
	CreateS3Bucket(ctx context.Context, bucket string, region string) error
	EnableS3BucketVersioning(ctx context.Context, bucket string) error
	MakeS3BucketAclPrivate(ctx context.Context, bucket string) error
	DisableS3BucketPublicAccess(ctx context.Context, bucket string) error
	DeleteS3BucketObject(ctx context.Context, bucket string, key string) error
	PutS3BucketObjectAsBinaryFile(ctx context.Context, bucket string, key string, file *os.File) error
	PutS3BucketObjectAsTextFile(ctx context.Context, bucket string, key string, value string) error
	GetS3BucketObject(ctx context.Context, bucket string, key string) (*s3.GetObjectOutput, error)

	GetALBListenerRule(ctx context.Context, listenerRuleArn string) (*albTypes.Rule, error)
	ModifyALBListenerRule(ctx context.Context, listenerRuleArn string, forwardAction *albTypes.ForwardActionConfig) error
	DescribeALBTargetHealth(ctx context.Context, targetGroupArn string) ([]albTypes.TargetHealthDescription, error)
	DescribeALBTargetGroup(ctx context.Context, targetGroupArn string) (*albTypes.TargetGroup, error)

	DescribeAutoScalingGroup(ctx context.Context, name string) (*asgTypes.AutoScalingGroup, error)
	UpdateAutoScalingGroup(ctx context.Context, name string, desiredCapacity *int32, minSize *int32, maxSize *int32) error
	DescribeScheduledActions(ctx context.Context, name string) ([]asgTypes.ScheduledUpdateGroupAction, error)
	PutScheduledUpdateGroupAction(ctx context.Context, name string, action *asgTypes.ScheduledUpdateGroupAction) error
	DeleteScheduledAction(ctx context.Context, autoScalingGroupName string, scheduledActionName string) error
	GetSSMParameter(ctx context.Context, name string, withDecription bool) (*ssmTypes.Parameter, error)
}

type BundleInfo

type BundleInfo struct {
	Value        string
	LastModified *time.Time
}

type Bundler

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

func NewBundler

func NewBundler(deployConfig *Config, awsClient AwsClient, logger Logger) *Bundler

func (*Bundler) Activate

func (b *Bundler) Activate(ctx context.Context, targetType TargetType, bundleValue string) error

func (*Bundler) Download

func (b *Bundler) Download(ctx context.Context, targetType TargetType) error

func (*Bundler) ListBundles

func (b *Bundler) ListBundles(ctx context.Context) error

func (*Bundler) Register

func (b *Bundler) Register(ctx context.Context, uploadFile string, bundleName string) error

type Config

type Config struct {
	BundleBucket    string       `json:"bundleBucket" validate:"required"`
	ListenerRuleArn string       `json:"listenerRuleArn" validate:"required"`
	Target          *TargetSet   `json:"target" validate:"required"`
	RetryPolicy     *RetryPolicy `json:"retryPolicy" validate:"required"`
	TimeZone        *TimeZone    `json:"timeZone" validate:"required"`
}

func NewConfig

func NewConfig(ctx context.Context, awsClient AwsClient, filepath string) (*Config, error)

type DefaultAwsClient

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

func NewDefaultAwsClient

func NewDefaultAwsClient(ctx context.Context) (*DefaultAwsClient, error)

func (*DefaultAwsClient) CreateS3Bucket

func (c *DefaultAwsClient) CreateS3Bucket(ctx context.Context, bucket string, region string) error

func (*DefaultAwsClient) DeleteS3BucketObject

func (c *DefaultAwsClient) DeleteS3BucketObject(ctx context.Context, bucket string, key string) error

func (*DefaultAwsClient) DeleteScheduledAction

func (c *DefaultAwsClient) DeleteScheduledAction(ctx context.Context, autoScalingGroupName string, scheduledActionName string) error

func (*DefaultAwsClient) DescribeALBTargetGroup

func (c *DefaultAwsClient) DescribeALBTargetGroup(ctx context.Context, targetGroupArn string) (*albTypes.TargetGroup, error)

func (*DefaultAwsClient) DescribeALBTargetHealth

func (c *DefaultAwsClient) DescribeALBTargetHealth(ctx context.Context, targetGroupArn string) ([]albTypes.TargetHealthDescription, error)

func (*DefaultAwsClient) DescribeAutoScalingGroup

func (c *DefaultAwsClient) DescribeAutoScalingGroup(ctx context.Context, name string) (*asgTypes.AutoScalingGroup, error)

func (*DefaultAwsClient) DescribeScheduledActions

func (c *DefaultAwsClient) DescribeScheduledActions(ctx context.Context, name string) ([]asgTypes.ScheduledUpdateGroupAction, error)

func (*DefaultAwsClient) DisableS3BucketPublicAccess

func (c *DefaultAwsClient) DisableS3BucketPublicAccess(ctx context.Context, bucket string) error

func (*DefaultAwsClient) EnableS3BucketVersioning

func (c *DefaultAwsClient) EnableS3BucketVersioning(ctx context.Context, bucket string) error

func (*DefaultAwsClient) GetALBListenerRule

func (c *DefaultAwsClient) GetALBListenerRule(ctx context.Context, listenerRuleArn string) (*albTypes.Rule, error)

func (*DefaultAwsClient) GetS3BucketObject

func (c *DefaultAwsClient) GetS3BucketObject(ctx context.Context, bucket string, key string) (*s3.GetObjectOutput, error)

func (*DefaultAwsClient) GetSSMParameter

func (c *DefaultAwsClient) GetSSMParameter(ctx context.Context, name string, withDecription bool) (*ssmTypes.Parameter, error)

func (*DefaultAwsClient) HeadS3Bucket

func (c *DefaultAwsClient) HeadS3Bucket(ctx context.Context, bucket string) error

func (*DefaultAwsClient) ListS3BucketObjects

func (c *DefaultAwsClient) ListS3BucketObjects(ctx context.Context, bucket string, prefix string) ([]s3Types.Object, error)

func (*DefaultAwsClient) MakeS3BucketAclPrivate

func (c *DefaultAwsClient) MakeS3BucketAclPrivate(ctx context.Context, bucket string) error

func (*DefaultAwsClient) ModifyALBListenerRule

func (c *DefaultAwsClient) ModifyALBListenerRule(ctx context.Context, listenerRuleArn string, forwardAction *albTypes.ForwardActionConfig) error

func (*DefaultAwsClient) PutS3BucketObjectAsBinaryFile

func (c *DefaultAwsClient) PutS3BucketObjectAsBinaryFile(ctx context.Context, bucket string, key string, file *os.File) error

func (*DefaultAwsClient) PutS3BucketObjectAsTextFile

func (c *DefaultAwsClient) PutS3BucketObjectAsTextFile(ctx context.Context, bucket string, key string, value string) error

func (*DefaultAwsClient) PutScheduledUpdateGroupAction

func (c *DefaultAwsClient) PutScheduledUpdateGroupAction(ctx context.Context, name string, action *asgTypes.ScheduledUpdateGroupAction) error

func (*DefaultAwsClient) Region

func (c *DefaultAwsClient) Region() string

func (*DefaultAwsClient) UpdateAutoScalingGroup

func (c *DefaultAwsClient) UpdateAutoScalingGroup(ctx context.Context, name string, desiredCapacity *int32, minSize *int32, maxSize *int32) error

type DefaultLogger

type DefaultLogger struct {
	Verbose bool
}

func (*DefaultLogger) Debug

func (l *DefaultLogger) Debug(message string)

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(message string, error error)

func (*DefaultLogger) Fatal

func (l *DefaultLogger) Fatal(message string, error error)

func (*DefaultLogger) Info

func (l *DefaultLogger) Info(message string)

func (*DefaultLogger) Warn

func (l *DefaultLogger) Warn(message string, error error)

type DeployInfo

type DeployInfo struct {
	IdlingTarget  *DeployTarget
	RunningTarget *DeployTarget
}

type DeployTarget

type DeployTarget struct {
	Type             TargetType
	TargetGroup      *albTypes.TargetGroupTuple
	AutoScalingGroup *asgTypes.AutoScalingGroup
}

type Deployer

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

func NewDeployer

func NewDeployer(deployConfig *Config, awsClient AwsClient, logger Logger) *Deployer

func (*Deployer) CleanupAutoScalingGroup

func (d *Deployer) CleanupAutoScalingGroup(ctx context.Context, autoScalingGroupName string) error

func (*Deployer) Deploy

func (d *Deployer) Deploy(
	ctx context.Context, swap bool,
	cleanupBeforeDeploy bool,
	cleanupAfterDeploy bool,
	swapDuration *time.Duration) error

func (*Deployer) GetDeployInfo

func (d *Deployer) GetDeployInfo(ctx context.Context) (*DeployInfo, error)

func (*Deployer) GetDeployTarget

func (d *Deployer) GetDeployTarget(
	ctx context.Context, rule *albTypes.Rule, targetType TargetType) (*DeployTarget, error)

func (*Deployer) HealthCheck

func (d *Deployer) HealthCheck(ctx context.Context, targetGroupArn string, desiredCount int) error

func (*Deployer) MoveScheduledActions

func (d *Deployer) MoveScheduledActions(
	ctx context.Context, fromAutoScalingGroupName string, toAutoScalingGroupName string) error

func (*Deployer) ShowStatus

func (d *Deployer) ShowStatus(ctx context.Context) error

func (*Deployer) SwapTraffic

func (d *Deployer) SwapTraffic(ctx context.Context, duration *time.Duration) error

func (*Deployer) UpdateAutoScalingGroup

func (d *Deployer) UpdateAutoScalingGroup(
	ctx context.Context, autoScalingGroupName string, desiredCapacity *int32, minSize *int32, maxSize *int32) error

func (*Deployer) UpdateAutoScalingGroupByTarget

func (d *Deployer) UpdateAutoScalingGroupByTarget(
	ctx context.Context, targetType TargetType, desiredCapacity *int32, minSize *int32, maxSize *int32) error

func (*Deployer) UpdateTraffic

func (d *Deployer) UpdateTraffic(ctx context.Context, blueWeight int32, greenWeight int32) error

type FixedIntervalRetryer

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

func NewFixedIntervalRetryer

func NewFixedIntervalRetryer(maxLimit int, interval *time.Duration) *FixedIntervalRetryer

func (FixedIntervalRetryer) Start

func (r FixedIntervalRetryer) Start(hendler func(index int, interval *time.Duration) (RetryResult, error)) error

type HealthInfo

type HealthInfo struct {
	TargetGroupArn string
	TotalCount     int
	HealthyCount   int
	UnhealthyCount int
	UnusedCount    int
	InitialCount   int
	DrainingCount  int
}

type Logger

type Logger interface {
	Debug(message string)
	Info(message string)
	Warn(message string, error error)
	Error(message string, error error)
	Fatal(message string, error error)
}

type RetryPolicy

type RetryPolicy struct {
	MaxLimit        int `json:"maxLimit"`
	IntervalSeconds int `json:"intervalSeconds"`
}

type RetryResult

type RetryResult bool

type Retryer

type Retryer interface {
	Start(hendler func(index int, interval *time.Duration) (RetryResult, error)) error
}

type Target

type Target struct {
	AutoScalingGroupName string `json:"autoScalingGroupName" validate:"required"`
	TargetGroupArn       string `json:"TargetGroupArn" validate:"required"`
}

type TargetSet

type TargetSet struct {
	Blue  *Target `json:"blue" validate:"required"`
	Green *Target `json:"green" validate:"required"`
}

type TargetType

type TargetType string
const (
	BlueTargetType  TargetType = "blue"
	GreenTargetType TargetType = "green"
)

type TimeZone

type TimeZone struct {
	Location string `json:"location"`
	Offset   int    `json:"offset"`
}

func (*TimeZone) CurrentLocation

func (t *TimeZone) CurrentLocation() *time.Location

Jump to

Keyboard shortcuts

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