Skip to content

Commit edcb876

Browse files
authored
Merge pull request #266 from yashsinghcodes/main
GetDockerClient for valid docker api version
2 parents 3a05484 + d6d9ae6 commit edcb876

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

shared.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import (
6161
"golang.org/x/crypto/bcrypt"
6262

6363
"github.com/Masterminds/semver"
64+
dockerclient "github.com/docker/docker/client"
6465
)
6566

6667
var project ShuffleStorage
@@ -8052,6 +8053,13 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
80528053
return
80538054
}
80548055

8056+
// This fix the region issues with public workflow but can it create problem?
8057+
if len(tmpworkflow.ID) == 0 || workflow.Public == true {
8058+
log.Printf("[WARNING] Failed to find public workflow in region, using user provided workflow data")
8059+
tmp := workflow
8060+
tmpworkflow = &tmp
8061+
}
8062+
80558063
if project.Environment == "cloud" && tmpworkflow.Validated == false {
80568064
if workflow.Validated == true {
80578065

@@ -33713,3 +33721,49 @@ func getPrioritisedAppActions(ctx context.Context, inputApp string, maxAmount in
3371333721

3371433722
return returnActions
3371533723
}
33724+
33725+
func GetDockerClient() (*dockerclient.Client, string, error) {
33726+
ctx := context.Background()
33727+
dockerApiVersion := os.Getenv("DOCKER_API_VERSION")
33728+
cli, err := dockerclient.NewEnvClient()
33729+
if err != nil {
33730+
return nil, dockerApiVersion,err
33731+
}
33732+
33733+
_, err = cli.Info(ctx)
33734+
if err == nil {
33735+
return cli, dockerApiVersion,nil
33736+
}
33737+
33738+
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower("Minimum supported API version is")) {
33739+
re := regexp.MustCompile(`(?i)minimum supported api version is ([0-9\.]+)`)
33740+
match := re.FindStringSubmatch(err.Error())
33741+
if len(match) == 2 {
33742+
required := match[1]
33743+
os.Setenv("DOCKER_API_VERSION", required)
33744+
cli, err = dockerclient.NewEnvClient()
33745+
if err == nil {
33746+
dockerApiVersion = required
33747+
_, err = cli.Info(ctx)
33748+
return cli, dockerApiVersion, err
33749+
}
33750+
}
33751+
}
33752+
33753+
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower("Maximum supported API version is")) {
33754+
re := regexp.MustCompile(`(?i)maximum supported api version is ([0-9\.]+)`)
33755+
match := re.FindStringSubmatch(err.Error())
33756+
if len(match) == 2 {
33757+
required := match[1]
33758+
os.Setenv("DOCKER_API_VERSION", required)
33759+
cli, err = dockerclient.NewEnvClient()
33760+
if err == nil {
33761+
dockerApiVersion = required
33762+
_, err = cli.Info(ctx)
33763+
return cli, dockerApiVersion, err
33764+
}
33765+
}
33766+
}
33767+
33768+
return cli, dockerApiVersion, err
33769+
}

0 commit comments

Comments
 (0)