...
1 package libdevfile
2
3 import (
4 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
5 "github.com/devfile/library/v2/pkg/devfile/parser"
6 parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
7 )
8
9
10 type imageComponent struct {
11 component v1alpha2.Component
12 devfileObj parser.DevfileObj
13 }
14
15 var _ component = (*imageComponent)(nil)
16
17 func newImageComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *imageComponent {
18 return &imageComponent{
19 component: component,
20 devfileObj: devfileObj,
21 }
22 }
23
24 func (e *imageComponent) CheckValidity() error {
25 return nil
26 }
27
28 func (e *imageComponent) Apply(handler Handler, kind v1alpha2.CommandGroupKind) error {
29 return handler.ApplyImage(e.component)
30 }
31
32
33
34
35 func GetImageComponentsToPushAutomatically(devfileObj parser.DevfileObj) ([]v1alpha2.Component, error) {
36 imageComponents, err := devfileObj.Data.GetComponents(parsercommon.DevfileOptions{
37 ComponentOptions: parsercommon.ComponentOptions{ComponentType: v1alpha2.ImageComponentType},
38 })
39 if err != nil {
40 return nil, err
41 }
42
43 allApplyCommands, err := devfileObj.Data.GetCommands(parsercommon.DevfileOptions{
44 CommandOptions: parsercommon.CommandOptions{CommandType: v1alpha2.ApplyCommandType},
45 })
46 if err != nil {
47 return nil, err
48 }
49
50 m := make(map[string]v1alpha2.Component)
51 for _, comp := range imageComponents {
52 var add bool
53 if comp.Image.AutoBuild == nil {
54
55 if !IsComponentReferenced(allApplyCommands, comp.Name) {
56 add = true
57 }
58 } else if *comp.Image.AutoBuild {
59 add = true
60 }
61 if !add {
62 continue
63 }
64 if _, present := m[comp.Name]; !present {
65 m[comp.Name] = comp
66 }
67 }
68
69 var result []v1alpha2.Component
70 for _, comp := range m {
71 result = append(result, comp)
72 }
73 return result, nil
74 }
75
View as plain text