Skip to content

Commit

Permalink
Execute start hook if defined in cloudbin image (#1552)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
  • Loading branch information
pchico83 committed May 20, 2021
1 parent 92b1899 commit e27561d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
15 changes: 12 additions & 3 deletions cmd/up/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ func (up *upContext) activate(autoDeploy, build bool) error {
log.Debugf("clean command output: %s", output)

outByCommand := strings.Split(strings.TrimSpace(output), "\n")
if len(outByCommand) >= 2 {
version, watches := outByCommand[0], outByCommand[1]
var version, watches, hook string
if len(outByCommand) >= 3 {
version, watches, hook = outByCommand[0], outByCommand[1], outByCommand[2]

if isWatchesConfigurationTooLow(watches) {
folder := config.GetNamespaceHome(up.Dev.Namespace)
Expand All @@ -147,6 +148,7 @@ func (up *upContext) activate(autoDeploy, build bool) error {
log.Yellow("Please consider upgrading your init container image %s with the content of %s", up.Dev.InitContainer.Image, model.OktetoBinImageTag)
log.Infof("Using init image %s instead of default init image (%s)", up.Dev.InitContainer.Image, model.OktetoBinImageTag)
}

}
divertURL := ""
if up.Dev.Divert != nil {
Expand All @@ -160,7 +162,14 @@ func (up *upContext) activate(autoDeploy, build bool) error {
}
}
printDisplayContext(up.Dev, divertURL)
up.CommandResult <- up.runCommand(ctx)
if hook == "yes" {
log.Information("Running start.sh hook...")
if err := up.runCommand(ctx, []string{"/var/okteto/cloudbin/start.sh"}); err != nil {
up.CommandResult <- err
return
}
}
up.CommandResult <- up.runCommand(ctx, up.Dev.Command.Values)
}()
prevError := up.waitUntilExitOrInterrupt()

Expand Down
8 changes: 4 additions & 4 deletions cmd/up/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (up *upContext) cleanCommand(ctx context.Context) {
in := strings.NewReader("\n")
var out bytes.Buffer

cmd := "cat /var/okteto/bin/version.txt; cat /proc/sys/fs/inotify/max_user_watches; /var/okteto/bin/clean >/dev/null 2>&1"
cmd := "cat /var/okteto/bin/version.txt; cat /proc/sys/fs/inotify/max_user_watches; [ -f /var/okteto/cloudbin/start.sh ] && echo yes || echo no; /var/okteto/bin/clean >/dev/null 2>&1"

err := exec.Exec(
ctx,
Expand All @@ -42,14 +42,14 @@ func (up *upContext) cleanCommand(ctx context.Context) {
up.cleaned <- out.String()
}

func (up *upContext) runCommand(ctx context.Context) error {
func (up *upContext) runCommand(ctx context.Context, cmd []string) error {
log.Infof("starting remote command")
if err := config.UpdateStateFile(up.Dev, config.Ready); err != nil {
return err
}

if up.Dev.RemoteModeEnabled() {
return ssh.Exec(ctx, up.Dev.Interface, up.Dev.RemotePort, true, os.Stdin, os.Stdout, os.Stderr, up.Dev.Command.Values)
return ssh.Exec(ctx, up.Dev.Interface, up.Dev.RemotePort, true, os.Stdin, os.Stdout, os.Stderr, cmd)
}

return exec.Exec(
Expand All @@ -63,7 +63,7 @@ func (up *upContext) runCommand(ctx context.Context) error {
os.Stdin,
os.Stdout,
os.Stderr,
up.Dev.Command.Values,
cmd,
)
}

Expand Down
2 changes: 1 addition & 1 deletion integration/stacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestCompose(t *testing.T) {
if err := deployStack(ctx, oktetoPath, "docker-compose.yml", composeGitFolder); err != nil {
t.Fatal(err)
}
log.Println("Stack has been redeployed succesfully")
log.Println("Stack has been redeployed successfully")

if err := destroyStack(ctx, oktetoPath, "docker-compose.yml", composeGitFolder); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit e27561d

Please sign in to comment.