mirror of https://github.com/docker/compose.git
Update existing stack installation on `compose up` instead of returning error
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
9279954193
commit
bb25812511
|
@ -74,7 +74,7 @@ func NewComposeService() (compose.Service, error) {
|
||||||
func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
|
func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
|
|
||||||
eventName := "Convert to Helm charts"
|
eventName := "Convert Compose file to Helm charts"
|
||||||
w.Event(progress.CreatingEvent(eventName))
|
w.Event(progress.CreatingEvent(eventName))
|
||||||
|
|
||||||
chart, err := helm.GetChartInMemory(project)
|
chart, err := helm.GetChartInMemory(project)
|
||||||
|
@ -83,16 +83,31 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
||||||
}
|
}
|
||||||
w.Event(progress.NewEvent(eventName, progress.Done, ""))
|
w.Event(progress.NewEvent(eventName, progress.Done, ""))
|
||||||
|
|
||||||
eventName = "Install Helm charts"
|
stack, err := s.sdk.Get(project.Name)
|
||||||
w.Event(progress.CreatingEvent(eventName))
|
if err != nil || stack == nil {
|
||||||
|
// install stack
|
||||||
|
eventName = "Install Compose stack"
|
||||||
|
w.Event(progress.CreatingEvent(eventName))
|
||||||
|
|
||||||
err = s.sdk.InstallChart(project.Name, chart, func(format string, v ...interface{}) {
|
err = s.sdk.InstallChart(project.Name, chart, func(format string, v ...interface{}) {
|
||||||
message := fmt.Sprintf(format, v...)
|
message := fmt.Sprintf(format, v...)
|
||||||
w.Event(progress.NewEvent(eventName, progress.Done, message))
|
w.Event(progress.NewEvent(eventName, progress.Done, message))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//update stack
|
||||||
|
eventName = "Updating Compose stack"
|
||||||
|
w.Event(progress.CreatingEvent(eventName))
|
||||||
|
|
||||||
|
err = s.sdk.UpdateChart(project.Name, chart, func(format string, v ...interface{}) {
|
||||||
|
message := fmt.Sprintf(format, v...)
|
||||||
|
w.Event(progress.NewEvent(eventName, progress.Done, message))
|
||||||
|
})
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Event(progress.NewEvent(eventName, progress.Done, ""))
|
w.Event(progress.NewEvent(eventName, progress.Done, ""))
|
||||||
|
|
||||||
return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{
|
return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{
|
||||||
|
|
|
@ -84,6 +84,19 @@ func (hc *Actions) InstallChart(name string, chart *chart.Chart, logger func(for
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateChart upgrades chart
|
||||||
|
func (hc *Actions) UpdateChart(name string, chart *chart.Chart, logger func(format string, v ...interface{})) error {
|
||||||
|
err := hc.initialize(logger)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
actUpgrade := action.NewUpgrade(hc.Config)
|
||||||
|
actUpgrade.Namespace = hc.Namespace
|
||||||
|
_, err = actUpgrade.Run(name, chart, map[string]interface{}{})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Uninstall uninstall chart
|
// Uninstall uninstall chart
|
||||||
func (hc *Actions) Uninstall(name string, logger func(format string, v ...interface{})) error {
|
func (hc *Actions) Uninstall(name string, logger func(format string, v ...interface{})) error {
|
||||||
err := hc.initialize(logger)
|
err := hc.initialize(logger)
|
||||||
|
|
Loading…
Reference in New Issue