Skip to content

Commit 4e49c47

Browse files
committed
Optimize terraform installation
1 parent 5f30903 commit 4e49c47

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

backend/internal/processes/bootstrap.go

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package processes
22

33
import (
44
"fmt"
5+
"sync"
56

67
log "github.com/sirupsen/logrus"
78
"github.com/spf13/afero"
@@ -80,54 +81,76 @@ func BootstrapEnv(appconf *config.AppConfig) error {
8081
return err
8182
}
8283

83-
//r := action.ActRunnerImpl{}
84-
//err = UpdateCoreConfig(appconf, store, nil, "")
85-
//if err != nil {
86-
// log.WithError(err).Error("Problem updating ssm config")
87-
//}
88-
84+
// First install Gateway and API Gateway sequentially
8985
log.Infof("Setting Up HTTPD Gateway from Marketplace")
90-
err = installGateway(store, appconf)
91-
if err != nil {
86+
if err := installGateway(store, appconf); err != nil {
9287
log.WithError(err).Error("Error installing HTTPD Gateway")
9388
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
9489
if err != nil {
9590
log.WithError(err).Error("Problem writing to auditlog")
9691
}
97-
return err
92+
return fmt.Errorf("gateway installation failed: %w", err)
9893
}
9994

100-
log.Infof("Setting Up Health Status Lambda")
101-
err = installHealthStatusLambda(store, appconf)
102-
if err != nil {
103-
log.WithError(err).Error("Error installing Health Status")
95+
log.Infof("Setting Up Basic API Gateway from Marketplace")
96+
if err := installBasicAPIGateway(store, appconf); err != nil {
97+
log.WithError(err).Error("Error installing API Gateway")
10498
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
10599
if err != nil {
106100
log.WithError(err).Error("Problem writing to auditlog")
107101
}
108-
return err
102+
return fmt.Errorf("API gateway installation failed: %w", err)
109103
}
110104

111-
log.Infof("Setting Up Basic API Gateway from Marketplace")
112-
err = installBasicAPIGateway(store, appconf)
113-
if err != nil {
114-
log.WithError(err).Error("Error installing API Gateway")
115-
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
116-
if err != nil {
117-
log.WithError(err).Error("Problem writing to auditlog")
105+
// Now parallelize the remaining installations
106+
log.Infof("Starting parallel installation of remaining components")
107+
108+
var wg sync.WaitGroup
109+
errChan := make(chan error, 2) // Buffer for potential errors from 2 installations
110+
111+
// Launch Health Status Lambda installation
112+
wg.Add(1)
113+
go func() {
114+
defer wg.Done()
115+
log.Infof("Setting Up Health Status Lambda")
116+
if err := installHealthStatusLambda(store, appconf); err != nil {
117+
log.WithError(err).Error("Error installing Health Status")
118+
errChan <- fmt.Errorf("health status lambda installation failed: %w", err)
118119
}
119-
return err
120+
}()
121+
122+
// Launch Unity UI installation
123+
wg.Add(1)
124+
go func() {
125+
defer wg.Done()
126+
log.Infof("Setting Up Unity UI from Marketplace")
127+
if err := installUnityUi(store, appconf); err != nil {
128+
log.WithError(err).Error("Error installing unity-portal")
129+
errChan <- fmt.Errorf("unity UI installation failed: %w", err)
130+
}
131+
}()
132+
133+
// Wait for remaining installations to complete
134+
wg.Wait()
135+
close(errChan)
136+
137+
// Check for any errors that occurred during parallel installation
138+
var errors []error
139+
for err := range errChan {
140+
errors = append(errors, err)
120141
}
121142

122-
log.Infof("Setting Up Unity UI from Marketplace")
123-
err = installUnityUi(store, appconf)
124-
if err != nil {
125-
log.WithError(err).Error("Error installing unity-portal")
126-
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
143+
if len(errors) > 0 {
144+
// Combine all errors into a single error message
145+
errorMsg := "Multiple installation failures:"
146+
for _, err := range errors {
147+
errorMsg += "\n- " + err.Error()
148+
}
149+
err := store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
127150
if err != nil {
128151
log.WithError(err).Error("Problem writing to auditlog")
129152
}
130-
return err
153+
return fmt.Errorf(errorMsg)
131154
}
132155

133156
err = store.AddToAudit(application.Bootstrap_Successful, "test")

0 commit comments

Comments
 (0)