Skip to content

Commit

Permalink
Fix interactive shell command keepalive task
Browse files Browse the repository at this point in the history
These stopped working at some point because the $(...) commands were
getting evaluated immediately instead of within the for loop. Avoiding
the double shell wrapper for buildpacks fixes this.
  • Loading branch information
ipmb committed Mar 25, 2023
1 parent 9fb7242 commit bc4364d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ var maxLifetime = 12 * 60 * 60
var waitForConnect = 60

var ShellBackgroundCommand = []string{
"/bin/sh",
"-c",
strings.Join([]string{
"STOP=$(($(date +%s)+" + fmt.Sprintf("%d", maxLifetime) + "))",
// Give user time to connect
Expand Down
2 changes: 1 addition & 1 deletion cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var dbShellCmd = &cobra.Command{
checkErr(err)
family, exec, err := a.DBShellTaskInfo()
checkErr(err)
StartInteractiveShell(a, family, aws.String(fmt.Sprintf("entrypoint.sh %s", *exec)), &ecs.TaskOverride{})
StartInteractiveShell(a, family, aws.String(fmt.Sprintf("entrypoint.sh %s", *exec)), []string{"/bin/sh", "-c"}, &ecs.TaskOverride{})
},
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func WaitForTaskRunning(a *app.App, task *ecs.Task) error {
return nil
}

func StartInteractiveShell(a *app.App, taskFamily, shellCmd *string, taskOverride *ecs.TaskOverride) {
func StartInteractiveShell(a *app.App, taskFamily, shellCmd *string, taskCommandPrefix []string, taskOverride *ecs.TaskOverride) {
task, err := a.StartTask(
taskFamily,
app.ShellBackgroundCommand,
append(taskCommandPrefix, app.ShellBackgroundCommand...),
taskOverride,
false,
)
Expand Down Expand Up @@ -128,7 +128,7 @@ func interactiveCmd(a *app.App, cmd string) {
checkErr(a.ValidateECSTaskSize(*size))
isBuildpack := *buildSystem == "buildpacks" || *buildSystem == ""
exec := cmd
if isBuildpack && !shellRoot{
if isBuildpack && !shellRoot {
exec = fmt.Sprintf("su --preserve-environment --pty --command '/cnb/lifecycle/launcher %s' heroku", cmd)
} else if !isBuildpack && shellRoot {
checkErr(fmt.Errorf("--root is only supported on the buildpack build system"))
Expand Down Expand Up @@ -170,7 +170,12 @@ func interactiveCmd(a *app.App, cmd string) {
err = a.ConnectToEcsSession(ecsSession)
checkErr(err)
}
StartInteractiveShell(a, taskFamily, &exec, &ecs.TaskOverride{
var taskCommandPrefix []string
if !isBuildpack {
// buildpacks already wrap commands in `bash -c`
taskCommandPrefix = []string{"/bin/sh", "-c"}
}
StartInteractiveShell(a, taskFamily, &exec, taskCommandPrefix, &ecs.TaskOverride{
Cpu: aws.String(fmt.Sprintf("%d", size.CPU)),
Memory: aws.String(fmt.Sprintf("%d", size.Memory)),
})
Expand Down

0 comments on commit bc4364d

Please sign in to comment.