Skip to content

Commit

Permalink
wip - halfpipe exec docker-compose tasks too
Browse files Browse the repository at this point in the history
  • Loading branch information
robwhitby committed Sep 27, 2023
1 parent 0f7e2ef commit 84653d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
37 changes: 32 additions & 5 deletions cmd/cmds/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ var execCmd = &cobra.Command{
os.Exit(1)
}

found, task := man.Tasks.GetRunTask(taskName)
if !found {
printErr(fmt.Errorf("run task not found '%s'", taskName))
task := man.Tasks.GetTask(taskName)

switch t := task.(type) {
case manifest.Run:
fmt.Println(renderRunCommand(t, man.Team))
case manifest.DockerCompose:
fmt.Println(renderDockerComposeCommand(t, man.Team))
default:
printErr(fmt.Errorf("task not found with name '%s' and type 'run' or 'docker-compose'", taskName))
os.Exit(1)
}
fmt.Println(renderShellCommand(task, man.Team))
},
}

func renderShellCommand(task manifest.Run, team string) string {
func renderRunCommand(task manifest.Run, team string) string {
s := []string{
"docker run -it",
`-v "$PWD":/app`,
Expand All @@ -50,6 +55,28 @@ func renderShellCommand(task manifest.Run, team string) string {
return strings.Join(s, " \\ \n ")
}

func renderDockerComposeCommand(task manifest.DockerCompose, team string) string {
s := []string{
"docker compose",
fmt.Sprintf("-f %s", task.ComposeFile),
"run",
`-v "$PWD":/app`,
"-w /app",
}

for k, v := range task.Vars {
s = append(s, fmt.Sprintf("-e %s=%s", k, vaultLookup(v, team)))
}

s = append(s, "--use-aliases", task.Service)

if task.Command != "" {
s = append(s, task.Command)
}

return strings.Join(s, " \\ \n ")
}

func vaultLookup(s string, team string) string {
if !isSecret(s) {
return s
Expand Down
6 changes: 3 additions & 3 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func (tl TaskList) Flatten() (updated TaskList) {
return
}

func (tl TaskList) GetRunTask(name string) (found bool, task Run) {
func (tl TaskList) GetTask(name string) Task {
for _, t := range tl.Flatten() {
if t.GetName() == name {
return true, t.(Run)
return t
}
}
return false, Run{}
return nil
}

func (tl TaskList) PreviousTaskNames(currentIndex int) []string {
Expand Down

0 comments on commit 84653d8

Please sign in to comment.