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
Member

This solves coop-cloud/organising#235

To execute commands after each abra app deploy add the env:
POST_DEPLOY_CMDS="<container> <command> <arguments>|<container> <command2> <arguments2>|... "
To execute commands after each abra app upgrade add the env:
POST_UPGRADE_CMDS="<container> <command> <arguments>|..."

It is important that the health checks are working correctly and the timeout is high enough, because the commands are only executed after the services converged successfully.

This solves https://git.coopcloud.tech/coop-cloud/organising/issues/235 To execute commands after each `abra app deploy` add the env: `POST_DEPLOY_CMDS="<container> <command> <arguments>|<container> <command2> <arguments2>|... "` To execute commands after each `abra app upgrade` add the env: `POST_UPGRADE_CMDS="<container> <command> <arguments>|..."` It is important that the health checks are working correctly and the timeout is high enough, because the commands are only executed after the services converged successfully.
decentral1se reviewed 2023-04-14 11:38:02 +00:00
decentral1se left a comment
Owner

LGTM! Some minor comments. Can you also throw up some docs for this new functionality as well? Thanks!

LGTM! Some minor comments. Can you also throw up some docs for this new functionality as well? Thanks!
@ -207,1 +207,4 @@
postDeployCmds, ok := app.Env["POST_UPGRADE_CMDS"]
if ok && !internal.DontWaitConverge {
logrus.Debugf("Run the following post-deploy commands: %s", postDeployCmds)
Owner

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

nitpick: `Run` -> `run` since the rest of the codebase uses lowercase
moritz marked this conversation as resolved
@ -208,0 +209,4 @@
if ok && !internal.DontWaitConverge {
logrus.Debugf("Run the following post-deploy commands: %s", postDeployCmds)
if err := internal.PostCmds(cl, app, postDeployCmds); err != nil {
logrus.Fatal(err)
Owner

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

`logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)`?
moritz marked this conversation as resolved
@ -7,2 +20,4 @@
"github.com/sirupsen/logrus"
)
func RunCmdRemote(cl *dockerClient.Client, app config.App, abraSh, serviceName, cmdName, cmdArgs string) error {
Owner

Missing docstring?

Missing docstring?
moritz marked this conversation as resolved
@ -8,1 +22,4 @@
func RunCmdRemote(cl *dockerClient.Client, app config.App, abraSh, serviceName, cmdName, cmdArgs string) error {
filters := filters.NewArgs()
filters.Add("name", fmt.Sprintf("^%s_%s", app.StackName(), serviceName))
Owner

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.
Author
Member

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.
moritz marked this conversation as resolved
@ -166,1 +167,4 @@
postDeployCmds, ok := app.Env["POST_DEPLOY_CMDS"]
if ok && !DontWaitConverge {
logrus.Debugf("Run the following post-deploy commands: %s", postDeployCmds)
Owner

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

nitpick: Run -> run since the rest of the codebase uses lowercase
moritz marked this conversation as resolved
@ -167,0 +169,4 @@
if ok && !DontWaitConverge {
logrus.Debugf("Run the following post-deploy commands: %s", postDeployCmds)
if err := PostCmds(cl, app, postDeployCmds); err != nil {
logrus.Fatal(err)
Owner

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

logrus.Fatalf("attempting to run post deploy commands, saw: %s", err)?
moritz marked this conversation as resolved
@ -167,0 +176,4 @@
return nil
}
func PostCmds(cl *dockerClient.Client, app config.App, commands string) error {
Owner

Missing doc string?

Missing doc string?
moritz marked this conversation as resolved
@ -167,0 +196,4 @@
if len(commandParts) > 2 {
parsedCmdArgs = fmt.Sprintf("%s ", strings.Join(commandParts[2:], " "))
}
logrus.Infof("Running post-command '%s %s' in container %s", cmdName, parsedCmdArgs, targetServiceName)
Owner

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

nitpick: Running -> running since the rest of the codebase uses lowercase
moritz marked this conversation as resolved
moritz force-pushed post_deploy_cmds from 6c993e812c to 14bdb57ac7 2023-04-14 12:33:42 +00:00 Compare
moritz added 1 commit 2023-04-14 12:37:18 +00:00
resolve PR review
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
0845fcf78c
moritz added 1 commit 2023-04-14 13:30:24 +00:00
fix drone building
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
a96f7d39cb
moritz added 1 commit 2023-04-14 13:54:56 +00:00
fix drone building
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
a0eb70879d
Author
Member
Some docs: https://docs.coopcloud.tech/maintainers/handbook/#global-environment-variables
moritz merged commit 18615eaaef into main 2023-04-14 14:12:32 +00:00
moritz deleted branch post_deploy_cmds 2023-04-14 14:12:37 +00:00
Sign in to join this conversation.
No description provided.