diff options
author | Josh Spicer <joshspicer@github.com> | 2022-11-17 01:18:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 01:18:29 +0300 |
commit | 348ee69aaa59976259fe8f0b727a1719bc7663d9 (patch) | |
tree | 03c07c75a5ec9947208b529f2ecebcf49085fb0d | |
parent | f9acb6aae1e520b0b61aaac9ab4ecb00dd497451 (diff) |
follow symlinks when chowning and add practical dotnet test
-rwxr-xr-x | src/dotnet/install.sh | 14 | ||||
-rw-r--r-- | test/dotnet/assert_run_project.sh | 8 | ||||
-rw-r--r-- | test/dotnet/example_project/.gitignore | 2 | ||||
-rw-r--r-- | test/dotnet/example_project/Movie.cs | 8 | ||||
-rw-r--r-- | test/dotnet/example_project/Program.cs | 27 | ||||
-rw-r--r-- | test/dotnet/example_project/example_project.csproj | 14 | ||||
-rw-r--r-- | test/dotnet/install_additional_dotnet.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_dotnet_3.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_dotnet_6_focal.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_dotnet_7_bullseye.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_dotnet_7_jammy.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_dotnet_latest.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_dotnet_lts.sh | 2 | ||||
-rw-r--r-- | test/dotnet/install_non_root_remoteUser.sh | 13 | ||||
-rw-r--r-- | test/dotnet/install_wo_apt.sh | 2 | ||||
-rw-r--r-- | test/dotnet/scenarios.json | 9 | ||||
-rwxr-xr-x | test/dotnet/test.sh | 2 |
17 files changed, 111 insertions, 2 deletions
diff --git a/src/dotnet/install.sh b/src/dotnet/install.sh index 78cd691..b0b2050 100755 --- a/src/dotnet/install.sh +++ b/src/dotnet/install.sh @@ -15,7 +15,7 @@ INSTALL_USING_APT=${INSTALLUSINGAPT:-"true"} DOTNET_LATEST="7" DOTNET_LTS="6" -USERNAME=${USERNAME:-"automatic"} +USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" UPDATE_RC=${UPDATE_RC:-"true"} TARGET_DOTNET_ROOT=${TARGET_DOTNET_ROOT:-"/usr/local/dotnet"} ACCESS_GROUP=${ACCESS_GROUP:-"dotnet"} @@ -187,6 +187,8 @@ install_using_apt() { local target_dotnet_version="$2" local use_msft_repo="$3" + echo "🚀 Starting install_using_apt ('${sdk_or_runtime}' at version '${target_dotnet_version}' from msft repo '${use_msft_repo}')..." + if [ "${use_msft_repo}" = "true" ]; then # Install dependencies check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr @@ -316,6 +318,8 @@ install_using_dotnet_releases_url() { local sdk_or_runtime="$1" local version="$2" + echo "🚀 Starting install_using_dotnet_releases_url (${sdk_or_runtime} version ${version})..." + # Check listed package dependecies and install them if they are not already installed. # NOTE: icu-devtools is a small package with similar dependecies to .NET. # It will install the appropriate dependencies based on the OS: @@ -429,6 +433,7 @@ if [[ "${DOTNET_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${DOTNE echo "Could not install requested version from apt on current distribution." exit 1 fi + CHANGE_OWNERSHIP="true" else if [[ "${INSTALL_USING_APT}" = "false" ]]; then echo "Installing dotnet from releases url" @@ -452,16 +457,21 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then fi if [ "${CHANGE_OWNERSHIP}" = "true" ]; then + echo "Changing ownership ("${USERNAME}" <- "${TARGET_DOTNET_ROOT}")" if ! cat /etc/group | grep -e "^dotnet:" > /dev/null 2>&1; then groupadd -r dotnet fi usermod -a -G dotnet "${USERNAME}" - chown -R "${USERNAME}:dotnet" "${TARGET_DOTNET_ROOT}" + chown -H -R "${USERNAME}:dotnet" "${TARGET_DOTNET_ROOT}" # Recursively traverse (-R), also following symbolic links (-H) chmod -R g+r+w "${TARGET_DOTNET_ROOT}" find "${TARGET_DOTNET_ROOT}" -type d -print0 | xargs -n 1 -0 chmod g+s +else + echo "Not changing ownership ("${USERNAME}" <- "${TARGET_DOTNET_ROOT}")" fi + + # Clean up rm -rf /var/lib/apt/lists/* diff --git a/test/dotnet/assert_run_project.sh b/test/dotnet/assert_run_project.sh new file mode 100644 index 0000000..872d068 --- /dev/null +++ b/test/dotnet/assert_run_project.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib + +cd example_project +check "dotnet run" bash -c "dotnet run | grep 'Inception'"
\ No newline at end of file diff --git a/test/dotnet/example_project/.gitignore b/test/dotnet/example_project/.gitignore new file mode 100644 index 0000000..8d4a6c0 --- /dev/null +++ b/test/dotnet/example_project/.gitignore @@ -0,0 +1,2 @@ +bin +obj
\ No newline at end of file diff --git a/test/dotnet/example_project/Movie.cs b/test/dotnet/example_project/Movie.cs new file mode 100644 index 0000000..9d549ef --- /dev/null +++ b/test/dotnet/example_project/Movie.cs @@ -0,0 +1,8 @@ +// See https://aka.ms/new-console-template for more information + +internal class Movie +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/example_project/Program.cs b/test/dotnet/example_project/Program.cs new file mode 100644 index 0000000..7beb65f --- /dev/null +++ b/test/dotnet/example_project/Program.cs @@ -0,0 +1,27 @@ +// See https://aka.ms/new-console-template for more information
+
+using Newtonsoft.Json;
+
+Console.WriteLine("Hello, World!");
+
+string json = @"{
+ 'Name': 'Inception',
+ 'ReleaseDate': '2010-07-08T00:00:00',
+ 'Genres': [
+ 'Action',
+ 'Thriller'
+ ]
+}";
+
+Movie? m = JsonConvert.DeserializeObject<Movie>(json);
+
+if (m == default)
+{
+ Console.WriteLine("Decoding failed!");
+}
+else
+{
+ Console.WriteLine($"Name: {m.Name}");
+ Console.WriteLine($"Release Date: {m.ReleaseDate}");
+ Console.WriteLine($"Genres: {string.Join(", ", m.Genres)}");
+}
diff --git a/test/dotnet/example_project/example_project.csproj b/test/dotnet/example_project/example_project.csproj new file mode 100644 index 0000000..6132c9e --- /dev/null +++ b/test/dotnet/example_project/example_project.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net7.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup>
+
+</Project>
diff --git a/test/dotnet/install_additional_dotnet.sh b/test/dotnet/install_additional_dotnet.sh index e69c7dc..b077462 100644 --- a/test/dotnet/install_additional_dotnet.sh +++ b/test/dotnet/install_additional_dotnet.sh @@ -13,5 +13,7 @@ check "dotnet version 3.1.420 installed" bash -c "ls -l /usr/local/dotnet | gre check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_dotnet_3.sh b/test/dotnet/install_dotnet_3.sh index 51d871b..aed11f5 100644 --- a/test/dotnet/install_dotnet_3.sh +++ b/test/dotnet/install_dotnet_3.sh @@ -13,5 +13,7 @@ check "dotnet version 3 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_dotnet_6_focal.sh b/test/dotnet/install_dotnet_6_focal.sh index 758f040..2b97e75 100644 --- a/test/dotnet/install_dotnet_6_focal.sh +++ b/test/dotnet/install_dotnet_6_focal.sh @@ -13,5 +13,7 @@ check "dotnet version 6 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_dotnet_7_bullseye.sh b/test/dotnet/install_dotnet_7_bullseye.sh index 2c015fc..6e78d7a 100644 --- a/test/dotnet/install_dotnet_7_bullseye.sh +++ b/test/dotnet/install_dotnet_7_bullseye.sh @@ -13,5 +13,7 @@ check "dotnet version 7 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_dotnet_7_jammy.sh b/test/dotnet/install_dotnet_7_jammy.sh index 2c015fc..6e78d7a 100644 --- a/test/dotnet/install_dotnet_7_jammy.sh +++ b/test/dotnet/install_dotnet_7_jammy.sh @@ -13,5 +13,7 @@ check "dotnet version 7 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_dotnet_latest.sh b/test/dotnet/install_dotnet_latest.sh index 2c015fc..6e78d7a 100644 --- a/test/dotnet/install_dotnet_latest.sh +++ b/test/dotnet/install_dotnet_latest.sh @@ -13,5 +13,7 @@ check "dotnet version 7 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_dotnet_lts.sh b/test/dotnet/install_dotnet_lts.sh index 758f040..2b97e75 100644 --- a/test/dotnet/install_dotnet_lts.sh +++ b/test/dotnet/install_dotnet_lts.sh @@ -13,5 +13,7 @@ check "dotnet version 6 installed" bash -c "ls -l /usr/share/dotnet/sdk | grep check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/install_non_root_remoteUser.sh b/test/dotnet/install_non_root_remoteUser.sh new file mode 100644 index 0000000..e9680cb --- /dev/null +++ b/test/dotnet/install_non_root_remoteUser.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "ensure i am user codespace" bash -c "whoami | grep 'codespace'" + +./install_dotnet_7_jammy.sh + +# Report result +reportResults diff --git a/test/dotnet/install_wo_apt.sh b/test/dotnet/install_wo_apt.sh index a1745c5..6a8b9ce 100644 --- a/test/dotnet/install_wo_apt.sh +++ b/test/dotnet/install_wo_apt.sh @@ -13,5 +13,7 @@ check "dotnet version 7 installed" bash -c "ls -l /usr/local/dotnet | grep '7\. check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults diff --git a/test/dotnet/scenarios.json b/test/dotnet/scenarios.json index 37f83d5..1b88819 100644 --- a/test/dotnet/scenarios.json +++ b/test/dotnet/scenarios.json @@ -72,5 +72,14 @@ "installUsingApt": false } } + }, + "install_non_root_remoteUser": { + "image": "mcr.microsoft.com/devcontainers/universal:2", + "remoteUser": "codespace", + "features": { + "dotnet": { + "version": "7" + } + } } }
\ No newline at end of file diff --git a/test/dotnet/test.sh b/test/dotnet/test.sh index 7eb0cf6..3befeec 100755 --- a/test/dotnet/test.sh +++ b/test/dotnet/test.sh @@ -17,5 +17,7 @@ check "some major version of dotnet 7 is installed" bash -c "dotnet --version | check "current link dotnet" /usr/local/dotnet/current/dotnet --info check "current link sdk" ls -l /usr/local/dotnet/current/sdk +./assert_run_project.sh + # Report result reportResults
\ No newline at end of file |