diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d09c164f..4e06465b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -37,7 +37,7 @@ jobs: # Run the test cases - name: Run the test cases - run: docker run --volume $(pwd)/tests:/tests tools_cloudshell /bin/bash /tests/test.sh + run: docker run -i --volume $(pwd)/tests:/tests tools_cloudshell /bin/bash /tests/test.sh # Show Docker image size - name: find the pull request id diff --git a/linux/bash/bashrc b/linux/bash/bashrc new file mode 100644 index 00000000..3159cd9e --- /dev/null +++ b/linux/bash/bashrc @@ -0,0 +1,11 @@ +# Start: Define custom environment variables + +# Add dotnet tools to PATH so users can install a tool using dotnet tools and +# can execute that command from any directory +export PATH=$HOME/.dotnet/tools:$PATH + +# Add user's home directories to PATH at the front so they can install tools +# which override defaults +export PATH=$HOME/.local/bin:$HOME/bin:$PATH + +# End: Define custom environment variables diff --git a/linux/tools.Dockerfile b/linux/tools.Dockerfile index fcc40d96..fc2ffd7a 100644 --- a/linux/tools.Dockerfile +++ b/linux/tools.Dockerfile @@ -66,10 +66,10 @@ RUN rm -f ./linux/Dockerfile && rm -f /bin/su RUN ln -s /usr/bin/python3 /usr/bin/python RUN ln -s /usr/bin/node /usr/bin/nodejs -# Add user's home directories to PATH at the front so they can install tools which -# override defaults -# Add dotnet tools to PATH so users can install a tool using dotnet tools and can execute that command from any directory -ENV PATH ~/.local/bin:~/bin:~/.dotnet/tools:$PATH +# Add custom environment variables to /etc/skel/.bashrc so they will be +# available to users any time they open a new shell. +COPY ./linux/bash/bashrc linux/bashrc +RUN cat linux/bashrc >> /etc/skel/.bashrc && rm linux/bashrc # Set AZUREPS_HOST_ENVIRONMENT ENV AZUREPS_HOST_ENVIRONMENT cloud-shell/1.0 diff --git a/tests/PSinLinuxCloudShellImage.Tests.ps1 b/tests/PSinLinuxCloudShellImage.Tests.ps1 index b5c143a8..a7161eeb 100755 --- a/tests/PSinLinuxCloudShellImage.Tests.ps1 +++ b/tests/PSinLinuxCloudShellImage.Tests.ps1 @@ -74,8 +74,8 @@ Describe "Various programs installed with expected versions" { It "has local paths in `$PATH" { $paths = ($env:PATH).split(":") - $paths | Should -Contain "~/bin" - $paths | Should -Contain "~/.local/bin" + $paths | Should -Contain "$HOME/bin" + $paths | Should -Contain "$HOME/.local/bin" } It "Ansible pwsh has modules" { diff --git a/tests/test.sh b/tests/test.sh index 4eec30ab..b62c94d9 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -19,5 +19,9 @@ pwsh /tests/root-tests.ps1 pwsh -c "Install-Module Pester -Force -Scope AllUsers" +# Run tests as csuser with an interactive shell to verify the configuration in +# the same environment this imange will be used in. Otherwise, the .bashrc won't +# be sourced and the bash configuration (e.g., environment variables) won't be +# set during the tests. echo "running tests as csuser" -runuser -u csuser pwsh /tests/test.ps1 \ No newline at end of file +runuser -u csuser -- /bin/bash -i -c 'pwsh /tests/test.ps1'