Skip to content

Commit

Permalink
fix: --shell option not working for all dockerized commands (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
boukeversteegh authored Mar 20, 2022
1 parent 3f9a502 commit 994e2e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ name: Compile and Test
on: [push]

jobs:
ShellTest:
strategy:
fail-fast: true
matrix:
command:
- go
- aws
- python
runs-on: ubuntu-latest
steps:
- name: Checkout Dockerized
uses: actions/checkout@v2
- name: Compile
run: bin/dockerized --compile
- name: "Test: dockerized --shell ${{matrix.command}}"
env:
COMMAND: "${{matrix.command}}"
run: |
bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | tee ~/shell.log
grep $(hostname) ~/shell.log
CompileAndTest:
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -40,6 +60,7 @@ jobs:
../bin/dockerized go version | grep "1.17.8"
shell: bash


# region windows
- if: runner.os == 'windows'
name: "dockerized --compile (cmd)"
Expand Down
7 changes: 4 additions & 3 deletions lib/dockerized.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func main() {
fmt.Printf("Opening shell in container for %s...\n", commandName)

if len(commandArgs) > 0 {
fmt.Printf("Ignoring arguments: %s\n", commandArgs[0])
fmt.Printf("Passing arguments to shell: %s\n", commandArgs)
}
}

Expand All @@ -145,12 +145,13 @@ func main() {
}
welcomeMessage = strings.ReplaceAll(welcomeMessage, "\\", "\\\\")

preferredShells := "bash zsh sh"
var cmdPrintWelcome = fmt.Sprintf("echo '%s'", color.YellowString(welcomeMessage))
var cmdLaunchShell = "$(which bash || which zsh || which sh || command -v bash || command -v zsh || command -v | head -n 1)"
var cmdLaunchShell = fmt.Sprintf("$(command -v %[1]s | head -n1 || which %[1]s | head -n1)", preferredShells)

runOptions.Environment = append(runOptions.Environment, "PS1="+ps1)
runOptions.Entrypoint = []string{"/bin/sh"}
runOptions.Command = []string{"-c", fmt.Sprintf("%s; %s", cmdPrintWelcome, cmdLaunchShell)}
runOptions.Command = []string{"-c", fmt.Sprintf("%s; %s \"%s\"", cmdPrintWelcome, cmdLaunchShell, strings.Join(commandArgs, "\" \""))}
}

if !contains(project.ServiceNames(), commandName) {
Expand Down

0 comments on commit 994e2e6

Please sign in to comment.