From b6a038af0524dd11548518d7caa3d4e62d6bfc63 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 3 May 2024 16:34:40 +0100 Subject: [PATCH 01/14] Updated github ssh keys --- Dockerfile | 2 +- terragrunt/Dockerfile | 2 +- terragrunt/known_hosts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d5f49cd..4a557ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Dockerfile used in execution of Github Action FROM gruntwork/terragrunt:0.2.0 -LABEL maintainer "Gruntwork " +LABEL maintainer="Gruntwork " ENV MISE_CONFIG_DIR=~/.config/mise ENV MISE_STATE_DIR=~/.local/state/mise diff --git a/terragrunt/Dockerfile b/terragrunt/Dockerfile index 1e3acf4..0fb6a88 100644 --- a/terragrunt/Dockerfile +++ b/terragrunt/Dockerfile @@ -1,7 +1,7 @@ # Container to run Terragrunt and Terraform # Contains inside mise to allow users to install custom Terraform and Terragrunt versions FROM ubuntu:22.04 -LABEL maintainer "Gruntwork " +LABEL maintainer="Gruntwork " ARG MISE_VERSION_INSTALL=v2024.4.0 diff --git a/terragrunt/known_hosts b/terragrunt/known_hosts index 77a3f00..8e58cb4 100644 --- a/terragrunt/known_hosts +++ b/terragrunt/known_hosts @@ -1,3 +1,5 @@ gitlab.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9 github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk= bitbucket.com,bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw== +github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl +github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg= \ No newline at end of file From 6006d34a933f6d853a228f633cfb3a6c6476b1f1 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 3 May 2024 16:37:56 +0100 Subject: [PATCH 02/14] Spacing update --- terragrunt/known_hosts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terragrunt/known_hosts b/terragrunt/known_hosts index 8e58cb4..9f63205 100644 --- a/terragrunt/known_hosts +++ b/terragrunt/known_hosts @@ -2,4 +2,4 @@ gitlab.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgM github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk= bitbucket.com,bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw== github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl -github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg= \ No newline at end of file +github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg= From 13f583df58dfd8b731f3d593110ab37d00e25a98 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 6 May 2024 18:53:03 +0100 Subject: [PATCH 03/14] Fixed passing of SSH keys --- src/main.sh | 7 ++ terragrunt/Dockerfile | 6 +- test/action_run_test.go | 88 +++++++++++-------- .../terragrunt.hcl | 7 ++ 4 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 test/fixture-action-execution-ssh/terragrunt.hcl diff --git a/src/main.sh b/src/main.sh index 1cfd9a6..abcb8f7 100755 --- a/src/main.sh +++ b/src/main.sh @@ -255,4 +255,11 @@ ${terragrunt_output} exit $exit_code } +pwd +whoami +cat /root/.ssh/known_hosts +mkdir -p /tmp/qwe + +git clone git@github.com:gruntwork-io/terragrunt.git /tmp/qwe + main "$@" diff --git a/terragrunt/Dockerfile b/terragrunt/Dockerfile index 0fb6a88..8584907 100644 --- a/terragrunt/Dockerfile +++ b/terragrunt/Dockerfile @@ -16,9 +16,9 @@ RUN apt-get update \ sudo \ && rm -rf /var/lib/apt/lists/* -RUN mkdir -p /home/runner/.ssh -COPY ./known_hosts /home/runner/.ssh/known_hosts - +RUN mkdir -p /root/.ssh +COPY ./known_hosts /root/.ssh/known_hosts +RUN chown -R root:root /root/.ssh # install mise RUN wget -q "https://github.com/jdx/mise/releases/download/${MISE_VERSION_INSTALL}/mise-${MISE_VERSION_INSTALL}-linux-x64" -O "/usr/bin/mise" \ && chmod +x "/usr/bin/mise" diff --git a/test/action_run_test.go b/test/action_run_test.go index 87a27eb..386a286 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -17,10 +17,10 @@ func TestTerragruntAction(t *testing.T) { tag := buildActionImage(t) testCases := []struct { - iac_name string - iac_type string - iac_version string - tg_version string + iacName string + iacType string + iacVersion string + tgVersion string }{ {"Terraform", "TF", "1.4.6", "0.46.3"}, {"OpenTofu", "TOFU", "1.6.0", "0.53.3"}, @@ -29,86 +29,100 @@ func TestTerragruntAction(t *testing.T) { for _, tc := range testCases { tc := tc - t.Run(tc.iac_name, func(t *testing.T) { + t.Run(tc.iacName, func(t *testing.T) { t.Parallel() t.Run("testActionIsExecuted", func(t *testing.T) { t.Parallel() - testActionIsExecuted(t, tc.iac_type, tc.iac_name, tc.iac_version, tc.tg_version, tag) + testActionIsExecuted(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) + }) + t.Run("testActionIsExecutedSSHProject", func(t *testing.T) { + t.Parallel() + testActionIsExecutedSSHProject(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) }) t.Run("testOutputPlanIsUsedInApply", func(t *testing.T) { t.Parallel() - testOutputPlanIsUsedInApply(t, tc.iac_type, tc.iac_name, tc.iac_version, tc.tg_version, tag) + testOutputPlanIsUsedInApply(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) }) t.Run("testRunAllIsExecute", func(t *testing.T) { t.Parallel() - testRunAllIsExecuted(t, tc.iac_type, tc.iac_name, tc.iac_version, tc.tg_version, tag) + testRunAllIsExecuted(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) }) t.Run("testAutoApproveDelete", func(t *testing.T) { t.Parallel() - testAutoApproveDelete(t, tc.iac_type, tc.iac_name, tc.iac_version, tc.tg_version, tag) + testAutoApproveDelete(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) }) }) } } -func testActionIsExecuted(t *testing.T, iac_type string, iac_name string, iac_version string, tg_version string, tag string) { +func testActionIsExecuted(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { fixturePath := prepareFixture(t, "fixture-action-execution") - outputTF := runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "plan") - assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+iac_name) + outputTF := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "plan") + assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+iacName) +} + +func testActionIsExecutedSSHProject(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { + fixturePath := prepareFixture(t, "fixture-action-execution-ssh") + + outputTF := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "plan") + assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+iacName) } -func testOutputPlanIsUsedInApply(t *testing.T, iac_type string, iac_name string, iac_version string, tg_version string, tag string) { +func testOutputPlanIsUsedInApply(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { fixturePath := prepareFixture(t, "fixture-dependencies-project") - output := runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all plan -out=plan.out") - assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy") + output := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan -out=plan.out") + assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", iacName) - output = runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all apply plan.out") - assert.Contains(t, output, "1 added, 0 changed, 0 destroyed") + output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply plan.out") + assert.Contains(t, output, "1 added, 0 changed, 0 destroyed", iacName) } -func testRunAllIsExecuted(t *testing.T, iac_type string, iac_name string, iac_version string, tg_version string, tag string) { +func testRunAllIsExecuted(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { fixturePath := prepareFixture(t, "fixture-dependencies-project") - output := runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all plan") - assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy") + output := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan") + assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", iacName) - output = runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all apply") - assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy") + output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply") + assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", iacName) - output = runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all destroy") - assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy") - assert.Contains(t, output, "Destroy complete! Resources: 1 destroyed") + output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all destroy") + assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy", iacName) + assert.Contains(t, output, "Destroy complete! Resources: 1 destroyed", iacName) } -func testAutoApproveDelete(t *testing.T, iac_type string, iac_name string, iac_version string, tg_version string, tag string) { +func testAutoApproveDelete(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { fixturePath := prepareFixture(t, "fixture-dependencies-project") - output := runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all plan -out=plan.out") + output := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan -out=plan.out") assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy") - output = runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all apply plan.out") - assert.Contains(t, output, "1 added, 0 changed, 0 destroyed") + output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply plan.out") + assert.Contains(t, output, "1 added, 0 changed, 0 destroyed", iacName) // run destroy with auto-approve - output = runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all plan -destroy -out=destroy.out") - assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy") + output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan -destroy -out=destroy.out") + assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy", iacName) - output = runAction(t, tag, fixturePath, iac_type, iac_version, tg_version, "run-all apply -destroy destroy.out") - assert.Contains(t, output, "Resources: 0 added, 0 changed, 1 destroyed") + output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply -destroy destroy.out") + assert.Contains(t, output, "Resources: 0 added, 0 changed, 1 destroyed", iacName) } -func runAction(t *testing.T, tag, fixturePath, iac_type string, iac_version string, tg_version string, command string) string { +func runAction(t *testing.T, tag, fixturePath, iacType string, iacVersion string, tgVersion string, command string) string { opts := &docker.RunOptions{ EnvironmentVariables: []string{ - "INPUT_" + iac_type + "_VERSION=" + iac_version, - "INPUT_TG_VERSION=" + tg_version, + "INPUT_" + iacType + "_VERSION=" + iacVersion, + "INPUT_tgVersion=" + tgVersion, "INPUT_TG_COMMAND=" + command, "INPUT_TG_DIR=/github/workspace/code", "GITHUB_OUTPUT=/tmp/logs", }, - Volumes: []string{fixturePath + ":/github/workspace/code"}, + Volumes: []string{ + fixturePath + ":/github/workspace/code", + }, + Remove: true, } return docker.Run(t, tag, opts) } diff --git a/test/fixture-action-execution-ssh/terragrunt.hcl b/test/fixture-action-execution-ssh/terragrunt.hcl new file mode 100644 index 0000000..fa793d8 --- /dev/null +++ b/test/fixture-action-execution-ssh/terragrunt.hcl @@ -0,0 +1,7 @@ +inputs = { + name = "World" +} + +terraform { + source = "git::ssh://git@github.com:gruntwork-io/terragrunt.git//test/fixture-download/hello-world?ref=v0.9.9" +} From 05fb2f036bff2be80b1a94f6690c94fa2a51eb2b Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 7 May 2024 22:39:45 +0100 Subject: [PATCH 04/14] Add SSH agent container test --- src/main.sh | 7 --- test/action.go | 10 ++-- test/action_run_test.go | 111 ++++++++++++++++++++++++-------------- test/ssh-agent/Dockerfile | 11 ++++ 4 files changed, 88 insertions(+), 51 deletions(-) create mode 100644 test/ssh-agent/Dockerfile diff --git a/src/main.sh b/src/main.sh index abcb8f7..1cfd9a6 100755 --- a/src/main.sh +++ b/src/main.sh @@ -255,11 +255,4 @@ ${terragrunt_output} exit $exit_code } -pwd -whoami -cat /root/.ssh/known_hosts -mkdir -p /tmp/qwe - -git clone git@github.com:gruntwork-io/terragrunt.git /tmp/qwe - main "$@" diff --git a/test/action.go b/test/action.go index f1c6fa0..4a24064 100644 --- a/test/action.go +++ b/test/action.go @@ -7,11 +7,15 @@ import ( "github.com/gruntwork-io/terratest/modules/random" ) -func buildActionImage(t *testing.T) string { - tag := "terragrunt-action:" + random.UniqueId() +func buildImage(t *testing.T, tag, path string) { buildOptions := &docker.BuildOptions{ Tags: []string{tag}, } - docker.Build(t, "..", buildOptions) + docker.Build(t, path, buildOptions) +} + +func buildActionImage(t *testing.T) string { + tag := "terragrunt-action:" + random.UniqueId() + buildImage(t, tag, "..") return tag } diff --git a/test/action_run_test.go b/test/action_run_test.go index 386a286..b747fe9 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -12,16 +12,19 @@ import ( "github.com/stretchr/testify/assert" ) +type ActionConfig struct { + iacName string + iacType string + iacVersion string + tgVersion string +} + func TestTerragruntAction(t *testing.T) { t.Parallel() tag := buildActionImage(t) + buildImage(t, "ssh-agent:local", "ssh-agent") - testCases := []struct { - iacName string - iacType string - iacVersion string - tgVersion string - }{ + testCases := []ActionConfig{ {"Terraform", "TF", "1.4.6", "0.46.3"}, {"OpenTofu", "TOFU", "1.6.0", "0.53.3"}, } @@ -33,88 +36,109 @@ func TestTerragruntAction(t *testing.T) { t.Parallel() t.Run("testActionIsExecuted", func(t *testing.T) { t.Parallel() - testActionIsExecuted(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) + testActionIsExecuted(t, tc, tag) }) t.Run("testActionIsExecutedSSHProject", func(t *testing.T) { t.Parallel() - testActionIsExecutedSSHProject(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) + testActionIsExecutedSSHProject(t, tc, tag) }) t.Run("testOutputPlanIsUsedInApply", func(t *testing.T) { t.Parallel() - testOutputPlanIsUsedInApply(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) + testOutputPlanIsUsedInApply(t, tc, tag) }) t.Run("testRunAllIsExecute", func(t *testing.T) { t.Parallel() - testRunAllIsExecuted(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) + testRunAllIsExecuted(t, tc, tag) }) t.Run("testAutoApproveDelete", func(t *testing.T) { t.Parallel() - testAutoApproveDelete(t, tc.iacType, tc.iacName, tc.iacVersion, tc.tgVersion, tag) + testAutoApproveDelete(t, tc, tag) }) }) } } -func testActionIsExecuted(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { +func testActionIsExecuted(t *testing.T, actionConfig ActionConfig, tag string) { fixturePath := prepareFixture(t, "fixture-action-execution") - outputTF := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "plan") - assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+iacName) + outputTF := runAction(t, actionConfig, false, tag, fixturePath, "plan") + assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+actionConfig.iacName) } -func testActionIsExecutedSSHProject(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { +func testActionIsExecutedSSHProject(t *testing.T, actionConfig ActionConfig, tag string) { fixturePath := prepareFixture(t, "fixture-action-execution-ssh") - outputTF := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "plan") - assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+iacName) + outputTF := runAction(t, actionConfig, true, tag, fixturePath, "plan") + assert.Contains(t, outputTF, "You can apply this plan to save these new output values to the "+actionConfig.iacName) } -func testOutputPlanIsUsedInApply(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { +func testOutputPlanIsUsedInApply(t *testing.T, actionConfig ActionConfig, tag string) { fixturePath := prepareFixture(t, "fixture-dependencies-project") - output := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan -out=plan.out") - assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", iacName) + output := runAction(t, actionConfig, false, tag, fixturePath, "run-all plan -out=plan.out") + assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", actionConfig.iacName) - output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply plan.out") - assert.Contains(t, output, "1 added, 0 changed, 0 destroyed", iacName) + output = runAction(t, actionConfig, false, tag, fixturePath, "run-all apply plan.out") + assert.Contains(t, output, "1 added, 0 changed, 0 destroyed", actionConfig.iacName) } -func testRunAllIsExecuted(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { +func testRunAllIsExecuted(t *testing.T, actionConfig ActionConfig, tag string) { fixturePath := prepareFixture(t, "fixture-dependencies-project") - output := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan") - assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", iacName) + output := runAction(t, actionConfig, false, tag, fixturePath, "run-all plan") + assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", actionConfig.iacName) - output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply") - assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", iacName) + output = runAction(t, actionConfig, false, tag, fixturePath, "run-all apply") + assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy", actionConfig.iacName) - output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all destroy") - assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy", iacName) - assert.Contains(t, output, "Destroy complete! Resources: 1 destroyed", iacName) + output = runAction(t, actionConfig, false, tag, fixturePath, "run-all destroy") + assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy", actionConfig.iacName) + assert.Contains(t, output, "Destroy complete! Resources: 1 destroyed", actionConfig.iacName) } -func testAutoApproveDelete(t *testing.T, iacType string, iacName string, iacVersion string, tgVersion string, tag string) { +func testAutoApproveDelete(t *testing.T, actionConfig ActionConfig, tag string) { fixturePath := prepareFixture(t, "fixture-dependencies-project") - output := runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan -out=plan.out") + output := runAction(t, actionConfig, false, tag, fixturePath, "run-all plan -out=plan.out") assert.Contains(t, output, "1 to add, 0 to change, 0 to destroy") - output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply plan.out") - assert.Contains(t, output, "1 added, 0 changed, 0 destroyed", iacName) + output = runAction(t, actionConfig, false, tag, fixturePath, "run-all apply plan.out") + assert.Contains(t, output, "1 added, 0 changed, 0 destroyed", actionConfig.iacName) // run destroy with auto-approve - output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all plan -destroy -out=destroy.out") - assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy", iacName) + output = runAction(t, actionConfig, false, tag, fixturePath, "run-all plan -destroy -out=destroy.out") + assert.Contains(t, output, "0 to add, 0 to change, 1 to destroy", actionConfig.iacName) - output = runAction(t, tag, fixturePath, iacType, iacVersion, tgVersion, "run-all apply -destroy destroy.out") - assert.Contains(t, output, "Resources: 0 added, 0 changed, 1 destroyed", iacName) + output = runAction(t, actionConfig, false, tag, fixturePath, "run-all apply -destroy destroy.out") + assert.Contains(t, output, "Resources: 0 added, 0 changed, 1 destroyed", actionConfig.iacName) } -func runAction(t *testing.T, tag, fixturePath, iacType string, iacVersion string, tgVersion string, command string) string { +func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixturePath string, command string) string { + if sshAgent { + homeDir, err := os.UserHomeDir() + if err != nil { + assert.NoError(t, err) + } + sshPath := filepath.Join(homeDir, ".ssh") + + sshAgentID := docker.RunAndGetID(t, "ssh-agent:local", &docker.RunOptions{ + Remove: true, + EnvironmentVariables: []string{ + "SSH_AUTH_SOCK=/tmp/ssh-agent.sock", + }, + Volumes: []string{ + "ssh-agent:/tmp", + // add home from .ssh folder to container + sshPath + ":/root/.ssh", + }, + }) + defer docker.Stop(t, []string{sshAgentID}, &docker.StopOptions{}) + } + opts := &docker.RunOptions{ EnvironmentVariables: []string{ - "INPUT_" + iacType + "_VERSION=" + iacVersion, - "INPUT_tgVersion=" + tgVersion, + "INPUT_" + actionConfig.iacType + "_VERSION=" + actionConfig.iacVersion, + "INPUT_TG_VERSION=" + actionConfig.tgVersion, "INPUT_TG_COMMAND=" + command, "INPUT_TG_DIR=/github/workspace/code", "GITHUB_OUTPUT=/tmp/logs", @@ -124,6 +148,11 @@ func runAction(t *testing.T, tag, fixturePath, iacType string, iacVersion string }, Remove: true, } + if sshAgent { + // add ssh socket + opts.Volumes = append(opts.Volumes, "/tmp/ssh-agent.sock:/tmp/ssh-agent.sock") + opts.EnvironmentVariables = append(opts.EnvironmentVariables, "SSH_AUTH_SOCK=/tmp/ssh-agent.sock") + } return docker.Run(t, tag, opts) } diff --git a/test/ssh-agent/Dockerfile b/test/ssh-agent/Dockerfile new file mode 100644 index 0000000..df6f8e1 --- /dev/null +++ b/test/ssh-agent/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu:22.04 + +RUN apt-get update && \ + apt-get install -y openssh-client && \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir /ssh-agent + +ENV SSH_AUTH_SOCK /ssh-agent/socket + +CMD ["ssh-agent", "-a", "/ssh-agent/socket"] \ No newline at end of file From e64b417948d4fa53500ed9944f2a3cca8164fca7 Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 00:12:52 +0100 Subject: [PATCH 05/14] Add test for SSH client --- test/action_run_test.go | 48 ++++++++++--------- .../terragrunt.hcl | 2 +- test/ssh-agent/Dockerfile | 6 +-- test/ssh-agent/run.sh | 25 ++++++++++ 4 files changed, 54 insertions(+), 27 deletions(-) create mode 100755 test/ssh-agent/run.sh diff --git a/test/action_run_test.go b/test/action_run_test.go index b747fe9..f0e8199 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -1,10 +1,13 @@ package test import ( + "fmt" "os" "path/filepath" "testing" + "github.com/gruntwork-io/terratest/modules/random" + "github.com/gruntwork-io/terratest/modules/files" "github.com/stretchr/testify/require" @@ -114,6 +117,20 @@ func testAutoApproveDelete(t *testing.T, actionConfig ActionConfig, tag string) } func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixturePath string, command string) string { + + opts := &docker.RunOptions{ + EnvironmentVariables: []string{ + "INPUT_" + actionConfig.iacType + "_VERSION=" + actionConfig.iacVersion, + "INPUT_TG_VERSION=" + actionConfig.tgVersion, + "INPUT_TG_COMMAND=" + command, + "INPUT_TG_DIR=/github/workspace/code", + "GITHUB_OUTPUT=/tmp/logs", + }, + Volumes: []string{ + fixturePath + ":/github/workspace/code", + }, + } + if sshAgent { homeDir, err := os.UserHomeDir() if err != nil { @@ -121,37 +138,22 @@ func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixt } sshPath := filepath.Join(homeDir, ".ssh") + r := random.Random(1, 1000) + socketPath := fmt.Sprintf("/tmp/ssh-agent.sock.%d", r) sshAgentID := docker.RunAndGetID(t, "ssh-agent:local", &docker.RunOptions{ + Detach: true, Remove: true, EnvironmentVariables: []string{ - "SSH_AUTH_SOCK=/tmp/ssh-agent.sock", + "SSH_AUTH_SOCK=" + socketPath, }, Volumes: []string{ - "ssh-agent:/tmp", - // add home from .ssh folder to container - sshPath + ":/root/.ssh", + "/tmp:/tmp", + sshPath + ":/root/keys", }, }) defer docker.Stop(t, []string{sshAgentID}, &docker.StopOptions{}) - } - - opts := &docker.RunOptions{ - EnvironmentVariables: []string{ - "INPUT_" + actionConfig.iacType + "_VERSION=" + actionConfig.iacVersion, - "INPUT_TG_VERSION=" + actionConfig.tgVersion, - "INPUT_TG_COMMAND=" + command, - "INPUT_TG_DIR=/github/workspace/code", - "GITHUB_OUTPUT=/tmp/logs", - }, - Volumes: []string{ - fixturePath + ":/github/workspace/code", - }, - Remove: true, - } - if sshAgent { - // add ssh socket - opts.Volumes = append(opts.Volumes, "/tmp/ssh-agent.sock:/tmp/ssh-agent.sock") - opts.EnvironmentVariables = append(opts.EnvironmentVariables, "SSH_AUTH_SOCK=/tmp/ssh-agent.sock") + opts.Volumes = append(opts.Volumes, "/tmp:/tmp") + opts.EnvironmentVariables = append(opts.EnvironmentVariables, "SSH_AUTH_SOCK="+socketPath) } return docker.Run(t, tag, opts) } diff --git a/test/fixture-action-execution-ssh/terragrunt.hcl b/test/fixture-action-execution-ssh/terragrunt.hcl index fa793d8..2e95587 100644 --- a/test/fixture-action-execution-ssh/terragrunt.hcl +++ b/test/fixture-action-execution-ssh/terragrunt.hcl @@ -3,5 +3,5 @@ inputs = { } terraform { - source = "git::ssh://git@github.com:gruntwork-io/terragrunt.git//test/fixture-download/hello-world?ref=v0.9.9" + source = "git@github.com:gruntwork-io/terragrunt.git//test/fixture-download/hello-world?ref=v0.9.9" } diff --git a/test/ssh-agent/Dockerfile b/test/ssh-agent/Dockerfile index df6f8e1..23a42bd 100644 --- a/test/ssh-agent/Dockerfile +++ b/test/ssh-agent/Dockerfile @@ -6,6 +6,6 @@ RUN apt-get update && \ RUN mkdir /ssh-agent -ENV SSH_AUTH_SOCK /ssh-agent/socket - -CMD ["ssh-agent", "-a", "/ssh-agent/socket"] \ No newline at end of file +ENV SSH_AUTH_SOCK /tmp/ssh-agent.sock +ADD run.sh /run.sh +CMD ["/run.sh"] diff --git a/test/ssh-agent/run.sh b/test/ssh-agent/run.sh new file mode 100755 index 0000000..ad5fec0 --- /dev/null +++ b/test/ssh-agent/run.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -x + +cleanup() { + echo "Caught SIGTERM signal! Cleaning up..." + ssh-agent -k + exit 0 +} + +trap cleanup SIGTERM SIGINT + +mkdir -p ~/.ssh +cp -rfv ~/keys/* ~/.ssh/ +chown -R $(whoami) ~/.ssh + +# delete socket if exists +if [[ -S "$SSH_AUTH_SOCK" ]]; then + rm -f "$SSH_AUTH_SOCK" +fi + +eval "$(ssh-agent -s -a "$SSH_AUTH_SOCK")" +ssh-add ~/.ssh/* + +echo "SSH agent running on: $SSH_AUTH_SOCK" +tail -f /dev/null From 7707f5afa3500037a82fb0289f3d28912ef9f3a2 Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 08:19:45 +0100 Subject: [PATCH 06/14] Add usage of TEST_SSH_KEY --- .circleci/config.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0a35a0e..fecb95f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -67,7 +67,12 @@ jobs: at: /home/circleci - run: <<: *install_gruntwork_utils - - run: + - run: + name: Setup test SSH key + command: | + echo -e $TEST_SSH_KEY > ~/.ssh/id_rsa_gh + chmod 600 ~/.ssh/id_rsa_gh + - run: name: Run tests command: | mkdir -p /tmp/logs @@ -98,6 +103,7 @@ workflows: - SLACK__TOKEN__refarch-deployer-test - SLACK__WEBHOOK__refarch-deployer-test - SLACK__CHANNEL__test-workflow-approvals + - GITHUB_TERRAGRUNT_ACTION requires: - precommit filters: From 4427a8430f302331bdbdb650e3615d8961460ffb Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 08:26:43 +0100 Subject: [PATCH 07/14] Github clone test --- test/action_run_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/action_run_test.go b/test/action_run_test.go index f0e8199..0ebae9c 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -124,13 +124,14 @@ func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixt "INPUT_TG_VERSION=" + actionConfig.tgVersion, "INPUT_TG_COMMAND=" + command, "INPUT_TG_DIR=/github/workspace/code", - "GITHUB_OUTPUT=/tmp/logs", + "GITHUB_OUTPUT=/tmp/github-action-logs", }, Volumes: []string{ fixturePath + ":/github/workspace/code", }, } + // start ssh-agent container with SSH keys inside to allow action to clone Github code if sshAgent { homeDir, err := os.UserHomeDir() if err != nil { From b6a1117fed209f321090239302768923e19b534c Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 08:30:37 +0100 Subject: [PATCH 08/14] Test ssh print --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fecb95f..37006b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,8 +70,9 @@ jobs: - run: name: Setup test SSH key command: | - echo -e $TEST_SSH_KEY > ~/.ssh/id_rsa_gh - chmod 600 ~/.ssh/id_rsa_gh + ls -lahrt ~/.ssh +# echo -e $TEST_SSH_KEY > ~/.ssh/id_rsa_gh +# chmod 600 ~/.ssh/id_rsa_gh - run: name: Run tests command: | From 243ddb0fa8ecdf1759b4d44e4d1e8a3fe2d251af Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 08:35:24 +0100 Subject: [PATCH 09/14] Cleanup --- .circleci/config.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 37006b5..0a35a0e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -67,13 +67,7 @@ jobs: at: /home/circleci - run: <<: *install_gruntwork_utils - - run: - name: Setup test SSH key - command: | - ls -lahrt ~/.ssh -# echo -e $TEST_SSH_KEY > ~/.ssh/id_rsa_gh -# chmod 600 ~/.ssh/id_rsa_gh - - run: + - run: name: Run tests command: | mkdir -p /tmp/logs @@ -104,7 +98,6 @@ workflows: - SLACK__TOKEN__refarch-deployer-test - SLACK__WEBHOOK__refarch-deployer-test - SLACK__CHANNEL__test-workflow-approvals - - GITHUB_TERRAGRUNT_ACTION requires: - precommit filters: From da53b646c6ce744ccf6e4c054b31c97e8771d92b Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 08:37:58 +0100 Subject: [PATCH 10/14] Run script update --- test/ssh-agent/run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/ssh-agent/run.sh b/test/ssh-agent/run.sh index ad5fec0..420fcc3 100755 --- a/test/ssh-agent/run.sh +++ b/test/ssh-agent/run.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Script to run ssh-agent in the background and add ssh keys set -x cleanup() { @@ -23,3 +24,4 @@ ssh-add ~/.ssh/* echo "SSH agent running on: $SSH_AUTH_SOCK" tail -f /dev/null + From 75c0b0c1e266cde20685ad355cca98ababc7926f Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 09:51:14 +0100 Subject: [PATCH 11/14] Simplified permissions setting --- src/main.sh | 19 +++++++------------ test/action_run_test.go | 22 +++++++--------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/main.sh b/src/main.sh index 1cfd9a6..3c23d21 100755 --- a/src/main.sh +++ b/src/main.sh @@ -103,18 +103,11 @@ function setup_git { function setup_permissions { local -r dir="${1}" - sudo chown -R $(whoami) /github/workspace - # Set permissions for the working directory - if [[ -f "${dir}" ]]; then - sudo chown -R $(whoami) "${dir}" - sudo chmod -R o+rw "${dir}" - fi - # Set permissions for the output file - if [[ -f "${GITHUB_OUTPUT}" ]]; then - sudo chown -R $(whoami) "${GITHUB_OUTPUT}" - fi - # set permissions for .terraform directories, if any - sudo find /github/workspace -name ".terraform*" -exec chmod -R 777 {} \; + # fetch the user id and group id under which the github action is running + local -r uid=$(stat -c "%u" "/github/workspace") + local -r gid=$(stat -c "%g" "/github/workspace") + sudo chown -R "$uid:$gid" "${dir}" + sudo chmod -R o+rw "${dir}" } # Run INPUT_PRE_EXEC_* environment variables as Bash code @@ -219,6 +212,8 @@ function main { fi run_terragrunt "${tg_dir}" "${tg_arg_and_commands}" setup_permissions "${tg_dir}" + setup_permissions "${terragrunt_log_file}" + setup_permissions "${GITHUB_OUTPUT}" # setup permissions for the output files setup_post_exec diff --git a/test/action_run_test.go b/test/action_run_test.go index 0ebae9c..a0ef38d 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -114,6 +114,10 @@ func testAutoApproveDelete(t *testing.T, actionConfig ActionConfig, tag string) output = runAction(t, actionConfig, false, tag, fixturePath, "run-all apply -destroy destroy.out") assert.Contains(t, output, "Resources: 0 added, 0 changed, 1 destroyed", actionConfig.iacName) + + // check that fixturePath can removed recursively + err := os.RemoveAll(fixturePath) + assert.NoError(t, err) } func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixturePath string, command string) string { @@ -123,15 +127,15 @@ func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixt "INPUT_" + actionConfig.iacType + "_VERSION=" + actionConfig.iacVersion, "INPUT_TG_VERSION=" + actionConfig.tgVersion, "INPUT_TG_COMMAND=" + command, - "INPUT_TG_DIR=/github/workspace/code", + "INPUT_TG_DIR=/github/workspace", "GITHUB_OUTPUT=/tmp/github-action-logs", }, Volumes: []string{ - fixturePath + ":/github/workspace/code", + fixturePath + ":/github/workspace", }, } - // start ssh-agent container with SSH keys inside to allow action to clone Github code + // start ssh-agent container with SSH keys to allow clones over SSH if sshAgent { homeDir, err := os.UserHomeDir() if err != nil { @@ -162,17 +166,5 @@ func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixt func prepareFixture(t *testing.T, fixtureDir string) string { path, err := files.CopyTerraformFolderToTemp(fixtureDir, "test") require.NoError(t, err) - // chmod recursive for docker run - - err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - return os.Chmod(path, 0777) - }) - require.NoError(t, err) - - err = os.Chmod(path, 0777) - require.NoError(t, err) return path } From fbf385484b4afdf16545eec9432ad701da94a7af Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 10:56:42 +0100 Subject: [PATCH 12/14] Dir update --- src/main.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.sh b/src/main.sh index 3c23d21..d830111 100755 --- a/src/main.sh +++ b/src/main.sh @@ -106,8 +106,10 @@ function setup_permissions { # fetch the user id and group id under which the github action is running local -r uid=$(stat -c "%u" "/github/workspace") local -r gid=$(stat -c "%g" "/github/workspace") - sudo chown -R "$uid:$gid" "${dir}" - sudo chmod -R o+rw "${dir}" + if [[ -e "${dir}" ]]; then + sudo chown -R "$uid:$gid" "${dir}" + sudo chmod -R o+rw "${dir}" + fi } # Run INPUT_PRE_EXEC_* environment variables as Bash code From 6eaf671a90684b5c68e7e66006000598091c4c70 Mon Sep 17 00:00:00 2001 From: Denis O Date: Wed, 8 May 2024 11:00:40 +0100 Subject: [PATCH 13/14] Socket id passing --- test/action_run_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/action_run_test.go b/test/action_run_test.go index a0ef38d..26c4e21 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -122,13 +122,14 @@ func testAutoApproveDelete(t *testing.T, actionConfig ActionConfig, tag string) func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixturePath string, command string) string { + logId := random.Random(1, 5000) opts := &docker.RunOptions{ EnvironmentVariables: []string{ "INPUT_" + actionConfig.iacType + "_VERSION=" + actionConfig.iacVersion, "INPUT_TG_VERSION=" + actionConfig.tgVersion, "INPUT_TG_COMMAND=" + command, "INPUT_TG_DIR=/github/workspace", - "GITHUB_OUTPUT=/tmp/github-action-logs", + fmt.Sprintf("GITHUB_OUTPUT=/tmp/github-action-logs.%d", logId), }, Volumes: []string{ fixturePath + ":/github/workspace", @@ -143,8 +144,8 @@ func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixt } sshPath := filepath.Join(homeDir, ".ssh") - r := random.Random(1, 1000) - socketPath := fmt.Sprintf("/tmp/ssh-agent.sock.%d", r) + socketId := random.Random(1, 5000) + socketPath := fmt.Sprintf("/tmp/ssh-agent.sock.%d", socketId) sshAgentID := docker.RunAndGetID(t, "ssh-agent:local", &docker.RunOptions{ Detach: true, Remove: true, From 5108459870fa8200477a1e2855574b06a01b07ed Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 10 May 2024 21:15:26 +0100 Subject: [PATCH 14/14] Updated error checking --- test/action_run_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/action_run_test.go b/test/action_run_test.go index 26c4e21..5aa592b 100644 --- a/test/action_run_test.go +++ b/test/action_run_test.go @@ -139,9 +139,7 @@ func runAction(t *testing.T, actionConfig ActionConfig, sshAgent bool, tag, fixt // start ssh-agent container with SSH keys to allow clones over SSH if sshAgent { homeDir, err := os.UserHomeDir() - if err != nil { - assert.NoError(t, err) - } + assert.NoError(t, err) sshPath := filepath.Join(homeDir, ".ssh") socketId := random.Random(1, 5000)