Post-deploy abra.sh hooks #292

Merged
moritz merged 5 commits from post_deploy_cmds into main 2023-04-14 14:12:33 +00:00
3 changed files with 9 additions and 5 deletions
Showing only changes of commit 0845fcf78c - Show all commits

View File

@ -207,9 +207,9 @@ recipes.
postDeployCmds, ok := app.Env["POST_UPGRADE_CMDS"]
if ok && !internal.DontWaitConverge {
logrus.Debugf("Run the following post-deploy commands: %s", postDeployCmds)
logrus.Debugf("run the following post-deploy commands: %s", postDeployCmds)
moritz marked this conversation as resolved
Review

nitpick: Run -> run since the rest of the codebase uses lowercase

nitpick: `Run` -> `run` since the rest of the codebase uses lowercase
if err := internal.PostCmds(cl, app, postDeployCmds); err != nil {
logrus.Fatal(err)
logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)
moritz marked this conversation as resolved
Review

logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)?

`logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)`?
}
}

View File

@ -20,6 +20,7 @@ import (
"github.com/sirupsen/logrus"
)
// RunCmdRemote executes an abra.sh command in the target service
moritz marked this conversation as resolved
Review

Missing docstring?

Missing docstring?
func RunCmdRemote(cl *dockerClient.Client, app config.App, abraSh, serviceName, cmdName, cmdArgs string) error {
filters := filters.NewArgs()
moritz marked this conversation as resolved
Review

I'd recommend using the app.Filters if possible due to the often bizarre handling of filters in the Docker API. You'd pass exactMatch = true which I think is more readable for our future selves.

I'd recommend using the `app.Filters` if possible due to the often bizarre handling of filters in the Docker API. You'd pass `exactMatch = true` which I think is more readable for our future selves.
Review

I just moved this function from cli/app/cmd.go without touching it.
I think app.Filters doesn't make sense here, because it filters for all services and in this case only a filter for serviceName is required.

I just moved this function from `cli/app/cmd.go` without touching it. I think `app.Filters` doesn't make sense here, because it filters for all services and in this case only a filter for `serviceName` is required.
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), serviceName))

View File

@ -167,15 +167,18 @@ func DeployAction(c *cli.Context) error {
postDeployCmds, ok := app.Env["POST_DEPLOY_CMDS"]
if ok && !DontWaitConverge {
logrus.Debugf("Run the following post-deploy commands: %s", postDeployCmds)
logrus.Debugf("run the following post-deploy commands: %s", postDeployCmds)
moritz marked this conversation as resolved
Review

nitpick: Run -> run since the rest of the codebase uses lowercase

nitpick: Run -> run since the rest of the codebase uses lowercase
if err := PostCmds(cl, app, postDeployCmds); err != nil {
logrus.Fatal(err)
logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)
moritz marked this conversation as resolved
Review

logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)?

logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)?
}
}
return nil
}
// PostCmds parses a string of commands and executes them inside of the respective services
moritz marked this conversation as resolved
Review

Missing doc string?

Missing doc string?
// the commands string must have the following format:
// "<service> <command> <arguments>|<service> <command> <arguments>|... "
func PostCmds(cl *dockerClient.Client, app config.App, commands string) error {
abraSh := path.Join(config.RECIPES_DIR, app.Recipe, "abra.sh")
if _, err := os.Stat(abraSh); err != nil {
@ -196,7 +199,7 @@ func PostCmds(cl *dockerClient.Client, app config.App, commands string) error {
if len(commandParts) > 2 {
moritz marked this conversation as resolved
Review

nitpick: Running -> running since the rest of the codebase uses lowercase

nitpick: Running -> running since the rest of the codebase uses lowercase
parsedCmdArgs = fmt.Sprintf("%s ", strings.Join(commandParts[2:], " "))
}
logrus.Infof("Running post-command '%s %s' in container %s", cmdName, parsedCmdArgs, targetServiceName)
logrus.Infof("running post-command '%s %s' in container %s", cmdName, parsedCmdArgs, targetServiceName)
if err := EnsureCommand(abraSh, app.Recipe, cmdName); err != nil {
return err