From 2eb159b0c3e2ce160f0fb3b76a346cee04c77c44 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 1 Jan 2021 21:15:03 -0500 Subject: [PATCH] refactor: use error group for fetching the app shell to use for app-json tasks --- plugins/app-json/appjson.go | 33 +++++++++++++++++++++++++-------- plugins/app-json/go.mod | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/plugins/app-json/appjson.go b/plugins/app-json/appjson.go index 52a16695e..e83d7eaa4 100644 --- a/plugins/app-json/appjson.go +++ b/plugins/app-json/appjson.go @@ -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 { diff --git a/plugins/app-json/go.mod b/plugins/app-json/go.mod index d5297f0c4..bccdd308d 100644 --- a/plugins/app-json/go.mod +++ b/plugins/app-json/go.mod @@ -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