feat(deploy): set timeout via label
This commit is contained in:
parent
18615eaaef
commit
baaf8d224e
|
@ -3,6 +3,7 @@ package app
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
|
@ -201,6 +202,15 @@ recipes.
|
|||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
timeoutLabel := config.GetLabel(compose, stackName, "timeout")
|
||||
if timeoutLabel != "" {
|
||||
stack.WaitTimeout, err = strconv.Atoi(timeoutLabel)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
logrus.Debugf("Set waiting timeout to %s s", timeoutLabel)
|
||||
}
|
||||
|
||||
if err := stack.RunDeploy(cl, deployOpts, compose, stackName, internal.DontWaitConverge); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
|
@ -161,6 +162,15 @@ func DeployAction(c *cli.Context) error {
|
|||
logrus.Warn("skipping domain checks as requested")
|
||||
}
|
||||
|
||||
timeoutLabel := config.GetLabel(compose, stackName, "timeout")
|
||||
if timeoutLabel != "" {
|
||||
stack.WaitTimeout, err = strconv.Atoi(timeoutLabel)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
logrus.Debugf("Set waiting timeout to %s s", timeoutLabel)
|
||||
}
|
||||
|
||||
if err := stack.RunDeploy(cl, deployOpts, compose, app.Name, DontWaitConverge); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ update chaos deployments use the "--chaos" flag. Use it with care.
|
|||
},
|
||||
}
|
||||
|
||||
// getLabel reads docker labels in the format of "coop-cloud.${STACK_NAME}.${LABEL}".
|
||||
// getLabel reads docker labels from running services in the format of "coop-cloud.${STACK_NAME}.${LABEL}".
|
||||
func getLabel(cl *dockerclient.Client, stackName string, label string) (string, error) {
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("label", fmt.Sprintf("%s=%s", convert.LabelNamespace, stackName))
|
||||
|
@ -171,7 +171,7 @@ func getLabel(cl *dockerclient.Client, stackName string, label string) (string,
|
|||
return "", nil
|
||||
}
|
||||
|
||||
// getBoolLabel reads a boolean docker label.
|
||||
// getBoolLabel reads a boolean docker label from running services
|
||||
func getBoolLabel(cl *dockerclient.Client, stackName string, label string) (bool, error) {
|
||||
lableValue, err := getLabel(cl, stackName, label)
|
||||
if err != nil {
|
||||
|
@ -409,7 +409,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string, conf *run
|
|||
}
|
||||
|
||||
if !updatesEnabled {
|
||||
logrus.Debugf("Don't update %s due to disabling auto updates or missing ENABLE_AUTO_UPDATE env.", stackName)
|
||||
logrus.Debugf("Don't update %s due to disabled auto updates or missing ENABLE_AUTO_UPDATE env.", stackName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -544,3 +544,18 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv AppEn
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getLabel reads docker labels in the format of "coop-cloud.${STACK_NAME}.${LABEL}" from the local compose files
|
||||
func GetLabel(compose *composetypes.Config, stackName string, label string) string {
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.%s", stackName, label)
|
||||
logrus.Debugf("get label '%s'", labelKey)
|
||||
if labelValue, ok := service.Deploy.Labels[labelKey]; ok {
|
||||
return labelValue
|
||||
}
|
||||
}
|
||||
}
|
||||
logrus.Debugf("no %s label found for %s", label, stackName)
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ const (
|
|||
ResolveImageNever = "never"
|
||||
)
|
||||
|
||||
var WaitTimeout int = 50
|
||||
|
||||
type StackStatus struct {
|
||||
Services []swarm.Service
|
||||
Err error
|
||||
|
@ -457,7 +459,7 @@ func WaitOnService(ctx context.Context, cl *dockerClient.Client, serviceID, appN
|
|||
|
||||
go io.Copy(ioutil.Discard, pipeReader)
|
||||
|
||||
timeout := 50 * time.Second
|
||||
timeout := time.Duration(WaitTimeout) * time.Second
|
||||
|
||||
select {
|
||||
case err := <-errChan:
|
||||
|
|
Loading…
Reference in New Issue