refactor: use error group for fetching the app shell to use for app-json tasks

This commit is contained in:
Jose Diaz-Gonzalez
2021-01-01 21:15:03 -05:00
parent 596e7b6f24
commit 2eb159b0c3
2 changed files with 26 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ package appjson
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@@ -11,6 +12,7 @@ import (
"github.com/dokku/dokku/plugins/common"
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
@@ -130,16 +132,31 @@ func getReleaseCommand(appName string, image string) string {
}
func getDokkuAppShell(appName string) string {
dokkuAppShell := "/bin/bash"
if b, _ := common.PlugnTriggerOutput("config-get-global", []string{"DOKKU_APP_SHELL"}...); strings.TrimSpace(string(b[:])) != "" {
dokkuAppShell = strings.TrimSpace(string(b[:]))
shell := "/bin/bash"
globalShell := ""
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[:])) != "" {
dokkuAppShell = strings.TrimSpace(string(b[:]))
}
return dokkuAppShell
return shell
}
func executeScript(appName string, imageTag string, phase string) error {

View File

@@ -7,6 +7,7 @@ require (
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
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