@@ -20,42 +20,98 @@ package kube
20
20
21
21
import (
22
22
"context"
23
+ "fmt"
24
+ "strings"
23
25
24
26
"github.com/compose-spec/compose-go/types"
25
27
26
28
"github.com/docker/compose-cli/api/compose"
29
+ apicontext "github.com/docker/compose-cli/api/context"
30
+ "github.com/docker/compose-cli/api/context/store"
27
31
"github.com/docker/compose-cli/api/errdefs"
28
- "github.com/docker/compose-cli/kube/charts"
32
+ "github.com/docker/compose-cli/api/progress"
33
+ "github.com/docker/compose-cli/kube/helm"
34
+ "github.com/docker/compose-cli/kube/resources"
29
35
)
30
36
37
+ type composeService struct {
38
+ sdk * helm.Actions
39
+ }
40
+
31
41
// NewComposeService create a kubernetes implementation of the compose.Service API
32
42
func NewComposeService (ctx context.Context ) (compose.Service , error ) {
33
- chartsAPI , err := charts .NewSDK (ctx )
43
+ contextStore := store .ContextStore (ctx )
44
+ currentContext := apicontext .CurrentContext (ctx )
45
+ var kubeContext store.KubeContext
46
+
47
+ if err := contextStore .GetEndpoint (currentContext , & kubeContext ); err != nil {
48
+ return nil , err
49
+ }
50
+ config , err := resources .LoadConfig (kubeContext )
51
+ if err != nil {
52
+ return nil , err
53
+ }
54
+ actions , err := helm .NewActions (config )
34
55
if err != nil {
35
56
return nil , err
36
57
}
37
58
return & composeService {
38
- sdk : chartsAPI ,
59
+ sdk : actions ,
39
60
}, nil
40
61
}
41
62
42
- type composeService struct {
43
- sdk charts.SDK
44
- }
45
-
46
63
// Up executes the equivalent to a `compose up`
47
64
func (s * composeService ) Up (ctx context.Context , project * types.Project , options compose.UpOptions ) error {
48
- return s .sdk .Install (project )
65
+ w := progress .ContextWriter (ctx )
66
+
67
+ eventName := "Convert to Helm charts"
68
+ w .Event (progress .CreatingEvent (eventName ))
69
+
70
+ chart , err := helm .GetChartInMemory (project )
71
+ if err != nil {
72
+ return err
73
+ }
74
+ w .Event (progress .NewEvent (eventName , progress .Done , "" ))
75
+
76
+ eventName = "Install Helm charts"
77
+ w .Event (progress .CreatingEvent (eventName ))
78
+
79
+ err = s .sdk .InstallChart (project .Name , chart , func (format string , v ... interface {}) {
80
+ message := fmt .Sprintf (format , v ... )
81
+ w .Event (progress .NewEvent (eventName , progress .Done , message ))
82
+ })
83
+
84
+ w .Event (progress .NewEvent (eventName , progress .Done , "" ))
85
+ return err
49
86
}
50
87
51
88
// Down executes the equivalent to a `compose down`
52
89
func (s * composeService ) Down (ctx context.Context , projectName string , options compose.DownOptions ) error {
53
- return s .sdk .Uninstall (projectName )
90
+ w := progress .ContextWriter (ctx )
91
+
92
+ eventName := fmt .Sprintf ("Remove %s" , projectName )
93
+ w .Event (progress .CreatingEvent (eventName ))
94
+
95
+ logger := func (format string , v ... interface {}) {
96
+ message := fmt .Sprintf (format , v ... )
97
+ if strings .Contains (message , "Starting delete" ) {
98
+ action := strings .Replace (message , "Starting delete for" , "Delete" , 1 )
99
+
100
+ w .Event (progress .CreatingEvent (action ))
101
+ w .Event (progress .NewEvent (action , progress .Done , "" ))
102
+ return
103
+ }
104
+ w .Event (progress .NewEvent (eventName , progress .Working , message ))
105
+ }
106
+ err := s .sdk .Uninstall (projectName , logger )
107
+ w .Event (progress .NewEvent (eventName , progress .Done , "" ))
108
+
109
+ return err
54
110
}
55
111
56
112
// List executes the equivalent to a `docker stack ls`
57
113
func (s * composeService ) List (ctx context.Context ) ([]compose.Stack , error ) {
58
- return s .sdk .List ()
114
+ return s .sdk .ListReleases ()
59
115
}
60
116
61
117
// Build executes the equivalent to a `compose build`
0 commit comments