forked from kayac/ecspresso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (46 loc) · 1.81 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ecspresso
import (
"errors"
"os"
"time"
"github.com/aws/aws-sdk-go/service/ecs"
)
type Config struct {
Region string `yaml:"region"`
Service string `yaml:"service"`
Cluster string `yaml:"cluster"`
TaskDefinitionPath string `yaml:"task_definition"`
ServiceDefinitionPath string `yaml:"service_definition"`
Timeout time.Duration `yaml:"timeout"`
}
type ServiceDefinition struct {
DeploymentConfiguration *ecs.DeploymentConfiguration `json:"deploymentConfiguration"`
DesiredCount *int64 `json:"desiredCount"`
HealthCheckGracePeriodSeconds *int64 `json:"healthCheckGracePeriod_seconds"`
LaunchType *string `json:"launchType"`
LoadBalancers []*ecs.LoadBalancer `json:"loadBalancers"`
NetworkConfiguration *ecs.NetworkConfiguration `json:"networkConfiguration"`
PlacementConstraints []*ecs.PlacementConstraint `json:"placementConstraints"`
PlacementStrategy []*ecs.PlacementStrategy `json:"placementStrategy"`
PlatformVersion *string `json:"platformVersion"`
Role *string `json:"role"`
SchedulingStrategy *string `json:"schedulingStrategy"`
}
func (c *Config) Validate() error {
if c.Service == "" {
return errors.New("service is not defined")
}
if c.Cluster == "" {
return errors.New("cluster is not defined")
}
if c.TaskDefinitionPath == "" {
return errors.New("task_definition is not defined")
}
return nil
}
func NewDefaultConfig() *Config {
return &Config{
Region: os.Getenv("AWS_REGION"),
Timeout: 300 * time.Second,
}
}