@@ -14,19 +14,23 @@ define(['models/wkt-project', 'models/wkt-console', 'utils/i18n', 'utils/project
14
14
return this . callPushImage ( ) ;
15
15
} ;
16
16
17
+ this . startPushAuxImage = async ( ) => {
18
+ return this . callPushAuxImage ( ) ;
19
+ } ;
20
+
17
21
this . callPushImage = async ( options ) => {
18
22
if ( ! options ) {
19
23
options = { } ;
20
24
}
21
25
22
26
let errTitle = i18n . t ( 'image-pusher-push-aborted-title' ) ;
23
- if ( this . project . settings . targetDomainLocation . value === 'pv' && ! this . project . image . createCustomImageForPV . value ) {
24
- const errMessage = i18n . t ( 'image-pusher-domain-location-pv -message' ) ;
27
+ if ( ! this . project . image . createPrimaryImage . value ) {
28
+ const errMessage = i18n . t ( 'image-pusher-image-not-create -message' ) ;
25
29
await window . api . ipc . invoke ( 'show-info-message' , errTitle , errMessage ) ;
26
30
return Promise . resolve ( false ) ;
27
31
}
28
32
29
- const validatableObject = this . getValidatableObject ( 'flow-push-image-name' ) ;
33
+ const validatableObject = this . getValidatableObjectForPrimary ( 'flow-push-image-name' ) ;
30
34
if ( validatableObject . hasValidationErrors ( ) ) {
31
35
const validationErrorDialogConfig = validatableObject . getValidationErrorDialogConfig ( errTitle ) ;
32
36
dialogHelper . openDialog ( 'validation-error-dialog' , validationErrorDialogConfig ) ;
@@ -117,29 +121,168 @@ define(['models/wkt-project', 'models/wkt-console', 'utils/i18n', 'utils/project
117
121
}
118
122
} ;
119
123
120
- this . getValidatableObject = ( flowNameKey ) => {
124
+ this . getValidatableObjectForPrimary = ( flowNameKey ) => {
121
125
const validationObject = validationHelper . createValidatableObject ( flowNameKey ) ;
122
- const settingsFormConfig = validationObject . getDefaultConfigObject ( ) ;
123
- settingsFormConfig . formName = 'project-settings-title' ;
126
+ const imageFormConfig = validationObject . getDefaultConfigObject ( ) ;
127
+ imageFormConfig . formName = 'image-design-form-name' ;
128
+ imageFormConfig . tabName = 'image-design-form-primary-tab-name' ;
124
129
125
130
validationObject . addField ( 'image-design-image-tag-label' ,
126
- this . project . image . imageTag . validate ( true ) , settingsFormConfig ) ;
131
+ this . project . image . imageTag . validate ( true ) , imageFormConfig ) ;
127
132
128
- const settingsFormBuilderConfig = validationObject . getDefaultConfigObject ( ) ;
129
- settingsFormBuilderConfig . formName = 'project-settings-title' ;
130
- settingsFormBuilderConfig . fieldNamePayload = { toolName : this . project . settings . builderType . value } ;
133
+ const settingsFormConfig = validationObject . getDefaultConfigObject ( ) ;
134
+ settingsFormConfig . formName = 'project-settings-title' ;
135
+ settingsFormConfig . fieldNamePayload = { toolName : this . project . settings . builderType . value } ;
131
136
validationObject . addField ( 'project-settings-build-tool-label' ,
132
137
validationHelper . validateRequiredField ( this . project . settings . builderExecutableFilePath . value ) ,
133
- settingsFormBuilderConfig ) ;
138
+ settingsFormConfig ) ;
134
139
135
140
if ( this . project . image . imageRegistryPushRequireAuthentication . value ) {
136
141
// skip validating the host portion of the image tag since it may be empty for Docker Hub...
137
142
validationObject . addField ( 'image-design-image-registry-push-username-label' ,
138
143
validationHelper . validateRequiredField ( this . project . image . imageRegistryPushUser . value ) ,
139
- settingsFormConfig ) ;
144
+ imageFormConfig ) ;
140
145
validationObject . addField ( 'image-design-image-registry-push-password-label' ,
141
146
validationHelper . validateRequiredField ( this . project . image . imageRegistryPushPassword . value ) ,
142
- settingsFormConfig ) ;
147
+ imageFormConfig ) ;
148
+ }
149
+
150
+ return validationObject ;
151
+ } ;
152
+
153
+ this . callPushAuxImage = async ( options ) => {
154
+ if ( ! options ) {
155
+ options = { } ;
156
+ }
157
+
158
+ let errTitle = i18n . t ( 'image-pusher-push-aborted-title' ) ;
159
+ let abortErrorMessage ;
160
+ if ( this . project . settings . targetDomainLocation . value !== 'mii' ) {
161
+ abortErrorMessage = i18n . t ( 'image-pusher-aux-image-not-mii-message' ) ;
162
+ } else if ( ! this . project . image . useAuxImage . value ) {
163
+ abortErrorMessage = i18n . t ( 'image-pusher-aux-image-not-use-message' ) ;
164
+ } else if ( ! this . project . image . createAuxImage . value ) {
165
+ abortErrorMessage = i18n . t ( 'image-pusher-aux-image-not-create-message' ) ;
166
+ }
167
+ if ( abortErrorMessage ) {
168
+ await window . api . ipc . invoke ( 'show-info-message' , errTitle , abortErrorMessage ) ;
169
+ return Promise . resolve ( false ) ;
170
+ }
171
+
172
+
173
+ const validatableObject = this . getValidatableObjectForAux ( 'flow-push-aux-image-name' ) ;
174
+ if ( validatableObject . hasValidationErrors ( ) ) {
175
+ const validationErrorDialogConfig = validatableObject . getValidationErrorDialogConfig ( errTitle ) ;
176
+ dialogHelper . openDialog ( 'validation-error-dialog' , validationErrorDialogConfig ) ;
177
+ return Promise . resolve ( false ) ;
178
+ }
179
+
180
+ const totalSteps = 4.0 ;
181
+ const imageTag = this . project . image . auxImageTag . value ;
182
+
183
+ let busyDialogMessage = i18n . t ( 'flow-image-builder-validation-in-progress' , { imageTag : imageTag } ) ;
184
+ dialogHelper . openBusyDialog ( busyDialogMessage , 'bar' ) ;
185
+ dialogHelper . updateBusyDialog ( busyDialogMessage , 0 / totalSteps ) ;
186
+ try {
187
+ const imageBuilderExe = this . project . settings . builderExecutableFilePath . value ;
188
+ if ( ! options . skipImageBuilderValidation ) {
189
+ const imageBuilderExeResults =
190
+ await window . api . ipc . invoke ( 'validate-image-builder-exe' , imageBuilderExe ) ;
191
+ if ( ! imageBuilderExeResults . isValid ) {
192
+ const errMessage = i18n . t ( 'image-pusher-image-builder-invalid-error-message' ,
193
+ { fileName : imageBuilderExe , error : imageBuilderExeResults . reason } ) ;
194
+ await window . api . ipc . invoke ( 'show-error-message' , errTitle , errMessage ) ;
195
+ return Promise . resolve ( false ) ;
196
+ }
197
+ }
198
+
199
+ busyDialogMessage = i18n . t ( 'image-pusher-image-exists-in-progress' , { imageTag : imageTag } ) ;
200
+ dialogHelper . updateBusyDialog ( busyDialogMessage , 1 / totalSteps ) ;
201
+ if ( ! options . skipLocalImageExistsValidation ) {
202
+ const imageExistsResults =
203
+ await window . api . ipc . invoke ( 'validate-image-exists-locally' , imageBuilderExe , imageTag ) ;
204
+ let errMessage ;
205
+ if ( imageExistsResults . isSuccess && ! imageExistsResults . imageExists ) {
206
+ errMessage = i18n . t ( 'image-pusher-image-not-exists-error-message' , { imageTag : imageTag } ) ;
207
+ } else if ( ! imageExistsResults . isSuccess ) {
208
+ errMessage = i18n . t ( 'image-pusher-image-exists-failed-error-message' ,
209
+ { imageTag : imageTag , error : imageExistsResults . reason } ) ;
210
+ }
211
+ if ( errMessage ) {
212
+ await window . api . ipc . invoke ( 'show-error-message' , errTitle , errMessage ) ;
213
+ return Promise . resolve ( false ) ;
214
+ }
215
+ }
216
+
217
+ busyDialogMessage = i18n . t ( 'flow-save-project-in-progress' ) ;
218
+ dialogHelper . updateBusyDialog ( busyDialogMessage , 2 / totalSteps ) ;
219
+ if ( ! options . skipProjectSave ) {
220
+ const saveResult = await projectIo . saveProject ( ) ;
221
+ if ( ! saveResult . saved ) {
222
+ const errMessage = `${ i18n . t ( 'image-pusher-project-not-saved-error-prefix' ) } : ${ saveResult . reason } ` ;
223
+ await window . api . ipc . invoke ( 'show-error-message' , errTitle , errMessage ) ;
224
+ return Promise . resolve ( false ) ;
225
+ }
226
+ }
227
+
228
+ if ( ! options . skipClearAndShowConsole ) {
229
+ wktConsole . clear ( ) ;
230
+ wktConsole . show ( true ) ;
231
+ }
232
+
233
+ busyDialogMessage = i18n . t ( 'image-pusher-push-in-progress' , { imageTag : imageTag } ) ;
234
+ dialogHelper . updateBusyDialog ( busyDialogMessage , 3 / totalSteps ) ;
235
+ const pushOptions = {
236
+ requiresLogin : this . project . image . auxImageRegistryPushRequireAuthentication . value ,
237
+ host : this . project . image . internal . auxImageRegistryAddress . value ,
238
+ username : this . project . image . auxImageRegistryPushUser . value ,
239
+ password : this . project . image . auxImageRegistryPushPassword . value
240
+ } ;
241
+ let pushResults = await window . api . ipc . invoke ( 'do-push-image' , imageBuilderExe , imageTag , pushOptions ) ;
242
+ dialogHelper . closeBusyDialog ( ) ;
243
+ if ( pushResults . isSuccess ) {
244
+ if ( ! options . skipCompleteDialog ) {
245
+ const title = i18n . t ( 'image-pusher-create-complete-title' ) ;
246
+ const message = i18n . t ( 'image-pusher-create-complete-message' , { imageTag : imageTag } ) ;
247
+ await window . api . ipc . invoke ( 'show-info-message' , title , message ) ;
248
+ }
249
+ return Promise . resolve ( true ) ;
250
+ } else {
251
+ const failedTitle = i18n . t ( 'image-pusher-push-failed-title' ) ;
252
+ const failedMessage = i18n . t ( 'image-pusher-push-failed-error-message' , { error : pushResults . reason } ) ;
253
+ await window . api . ipc . invoke ( 'show-error-message' , failedTitle , failedMessage ) ;
254
+ return Promise . resolve ( false ) ;
255
+ }
256
+ } catch ( err ) {
257
+ dialogHelper . closeBusyDialog ( ) ;
258
+ throw err ;
259
+ } finally {
260
+ dialogHelper . closeBusyDialog ( ) ;
261
+ }
262
+ } ;
263
+
264
+ this . getValidatableObjectForAux = ( flowNameKey ) => {
265
+ const validationObject = validationHelper . createValidatableObject ( flowNameKey ) ;
266
+ const imageFormConfig = validationObject . getDefaultConfigObject ( ) ;
267
+ imageFormConfig . formName = 'image-design-form-name' ;
268
+ imageFormConfig . tabName = 'image-design-form-auxiliary-tab-name' ;
269
+
270
+ validationObject . addField ( 'image-design-image-tag-label' ,
271
+ this . project . image . auxImageTag . validate ( true ) , imageFormConfig ) ;
272
+
273
+ const settingsFormConfig = validationObject . getDefaultConfigObject ( ) ;
274
+ settingsFormConfig . formName = 'project-settings-form-name' ;
275
+ settingsFormConfig . fieldNamePayload = { toolName : this . project . settings . builderType . value } ;
276
+ validationObject . addField ( 'project-settings-build-tool-label' ,
277
+ validationHelper . validateRequiredField ( this . project . settings . builderExecutableFilePath . value ) ,
278
+ settingsFormConfig ) ;
279
+
280
+ if ( this . project . image . auxImageRegistryPushRequireAuthentication . value ) {
281
+ // skip validating the host portion of the image tag since it may be empty for Docker Hub...
282
+ validationObject . addField ( 'image-design-aux-image-registry-push-username-label' ,
283
+ validationHelper . validateRequiredField ( this . project . image . auxImageRegistryPushUser . value ) , imageFormConfig ) ;
284
+ validationObject . addField ( 'image-design-aux-image-registry-push-password-label' ,
285
+ validationHelper . validateRequiredField ( this . project . image . auxImageRegistryPushPassword . value ) , imageFormConfig ) ;
143
286
}
144
287
145
288
return validationObject ;
0 commit comments