From 15de76a504c57b8ea105448559f81df699b3da12 Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:34:47 +0100 Subject: [PATCH 01/12] ensure shell can be started in various docker containers --- .github/workflows/test.yml | 15 +++++++++++++++ lib/dockerized.go | 7 ++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b7fb73..5592c17 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,6 +2,20 @@ name: Compile and Test on: [push] jobs: + ShellTest: + strategy: + matrix: + commands: + - go + - aws + - python + runs-on: ubuntu-latest + steps: + - name: Checkout Dockerized + uses: actions/checkout@v2 + - name: "Test: --shell {{matrix.command}}" + run: | + bin/dockerized --shell {{matrix.command}} -c 'echo $HOST_HOSTNAME' | grep $(hostname) CompileAndTest: runs-on: ${{ matrix.os }} strategy: @@ -40,6 +54,7 @@ jobs: ../bin/dockerized go version | grep "1.17.8" shell: bash + # region windows - if: runner.os == 'windows' name: "dockerized --compile (cmd)" diff --git a/lib/dockerized.go b/lib/dockerized.go index 9579a0c..2c29838 100644 --- a/lib/dockerized.go +++ b/lib/dockerized.go @@ -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) } } @@ -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) { From f87825db7f092df1e7ecb0ecd64d7bd75fc045b2 Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:38:07 +0100 Subject: [PATCH 02/12] pass matrix arg through env --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5592c17..49dfb0f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,11 @@ jobs: steps: - name: Checkout Dockerized uses: actions/checkout@v2 - - name: "Test: --shell {{matrix.command}}" + - name: "Test: --shell ${{matrix.command}}" + env: + COMMAND: "${{matrix.command}}" run: | - bin/dockerized --shell {{matrix.command}} -c 'echo $HOST_HOSTNAME' | grep $(hostname) + bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | grep $(hostname) CompileAndTest: runs-on: ${{ matrix.os }} strategy: From 5ac3934709e5b979b32a72f02973321ce158e0e7 Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:45:30 +0100 Subject: [PATCH 03/12] compile on host --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49dfb0f..0798c5c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,7 @@ jobs: env: COMMAND: "${{matrix.command}}" run: | + bin/dockerized --compile=host bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | grep $(hostname) CompileAndTest: runs-on: ${{ matrix.os }} From 59cfe5c266baf02a897b2c7e80179875cbc10f96 Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:45:54 +0100 Subject: [PATCH 04/12] Fix matrix variable --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0798c5c..fc4100e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: ShellTest: strategy: matrix: - commands: + command: - go - aws - python From 786177bbadea2bac6d223e641df3b0cb49dfa34a Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:46:43 +0100 Subject: [PATCH 05/12] Compile with docker --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc4100e..265777f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: env: COMMAND: "${{matrix.command}}" run: | - bin/dockerized --compile=host + bin/dockerized --compile bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | grep $(hostname) CompileAndTest: runs-on: ${{ matrix.os }} From 00425fff13d0c1d4290eb885f730c120b0bf39c7 Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:47:19 +0100 Subject: [PATCH 06/12] Improve naming --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 265777f..77b25d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,11 +13,12 @@ jobs: steps: - name: Checkout Dockerized uses: actions/checkout@v2 - - name: "Test: --shell ${{matrix.command}}" + - name: Compile + run: bin/dockerized --compile + - name: "Test: dockerized --shell" env: COMMAND: "${{matrix.command}}" run: | - bin/dockerized --compile bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | grep $(hostname) CompileAndTest: runs-on: ${{ matrix.os }} From b611905704dd80a67819427eb63a84041c5267fc Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:55:39 +0100 Subject: [PATCH 07/12] Sanity check that tests work --- lib/dockerized.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dockerized.go b/lib/dockerized.go index 2c29838..6b78060 100644 --- a/lib/dockerized.go +++ b/lib/dockerized.go @@ -145,7 +145,7 @@ func main() { } welcomeMessage = strings.ReplaceAll(welcomeMessage, "\\", "\\\\") - preferredShells := "bash zsh sh" + preferredShells := "zsh sh" var cmdPrintWelcome = fmt.Sprintf("echo '%s'", color.YellowString(welcomeMessage)) var cmdLaunchShell = fmt.Sprintf("$(command -v %[1]s | head -n1 || which %[1]s | head -n1)", preferredShells) From adcab560b5ecc9ad79877377102c627ceb8b16db Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 12:55:54 +0100 Subject: [PATCH 08/12] Sanity check that tests work --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77b25d6..4049d3f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ on: [push] jobs: ShellTest: strategy: + fail-fast: true matrix: command: - go From 7a944a7ccaa670625ba025f77a99694bd690b514 Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 13:03:16 +0100 Subject: [PATCH 09/12] Output shell test content --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4049d3f..a83b5cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: env: COMMAND: "${{matrix.command}}" run: | - bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | grep $(hostname) + bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | tee ~/shell.log | grep $(hostname) || cat ~/shell.log CompileAndTest: runs-on: ${{ matrix.os }} strategy: From 3cd6a6bcc7f8e1058f971eb764bfa682377f3b1c Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 13:03:56 +0100 Subject: [PATCH 10/12] Set name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a83b5cc..c3823e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v2 - name: Compile run: bin/dockerized --compile - - name: "Test: dockerized --shell" + - name: "Test: dockerized --shell ${{matrix.command}}" env: COMMAND: "${{matrix.command}}" run: | From 67b3978477c8fb1de9ed4576ce826e17e459b89a Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 13:08:00 +0100 Subject: [PATCH 11/12] Print log and test for contents after --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c3823e8..31ce5b4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,8 @@ jobs: env: COMMAND: "${{matrix.command}}" run: | - bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | tee ~/shell.log | grep $(hostname) || cat ~/shell.log + bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | tee ~/shell.log + grep $(hostname) ~/shell.log CompileAndTest: runs-on: ${{ matrix.os }} strategy: From d7642c3f86d6a8f2d67dd80f8c7d81faa589475a Mon Sep 17 00:00:00 2001 From: Bouke Versteegh Date: Sun, 20 Mar 2022 13:10:34 +0100 Subject: [PATCH 12/12] Revert intentional breaking --- lib/dockerized.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dockerized.go b/lib/dockerized.go index 6b78060..2c29838 100644 --- a/lib/dockerized.go +++ b/lib/dockerized.go @@ -145,7 +145,7 @@ func main() { } welcomeMessage = strings.ReplaceAll(welcomeMessage, "\\", "\\\\") - preferredShells := "zsh sh" + preferredShells := "bash zsh sh" var cmdPrintWelcome = fmt.Sprintf("echo '%s'", color.YellowString(welcomeMessage)) var cmdLaunchShell = fmt.Sprintf("$(command -v %[1]s | head -n1 || which %[1]s | head -n1)", preferredShells)