refactor: use error group for fetching the app shell to use for app-json tasks
This commit is contained in:
@@ -2,6 +2,7 @@ package appjson
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
shellquote "github.com/kballard/go-shellquote"
|
shellquote "github.com/kballard/go-shellquote"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AppJSON is a struct that represents an app.json file as understood by Dokku
|
// AppJSON is a struct that represents an app.json file as understood by Dokku
|
||||||
@@ -130,16 +132,31 @@ func getReleaseCommand(appName string, image string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getDokkuAppShell(appName string) string {
|
func getDokkuAppShell(appName string) string {
|
||||||
dokkuAppShell := "/bin/bash"
|
shell := "/bin/bash"
|
||||||
if b, _ := common.PlugnTriggerOutput("config-get-global", []string{"DOKKU_APP_SHELL"}...); strings.TrimSpace(string(b[:])) != "" {
|
globalShell := ""
|
||||||
dokkuAppShell = strings.TrimSpace(string(b[:]))
|
appShell := ""
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
errs, ctx := errgroup.WithContext(ctx)
|
||||||
|
errs.Go(func() error {
|
||||||
|
b, _ := common.PlugnTriggerOutput("config-get-global", []string{"DOKKU_APP_SHELL"}...)
|
||||||
|
globalShell = strings.TrimSpace(string(b[:]))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
errs.Go(func() error {
|
||||||
|
b, _ := common.PlugnTriggerOutput("config-global", []string{"DOKKU_APP_SHELL"}...)
|
||||||
|
appShell = strings.TrimSpace(string(b[:]))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
errs.Wait()
|
||||||
|
if appShell != "" {
|
||||||
|
shell = appShell
|
||||||
|
} else if globalShell != "" {
|
||||||
|
shell = globalShell
|
||||||
}
|
}
|
||||||
|
|
||||||
if b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_APP_SHELL"}...); strings.TrimSpace(string(b[:])) != "" {
|
return shell
|
||||||
dokkuAppShell = strings.TrimSpace(string(b[:]))
|
|
||||||
}
|
|
||||||
|
|
||||||
return dokkuAppShell
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeScript(appName string, imageTag string, phase string) error {
|
func executeScript(appName string, imageTag string, phase string) error {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ require (
|
|||||||
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||||
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 // indirect
|
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 // indirect
|
||||||
|
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/dokku/dokku/plugins/common => ../common
|
replace github.com/dokku/dokku/plugins/common => ../common
|
||||||
|
|||||||
Reference in New Issue
Block a user