-
Notifications
You must be signed in to change notification settings - Fork 524
/
Copy pathpipelineStage.go
224 lines (195 loc) · 10.2 KB
/
pipelineStage.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Copyright (c) 2024. Devtron Inc.
*
* 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 bean
import (
commonBean "github.com/devtron-labs/common-lib/workflow"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/pkg/pipeline/repository"
repository2 "github.com/devtron-labs/devtron/pkg/plugin/repository"
"github.com/devtron-labs/devtron/pkg/resourceQualifiers"
)
type PipelineStageDto struct {
Id int `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Type repository.PipelineStageType `json:"type,omitempty" validate:"omitempty,oneof=PRE_CI POST_CI PRE_CD POST_CD"`
Steps []*PipelineStageStepDto `json:"steps"`
TriggerType pipelineConfig.TriggerType `json:"triggerType,omitempty"`
}
type PipelineStageStepDto struct {
Id int `json:"id"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Index int `json:"index"`
StepType repository.PipelineStepType `json:"stepType" validate:"omitempty,oneof=INLINE REF_PLUGIN"`
OutputDirectoryPath []string `json:"outputDirectoryPath"`
InlineStepDetail *InlineStepDetailDto `json:"inlineStepDetail" validate:"omitempty,dive"`
RefPluginStepDetail *RefPluginStepDetailDto `json:"pluginRefStepDetail" validate:"omitempty,dive"`
TriggerIfParentStageFail bool `json:"triggerIfParentStageFail"`
}
type InlineStepDetailDto struct {
ScriptType repository2.ScriptType `json:"scriptType" validate:"omitempty,oneof=SHELL DOCKERFILE CONTAINER_IMAGE"`
Script string `json:"script"`
StoreScriptAt string `json:"storeScriptAt"`
DockerfileExists bool `json:"dockerfileExists,omitempty"`
MountPath string `json:"mountPath,omitempty"`
MountCodeToContainer bool `json:"mountCodeToContainer,omitempty"`
MountCodeToContainerPath string `json:"mountCodeToContainerPath,omitempty"`
MountDirectoryFromHost bool `json:"mountDirectoryFromHost"`
ContainerImagePath string `json:"containerImagePath,omitempty"`
ImagePullSecretType repository2.ScriptImagePullSecretType `json:"imagePullSecretType,omitempty" validate:"omitempty,oneof=CONTAINER_REGISTRY SECRET_PATH"`
ImagePullSecret string `json:"imagePullSecret,omitempty"`
MountPathMap []*MountPathMap `json:"mountPathMap,omitempty" validate:"omitempty,dive"`
CommandArgsMap []*CommandArgsMap `json:"commandArgsMap,omitempty" validate:"omitempty,dive"`
PortMap []*PortMap `json:"portMap,omitempty" validate:"omitempty,dive"`
InputVariables []*StepVariableDto `json:"inputVariables" validate:"dive"`
OutputVariables []*StepVariableDto `json:"outputVariables" validate:"dive"`
ConditionDetails []*ConditionDetailDto `json:"conditionDetails" validate:"dive"`
}
type RefPluginStepDetailDto struct {
PluginId int `json:"pluginId"`
InputVariables []*StepVariableDto `json:"inputVariables"`
OutputVariables []*StepVariableDto `json:"outputVariables"`
ConditionDetails []*ConditionDetailDto `json:"conditionDetails"`
}
// StepVariableDto is used to define the input/output variables for a step
// TODO: duplicate definition found - bean.PluginVariableDto.
// Have multiple conflicting fields with bean.PluginVariableDto.
type StepVariableDto struct {
Id int `json:"id"`
Name string `json:"name" validate:"required"`
Format repository.PipelineStageStepVariableFormatType `json:"format" validate:"oneof=STRING NUMBER BOOL DATE FILE"`
Description string `json:"description"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
DefaultValue string `json:"defaultValue,omitempty"`
Value string `json:"value"`
// ValueType – Ideally it should have json tag `valueType` instead of `variableType`
ValueType repository.PipelineStageStepVariableValueType `json:"variableType,omitempty" validate:"oneof=NEW FROM_PREVIOUS_STEP GLOBAL"`
PreviousStepIndex int `json:"refVariableStepIndex,omitempty"`
ReferenceVariableName string `json:"refVariableName,omitempty"`
VariableStepIndexInPlugin int `json:"variableStepIndexInPlugin,omitempty"`
ReferenceVariableStage repository.PipelineStageType `json:"refVariableStage,omitempty" validate:"omitempty,oneof=PRE_CI POST_CI PRE_CD POST_CD"`
StepVariableEntDto
}
type StepVariableEntDto struct {
}
func (s *StepVariableDto) GetValue() string {
if s == nil {
return ""
} else if len(s.Value) != 0 {
return s.Value
} else {
return s.DefaultValue
}
}
func (s *StepVariableDto) IsEmptyValue() bool {
if s == nil {
return true
}
// If the variable is global, then the value is empty, but referenceVariableName should not be empty
if s.ValueType.IsGlobalDefinedValue() {
return len(s.ReferenceVariableName) == 0
} else if s.ValueType.IsPreviousOutputDefinedValue() {
return len(s.ReferenceVariableName) == 0 || s.PreviousStepIndex == 0
}
return len(s.GetValue()) == 0
}
func (s *StepVariableDto) IsEmptyValueAllowed(isTriggerStage bool) bool {
if s == nil {
return false
}
// If the variable is not exposed as runtime arg OR if it is a trigger stage,
// then empty value refers to StepVariableDto.AllowEmptyValue
return s.AllowEmptyValue
}
type ConditionDetailDto struct {
Id int `json:"id"`
ConditionOnVariable string `json:"conditionOnVariable"` //name of variable on which condition is written
ConditionType repository.PipelineStageStepConditionType `json:"conditionType" validate:"oneof=SKIP TRIGGER FAIL PASS"`
ConditionalOperator string `json:"conditionOperator"`
ConditionalValue string `json:"conditionalValue"`
}
type MountPathMap struct {
FilePathOnDisk string `json:"filePathOnDisk"`
FilePathOnContainer string `json:"filePathOnContainer"`
}
type CommandArgsMap struct {
Command string `json:"command"`
Args []string `json:"args"`
}
type PortMap struct {
PortOnLocal int `json:"portOnLocal" validate:"number,gt=0"`
PortOnContainer int `json:"portOnContainer" validate:"number,gt=0"`
}
const (
VULNERABILITY_SCANNING_PLUGIN string = "Vulnerability Scanning"
NotTriggered string = "Not Triggered"
NotDeployed = "Not Deployed"
WorkflowTypeDeploy = "DEPLOY"
WorkflowTypePre = "PRE"
WorkflowTypePost = "POST"
)
// BuildPrePostStepDataRequest is a request object for func BuildPrePostAndRefPluginStepsDataForWfRequest
type BuildPrePostStepDataRequest struct {
PipelineId int
StageType string
Scope resourceQualifiers.Scope
}
// NewBuildPrePostStepDataReq creates a new BuildPrePostStepDataRequest object
func NewBuildPrePostStepDataReq(pipelineId int, stageType string, scope resourceQualifiers.Scope) *BuildPrePostStepDataRequest {
return &BuildPrePostStepDataRequest{
PipelineId: pipelineId,
StageType: stageType,
Scope: scope,
}
}
type VariableAndConditionDataForStep struct {
inputVariables []*commonBean.VariableObject
outputVariables []*commonBean.VariableObject
triggerSkipConditions []*ConditionObject
successFailureConditions []*ConditionObject
}
func NewVariableAndConditionDataForStep() *VariableAndConditionDataForStep {
return &VariableAndConditionDataForStep{}
}
func (v *VariableAndConditionDataForStep) AddInputVariable(variable *commonBean.VariableObject) *VariableAndConditionDataForStep {
v.inputVariables = append(v.inputVariables, variable)
return v
}
func (v *VariableAndConditionDataForStep) AddOutputVariable(variable *commonBean.VariableObject) *VariableAndConditionDataForStep {
v.outputVariables = append(v.outputVariables, variable)
return v
}
func (v *VariableAndConditionDataForStep) AddTriggerSkipCondition(condition *ConditionObject) *VariableAndConditionDataForStep {
v.triggerSkipConditions = append(v.triggerSkipConditions, condition)
return v
}
func (v *VariableAndConditionDataForStep) AddSuccessFailureCondition(condition *ConditionObject) *VariableAndConditionDataForStep {
v.successFailureConditions = append(v.successFailureConditions, condition)
return v
}
func (v *VariableAndConditionDataForStep) GetInputVariables() []*commonBean.VariableObject {
return v.inputVariables
}
func (v *VariableAndConditionDataForStep) GetOutputVariables() []*commonBean.VariableObject {
return v.outputVariables
}
func (v *VariableAndConditionDataForStep) GetTriggerSkipConditions() []*ConditionObject {
return v.triggerSkipConditions
}
func (v *VariableAndConditionDataForStep) GetSuccessFailureConditions() []*ConditionObject {
return v.successFailureConditions
}