-
Notifications
You must be signed in to change notification settings - Fork 153
/
application_ecs.go
97 lines (84 loc) · 3.32 KB
/
application_ecs.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2022 The PipeCD Authors.
//
// 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.
package config
import "encoding/json"
// ECSApplicationSpec represents an application configuration for ECS application.
type ECSApplicationSpec struct {
GenericApplicationSpec
// Input for ECS deployment such as where to fetch source code...
Input ECSDeploymentInput `json:"input"`
// Configuration for quick sync.
QuickSync ECSSyncStageOptions `json:"quickSync"`
}
// Validate returns an error if any wrong configuration value was found.
func (s *ECSApplicationSpec) Validate() error {
if err := s.GenericApplicationSpec.Validate(); err != nil {
return err
}
return nil
}
type ECSDeploymentInput struct {
// The name of service definition file placing in application directory.
// Default is service.json
ServiceDefinitionFile string `json:"serviceDefinitionFile" default:"service.json"`
// The name of task definition file placing in application directory.
// Default is taskdef.json
TaskDefinitionFile string `json:"taskDefinitionFile" default:"taskdef.json"`
// ECSTargetGroups
TargetGroups ECSTargetGroups `json:"targetGroups"`
// Automatically reverts all changes from all stages when one of them failed.
// Default is true.
AutoRollback *bool `json:"autoRollback,omitempty" default:"true"`
}
type ECSTargetGroups struct {
Primary json.RawMessage `json:"primary"`
Canary json.RawMessage `json:"canary"`
}
// ECSSyncStageOptions contains all configurable values for a ECS_SYNC stage.
type ECSSyncStageOptions struct {
}
// ECSCanaryRolloutStageOptions contains all configurable values for a ECS_CANARY_ROLLOUT stage.
type ECSCanaryRolloutStageOptions struct {
// Scale represents the amount of desired task that should be rolled out as CANARY variant workload.
Scale Percentage `json:"scale"`
}
// ECSPrimaryRolloutStageOptions contains all configurable values for a ECS_PRIMARY_ROLLOUT stage.
type ECSPrimaryRolloutStageOptions struct {
}
// ECSCanaryCleanStageOptions contains all configurable values for a ECS_CANARY_CLEAN stage.
type ECSCanaryCleanStageOptions struct {
}
// ECSTrafficRoutingStageOptions contains all configurable values for ECS_TRAFFIC_ROUTING stage.
type ECSTrafficRoutingStageOptions struct {
// Canary represents the amount of traffic that the rolled out CANARY variant will serve.
Canary Percentage `json:"canary"`
// Primary represents the amount of traffic that the rolled out CANARY variant will serve.
Primary Percentage `json:"primary"`
}
func (opts ECSTrafficRoutingStageOptions) Percentage() (primary, canary int) {
primary = opts.Primary.Int()
if primary > 0 && primary <= 100 {
canary = 100 - primary
return
}
canary = opts.Canary.Int()
if canary > 0 && canary <= 100 {
primary = 100 - canary
return
}
// As default, Primary variant will receive 100% of traffic.
primary = 100
canary = 0
return
}