forked from toolshed/abra
		
	fix: handle StackName / Name correctly
This commit is contained in:
		| @ -133,10 +133,9 @@ can take some time. | ||||
| 				totalAppsCount++ | ||||
|  | ||||
| 				if status { | ||||
| 					stackName := app.StackName() | ||||
| 					status := "unknown" | ||||
| 					version := "unknown" | ||||
| 					if statusMeta, ok := statuses[stackName]; ok { | ||||
| 					if statusMeta, ok := statuses[app.StackName()]; ok { | ||||
| 						if currentVersion, exists := statusMeta["version"]; exists { | ||||
| 							version = currentVersion | ||||
| 						} | ||||
| @ -191,7 +190,7 @@ can take some time. | ||||
|  | ||||
| 				appStats.server = app.Server | ||||
| 				appStats.recipe = app.Type | ||||
| 				appStats.appName = app.StackName() | ||||
| 				appStats.appName = app.Name | ||||
| 				appStats.domain = app.Domain | ||||
|  | ||||
| 				stats.apps = append(stats.apps, appStats) | ||||
|  | ||||
| @ -175,7 +175,7 @@ recipes. | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if err := stack.RunDeploy(cl, deployOpts, compose, app.Type, internal.DontWaitConverge); err != nil { | ||||
| 		if err := stack.RunDeploy(cl, deployOpts, compose, app.StackName(), internal.DontWaitConverge); err != nil { | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
|  | ||||
|  | ||||
| @ -35,7 +35,7 @@ volumes as eligiblef or pruning once undeployed. | ||||
| 		} | ||||
|  | ||||
| 		if !isDeployed { | ||||
| 			logrus.Fatalf("%s is not deployed?", stackName) | ||||
| 			logrus.Fatalf("%s is not deployed?", app.Name) | ||||
| 		} | ||||
|  | ||||
| 		if err := internal.DeployOverview(app, deployedVersion, "continue with undeploy?"); err != nil { | ||||
|  | ||||
| @ -188,7 +188,7 @@ recipes. | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
|  | ||||
| 		if err := stack.RunDeploy(cl, deployOpts, compose, app.Type, internal.DontWaitConverge); err != nil { | ||||
| 		if err := stack.RunDeploy(cl, deployOpts, compose, app.StackName(), internal.DontWaitConverge); err != nil { | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
|  | ||||
|  | ||||
| @ -23,7 +23,6 @@ import ( | ||||
| // DeployAction is the main command-line action for this package | ||||
| func DeployAction(c *cli.Context) error { | ||||
| 	app := ValidateApp(c) | ||||
| 	stackName := app.StackName() | ||||
|  | ||||
| 	if err := recipe.EnsureUpToDate(app.Type); err != nil { | ||||
| 		logrus.Fatal(err) | ||||
| @ -43,18 +42,18 @@ func DeployAction(c *cli.Context) error { | ||||
| 		logrus.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	logrus.Debugf("checking whether %s is already deployed", stackName) | ||||
| 	logrus.Debugf("checking whether %s is already deployed", app.StackName()) | ||||
|  | ||||
| 	isDeployed, deployedVersion, err := stack.IsDeployed(c.Context, cl, stackName) | ||||
| 	isDeployed, deployedVersion, err := stack.IsDeployed(c.Context, cl, app.StackName()) | ||||
| 	if err != nil { | ||||
| 		logrus.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	if isDeployed { | ||||
| 		if Force || Chaos { | ||||
| 			logrus.Warnf("%s is already deployed but continuing (--force/--chaos)", stackName) | ||||
| 			logrus.Warnf("%s is already deployed but continuing (--force/--chaos)", app.Name) | ||||
| 		} else { | ||||
| 			logrus.Fatalf("%s is already deployed", stackName) | ||||
| 			logrus.Fatalf("%s is already deployed", app.Name) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @ -124,7 +123,7 @@ func DeployAction(c *cli.Context) error { | ||||
| 	} | ||||
| 	deployOpts := stack.Deploy{ | ||||
| 		Composefiles: composeFiles, | ||||
| 		Namespace:    stackName, | ||||
| 		Namespace:    app.StackName(), | ||||
| 		Prune:        false, | ||||
| 		ResolveImage: stack.ResolveImageAlways, | ||||
| 	} | ||||
| @ -151,7 +150,7 @@ func DeployAction(c *cli.Context) error { | ||||
| 		logrus.Warn("skipping domain checks as requested") | ||||
| 	} | ||||
|  | ||||
| 	if err := stack.RunDeploy(cl, deployOpts, compose, app.Env["TYPE"], DontWaitConverge); err != nil { | ||||
| 	if err := stack.RunDeploy(cl, deployOpts, compose, app.Name, DontWaitConverge); err != nil { | ||||
| 		logrus.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| @ -173,7 +172,7 @@ func DeployOverview(app config.App, version, message string) error { | ||||
| 		server = "local" | ||||
| 	} | ||||
|  | ||||
| 	table.Append([]string{server, deployConfig, app.Domain, app.StackName(), version}) | ||||
| 	table.Append([]string{server, deployConfig, app.Domain, app.Name, version}) | ||||
| 	table.Render() | ||||
|  | ||||
| 	if NoInput { | ||||
| @ -211,7 +210,7 @@ func NewVersionOverview(app config.App, currentVersion, newVersion, releaseNotes | ||||
| 		server = "local" | ||||
| 	} | ||||
|  | ||||
| 	table.Append([]string{server, deployConfig, app.Domain, app.StackName(), currentVersion, newVersion}) | ||||
| 	table.Append([]string{server, deployConfig, app.Domain, app.Name, currentVersion, newVersion}) | ||||
| 	table.Render() | ||||
|  | ||||
| 	if releaseNotes == "" { | ||||
|  | ||||
| @ -43,13 +43,17 @@ type App struct { | ||||
| 	Path   string | ||||
| } | ||||
|  | ||||
| // StackName gets what the docker safe stack name is for the app | ||||
| // StackName gets what the docker safe stack name is for the app. This should | ||||
| // not not shown to the user, use a.Name for that. Give the output of this | ||||
| // command to Docker only. | ||||
| func (a App) StackName() string { | ||||
| 	if _, exists := a.Env["STACK_NAME"]; exists { | ||||
| 		return a.Env["STACK_NAME"] | ||||
| 	} | ||||
|  | ||||
| 	stackName := SanitiseAppName(a.Name) | ||||
| 	a.Env["STACK_NAME"] = stackName | ||||
|  | ||||
| 	return stackName | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -158,7 +158,7 @@ func pruneServices(ctx context.Context, cl *dockerclient.Client, namespace conve | ||||
| } | ||||
|  | ||||
| // RunDeploy is the swarm implementation of docker stack deploy | ||||
| func RunDeploy(cl *dockerclient.Client, opts Deploy, cfg *composetypes.Config, recipeName string, dontWait bool) error { | ||||
| func RunDeploy(cl *dockerclient.Client, opts Deploy, cfg *composetypes.Config, appName string, dontWait bool) error { | ||||
| 	ctx := context.Background() | ||||
|  | ||||
| 	if err := validateResolveImageFlag(&opts); err != nil { | ||||
| @ -170,7 +170,7 @@ func RunDeploy(cl *dockerclient.Client, opts Deploy, cfg *composetypes.Config, r | ||||
| 		opts.ResolveImage = ResolveImageNever | ||||
| 	} | ||||
|  | ||||
| 	return deployCompose(ctx, cl, opts, cfg, recipeName, dontWait) | ||||
| 	return deployCompose(ctx, cl, opts, cfg, appName, dontWait) | ||||
| } | ||||
|  | ||||
| // validateResolveImageFlag validates the opts.resolveImage command line option | ||||
| @ -183,7 +183,7 @@ func validateResolveImageFlag(opts *Deploy) error { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func deployCompose(ctx context.Context, cl *dockerclient.Client, opts Deploy, config *composetypes.Config, recipeName string, dontWait bool) error { | ||||
| func deployCompose(ctx context.Context, cl *dockerclient.Client, opts Deploy, config *composetypes.Config, appName string, dontWait bool) error { | ||||
| 	namespace := convert.NewNamespace(opts.Namespace) | ||||
|  | ||||
| 	if opts.Prune { | ||||
| @ -224,7 +224,7 @@ func deployCompose(ctx context.Context, cl *dockerclient.Client, opts Deploy, co | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return deployServices(ctx, cl, services, namespace, opts.SendRegistryAuth, opts.ResolveImage, recipeName, dontWait) | ||||
| 	return deployServices(ctx, cl, services, namespace, opts.SendRegistryAuth, opts.ResolveImage, appName, dontWait) | ||||
| } | ||||
|  | ||||
| func getServicesDeclaredNetworks(serviceConfigs []composetypes.ServiceConfig) map[string]struct{} { | ||||
| @ -340,7 +340,7 @@ func deployServices( | ||||
| 	namespace convert.Namespace, | ||||
| 	sendAuth bool, | ||||
| 	resolveImage string, | ||||
| 	recipeName string, | ||||
| 	appName string, | ||||
| 	dontWait bool) error { | ||||
| 	existingServices, err := GetStackServices(ctx, cl, namespace.Name()) | ||||
| 	if err != nil { | ||||
| @ -437,9 +437,9 @@ func deployServices( | ||||
| 	ch := make(chan error, len(serviceIDs)) | ||||
| 	for serviceID, serviceName := range serviceIDs { | ||||
| 		logrus.Debugf("waiting on %s to converge", serviceName) | ||||
| 		go func(sID, sName, rName string) { | ||||
| 			ch <- waitOnService(ctx, cl, sID, sName, rName) | ||||
| 		}(serviceID, serviceName, recipeName) | ||||
| 		go func(sID, sName, aName string) { | ||||
| 			ch <- WaitOnService(ctx, cl, sID, aName) | ||||
| 		}(serviceID, serviceName, appName) | ||||
| 	} | ||||
|  | ||||
| 	for _, serviceID := range serviceIDs { | ||||
| @ -469,7 +469,7 @@ func getStackConfigs(ctx context.Context, dockerclient client.APIClient, namespa | ||||
|  | ||||
| // https://github.com/docker/cli/blob/master/cli/command/service/helpers.go | ||||
| // https://github.com/docker/cli/blob/master/cli/command/service/progress/progress.go | ||||
| func waitOnService(ctx context.Context, cl *dockerclient.Client, serviceID, serviceName, recipeName string) error { | ||||
| func WaitOnService(ctx context.Context, cl *dockerclient.Client, serviceID, appName string) error { | ||||
| 	errChan := make(chan error, 1) | ||||
| 	pipeReader, pipeWriter := io.Pipe() | ||||
|  | ||||
| @ -498,8 +498,8 @@ If a service is failing to even start (run "abra app ps %s" to see what | ||||
| services are running) there could be a few things. The follow command will | ||||
| try to smoke those out for you: | ||||
|  | ||||
|     abra app errors %s | ||||
|     abra app errors --watch %s | ||||
|  | ||||
| `, recipeName, timeout, recipeName, recipeName, recipeName)) | ||||
| `, appName, timeout, appName, appName, appName)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user