From 3186f778cf8850ad99a31628491ecf6e258f0729 Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Fri, 15 Jul 2022 02:03:44 +0200 Subject: [PATCH 1/7] WCF Docker Containers --- .dockerignore | 10 + Docker/Client/Linux.dockerfile | 3 + Docker/Client/Windows.dockerfile | 7 + Docker/Service/Dockerfile | 13 + .../tools/CertificateGenerator/App.config | 2 +- .../CertificateGenerator.csproj | 6 +- .../tools/scripts/BuildSource.cmd | 4 + .../tools/scripts/BuildTest.cmd | 8 + .../tools/scripts/DockerStartWCFService.cmd | 64 +++++ .../scripts/DockerStartWCFTest-Linux.cmd | 67 +++++ .../scripts/DockerStartWCFTest-Windows.cmd | 65 +++++ .../tools/scripts/SetClientEnv-Linux.sh | 13 + .../tools/scripts/SetClientEnv-Windows.cmd | 13 + .../SetupWcfIISHostedService - Copy.cmd | 268 ++++++++++++++++++ .../scripts/SetupWcfIISHostedService.cmd | 5 +- .../StartWCFSelfHostedSvcDoWork - Copy.cmd | 91 ++++++ .../scripts/StartWCFSelfHostedSvcDoWork.cmd | 17 -- 17 files changed, 631 insertions(+), 25 deletions(-) create mode 100644 .dockerignore create mode 100644 Docker/Client/Linux.dockerfile create mode 100644 Docker/Client/Windows.dockerfile create mode 100644 Docker/Service/Dockerfile create mode 100644 src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh create mode 100644 src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd create mode 100644 src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..6269864134b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +# Ignore everything +* + +# Allow files and directories +#!global.json +#!NuGet.config +#!/eng +#!/src/System.Private.ServiceModel/tools +#!/artifacts/bin/CertificateGenerator +#!/artifacts/bin/SelfHostedWCFService \ No newline at end of file diff --git a/Docker/Client/Linux.dockerfile b/Docker/Client/Linux.dockerfile new file mode 100644 index 00000000000..2a3efdbb873 --- /dev/null +++ b/Docker/Client/Linux.dockerfile @@ -0,0 +1,3 @@ +FROM mcr.microsoft.com/dotnet/sdk:6.0.300-focal-amd64 + +CMD /wcf/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh && /wcf/eng/common/cibuild.sh -configuration Release -prepareMachine -t --integrationTest diff --git a/Docker/Client/Windows.dockerfile b/Docker/Client/Windows.dockerfile new file mode 100644 index 00000000000..a163c08829a --- /dev/null +++ b/Docker/Client/Windows.dockerfile @@ -0,0 +1,7 @@ +FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] + +CMD C:\wcf\src\System.Private.ServiceModel\tools\scripts\SetClientEnv-Windows.cmd; C:\wcf\eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Restore=false /p:Sign=false /p:Test=true /p:IntegrationTest=true /p:Pack=false /p:Publish=false; + + diff --git a/Docker/Service/Dockerfile b/Docker/Service/Dockerfile new file mode 100644 index 00000000000..b268be72f4c --- /dev/null +++ b/Docker/Service/Dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/dotnet/framework/wcf + +# IIS Hosted +EXPOSE 80 808 443 44345 + +# Self Hosted +EXPOSE 8081 8083 8084 44285 809 + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] +ENTRYPOINT ["powershell"] + +# Setup WCF web hosted and self hosted services - Container Startup CMD +CMD ./wcf/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd 38 /p:"c:\wcf"; ./wcf/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvc.cmd; powershell diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/App.config b/src/System.Private.ServiceModel/tools/CertificateGenerator/App.config index 970aad0e744..02dcadb10ac 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/App.config +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/App.config @@ -6,6 +6,6 @@ - + diff --git a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj index 182c6e160ff..95c9d216877 100644 --- a/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj +++ b/src/System.Private.ServiceModel/tools/CertificateGenerator/CertificateGenerator.csproj @@ -4,13 +4,13 @@ Exe CertificateGenerator CertificateGenerator - v4.5 + v4.8 - + - + diff --git a/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd b/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd new file mode 100644 index 00000000000..cb902351698 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd @@ -0,0 +1,4 @@ +:: Build certifcate generator tool +call BuildCertUtil.cmd +:: Build Selfhosted service +call BuildWCFSelfHostedService.cmd diff --git a/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd b/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd new file mode 100644 index 00000000000..6f1a302d7d5 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd @@ -0,0 +1,8 @@ +:: Build tests +::Windows Build +cd ..\..\..\..\ +call eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false + +::Linux Build +::call eng\common\cibuild.sh -configuration Release -preparemachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false + diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd new file mode 100644 index 00000000000..6d1d53828f7 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd @@ -0,0 +1,64 @@ +echo off +setlocal +echo ********************************** +echo Starting WCF Service on Docker +echo ********************************** + +set _exitCode=0 +::todo use vars +set ServiceImageTag = "wcf:service" +set "ServiceContainerName=WCFServiceContainer" + + +:: Make sure docker is running +docker ps>nul 2>&1 +if ERRORLEVEL 1 ( + echo. & echo ERROR: Please make sure docker is running. + goto :Failure +) + +::make sure we are using Windows Containers +CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine + +:: Check if WCF service is already running +FOR /F "tokens=* USEBACKQ" %%F IN (`docker container inspect -f '{{.State.Status}}' %ServiceContainerName%`) DO ( +if %%F == 'running' ( + echo. & echo WCF Service container is already running. + goto :Done +)) + +:: change directory to wcf folder +cd ../../../.. + +echo. & echo Building Docker image for WCF service + +:: Building docker image. +docker build -f ./Docker/Service/Dockerfile -t wcf:service . +if ERRORLEVEL 1 ( + echo. & echo ERROR: Building docker image failed. + goto :Failure +) +echo. & echo Building image success.. + +:: Starting docker container from the image. +echo. & echo Starting WCF Service Container +:: mount current directory for wcf source as container volume - C:\wcf +docker run --name %ServiceContainerName% --rm -it -d -v "%cd%":"C:\wcf" wcf:service +if ERRORLEVEL 1 ( + echo. & echo ERROR: Starting WCF service container failed. + goto :Failure +) + +echo. & echo Started WCF Service Container. +:: print service container IP address +docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" %ServiceContainerName% + +exit /b + +:Failure +echo. & echo Error... +set _exitCode=1 + +:Done +exit /b %_exitCode% +endlocal \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd new file mode 100644 index 00000000000..75c3fa232c9 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd @@ -0,0 +1,67 @@ +echo off +setlocal +echo ********************************** +echo Starting WCF Client on Docker +echo ********************************** + +set _exitCode=0 + +:: Make sure docker is running +docker ps>nul 2>&1 +if ERRORLEVEL 1 ( + echo. & echo ERROR: Please make sure docker is running. + goto :Failure +) + +echo. & echo Checking WCF service container status and IP address. + +::Switch to Windows Containers to check WCF Service status +CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine + +:: Check if WCF service is already running +docker container inspect -f '{{.State.Status}}' WCFServiceContainer +if ERRORLEVEL 1 ( + echo. & echo Warning: WCF Service container is not running. + CALL DockerStartWCFService.cmd +) + +:: set ServiceUri +FOR /F "tokens=* USEBACKQ" %%F IN (`docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" WCFServiceContainer`) DO ( +SET ServiceUri=%%F/WcfService38 +) +echo %ServiceUri% + +::Switch to Linux Containers to run Linux tests +CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchLinuxEngine + +:: change directory to wcf src +cd ../../../.. + +echo. & echo Building Docker image for WCF client + +:: Building docker image. +docker build -f ./Docker/Client/Linux.dockerfile --tag=wcf:client . +if ERRORLEVEL 1 ( + echo. & echo ERROR: Building docker image failed. + goto :Failure +) +echo. & echo Building image success.. + +:: Starting docker container from the image. +echo. & echo Starting WCF client +docker run --name wcfclient_container --rm -it --memory=2g -v "%cd%":"/wcf" -e ServiceUri=%ServiceUri% wcf:client +if ERRORLEVEL 1 ( + echo. & echo ERROR: Starting WCF client container failed. + goto :Failure +) + + +exit /b + +:Failure +echo. & echo Error... +set _exitCode=1 + +:Done +exit /b %_exitCode% +endlocal \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd new file mode 100644 index 00000000000..4a463f49dcc --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd @@ -0,0 +1,65 @@ +echo off +setlocal +echo ********************************** +echo Starting WCF Client on Docker +echo ********************************** + +set _exitCode=0 + +:: Make sure docker is running +docker ps>nul 2>&1 +if ERRORLEVEL 1 ( + echo. & echo ERROR: Please make sure docker is running. + goto :Failure +) + +echo. & echo Checking WCF service container status and IP address. + +::Switch to Windows Containers to check WCF Service status +CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine + +:: Check if WCF service is already running +docker container inspect -f '{{.State.Status}}' WCFServiceContainer +if ERRORLEVEL 1 ( + echo. & echo Warning: WCF Service container is not running. + CALL DockerStartWCFService.cmd +) + +:: set ServiceUri +FOR /F "tokens=* USEBACKQ" %%F IN (`docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" WCFServiceContainer`) DO ( +SET ServiceUri=%%F/WcfService38 +) +echo %ServiceUri% + +:: change directory to wcf src +cd ../../../.. + +echo. & echo Building Docker image for WCF client + +:: Building docker image. +docker build -f ./Docker/Client/Windows.dockerfile --tag=wcf:client . +if ERRORLEVEL 1 ( + echo. & echo ERROR: Building docker image failed. + goto :Failure +) +echo. & echo Building image success.. + +:: Starting docker container from the image. + +echo. & echo Starting WCF client +docker run --name wcfclient_container --rm -it --memory=2g -v "%cd%":"C:\wcf" -e ServiceUri=%ServiceUri% wcf:client +if ERRORLEVEL 1 ( + echo. & echo ERROR: Starting WCF client container failed. + goto :Failure +) + + +exit /b + +:Failure +echo. & echo Error... +set _exitCode=1 + +:Done +exit /b %_exitCode% +endlocal \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh new file mode 100644 index 00000000000..0b595cabcc6 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh @@ -0,0 +1,13 @@ +export Windows_Authentication_Available=true +export SPN_Available=true +export Server_Domain_Joined=true +export Ambient_Credentials_Available=true +export Domain_Available=true +export Explicit_Credentials_Available=true +export ExplicitUserName=indgaunt +export ExplicitPassword=IU872_oR4189l6_HT8 +export SSL_Available=true +export Root_Certificate_Installed=true +export Client_Certificate_Installed=true +export Peer_Certificate_Installed=true +export NegotiateTestDomain=REDMOND.CORP.MICROSOFT.COM \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd new file mode 100644 index 00000000000..99b2309b391 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd @@ -0,0 +1,13 @@ +setx Windows_Authentication_Available true +setx Digest_Authentication_Available true +setx Ambient_Credentials_Available true +setx SPN_Available true +setx NTLM_Available true +setx Server_Domain_Joined true +setx ExplicitUserName indgaunt +setx ExplicitPassword IU872_oR4189l6_HT8 +setx Domain_Available true +setx UPN_Available true +setx Root_Certificate_Installed true +setx Client_Certificate_Installed true +setx Peer_Certificate_Installed true \ No newline at end of file diff --git a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd new file mode 100644 index 00000000000..a677dd17217 --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd @@ -0,0 +1,268 @@ +@echo off +setlocal + +set _id=%1 +set _idMaster=Master +set _wcfTestDir=c:\WCFTest +set _repoHome=c:\git +set _pathIISHostedWcfService=src\System.Private.ServiceModel\tools\IISHostedWcfService +set _currentRepo=%_repoHome%\wcf%_id% +set _masterRepo=%_repoHome%\wcf%_idMaster% +set _prServiceName=PRService%_id% +set _wcfServiceName=WcfService%_id% +set _prServiceMaster=PRService%_idMaster% +set _wcfServiceMaster=WcfService%_idMaster% +set _logFile="%~dp0%~n0.log" +set _certExpirationInDays=99 +set _githubWcfRepoUrl=https://github.com/dotnet/wcf +set _exitCode=0 +set _cmd= +set _cleanup= +set _useExistingRepo= + +if '%1'=='' goto :Usage +if '%1'=='/?' goto :Usage +if '%1'=='-?' goto :Usage +if '%1'=='/help' goto :Usage +if '%1'=='-help' goto :Usage + +echo. +echo %date% %time% +echo ============================== + +:: Parse command line arguments +:NextArg +shift +set arg=%1 + +if '%arg%'=='' goto :NoMoreArg + +if /I '%arg%'=='/c' ( + set _cleanup=true + goto :NextArg +) + +if /I '%arg:~0,2%'=='/p' ( + set _useExistingRepo=true + set _currentRepo=%arg:~3% + goto :NextArg +) + +echo IGNORED unknown argument ^(use /? for help^): %arg% +goto :NextArg + +:NoMoreArg + +:: Make sure this script is running in elevated +if EXIST %_logFile% del %_logFile% /f /q +net session>nul 2>&1 +if ERRORLEVEL 1 ( + echo. & echo ERROR: Please run this script with elevated permission. + goto :Failure +) + +:: Make sure IIS appcmd.exe is accessible +set _appcmd=%windir%\System32\inetsrv\appcmd.exe +if NOT EXIST %_appcmd% ( + echo Could not find: %_appcmd%. + echo Please make sure IIS is installed. + goto :Failure +) + +:: Clean up any existing setup +echo Deleting WCF repo at %_currentRepo% if exists and associated application pools and services hosted on IIS... +%_appcmd% delete app "Default Web Site/%_prServiceName%" >nul +%_appcmd% delete apppool %_prServiceName% >nul +%_appcmd% delete app "Default Web Site/%_wcfServiceName%" >nul +%_appcmd% delete apppool %_wcfServiceName% >nul +if EXIST %_currentRepo% if DEFINED _useExistingRepo (echo User provided repo is not deleted: %_currentRepo%) else (rmdir /s /q %_currentRepo%) +if EXIST %_wcfTestDir% if /I '%_id%'=='%_idMaster%' rmdir /s /q %_wcfTestDir% +echo Clean up done. +if DEFINED _cleanup goto :Done + +:: Determine if we need to clone a new WCF repo +if DEFINED _useExistingRepo ( + if NOT EXIST %_currentRepo% echo ERROR: The provided WCF repo was not found: %_currentRepo% & goto :Failure + echo Use provided WCF repo: %_currentRepo% + goto :SkipCloneRepo +) + +:: Make sure git.exe is available +where git.exe /Q +if ERRORLEVEL 1 ( + echo Could not find: git.exe. + echo Please make sure git is installed and its location is part of PATH environment. + goto :Failure +) + +:: Clone a WCF repo +set _cmd=git clone %_githubWcfRepoUrl% %_currentRepo% +call %_cmd% +if ERRORLEVEL 1 goto :Failure +pushd %_currentRepo% +call :Run git config --add origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" +if ERRORLEVEL 1 goto :Failure +popd + +:SkipCloneRepo + +:: Create a new application pool and an application for the WCF test service +echo Create IIS application pool: %_wcfServiceName% +call :Run %_appcmd% add apppool /name:%_wcfServiceName% /processModel.IdentityType:LocalSystem /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated +if ERRORLEVEL 1 goto :Failure +echo Create IIS application: %_wcfServiceName% +call :Run %_appcmd% add app /site.name:"Default Web Site" /path:/%_wcfServiceName% /physicalPath:%_currentRepo%\%_pathIISHostedWcfService% /applicationPool:%_wcfServiceName% /enabledProtocols:"http,net.tcp" +if ERRORLEVEL 1 goto :Failure + +:: Grant app pool %_wcfServiceName% "Read and Execute" access to the IISHostedWcfService and its subdirectories +echo Grant app pool %_wcfServiceName% "Read and Execute" access to %_currentRepo%\%_pathIISHostedWcfService% +call :Run icacls %_currentRepo%\%_pathIISHostedWcfService% /grant:r "IIS APPPOOL\%_wcfServiceName%":(OI)(CI)RX /Q +if ERRORLEVEL 1 goto :Failure + +:: Setup PR service only if this is a master service +if /I NOT '%_id%'=='%_idMaster%' ( + echo SKIP creating PRService. PRService will be created when Id=%_idMaster%. + goto :SkipPRService +) + +:: Create a new application pool and an application for the PR service +echo Create IIS application pool: %_prServiceName% +call :Run %_appcmd% add apppool /name:%_prServiceName% /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated +if ERRORLEVEL 1 goto :Failure +echo Create IIS application: %_prServiceName% +call :Run %_appcmd% add app /site.name:"Default Web Site" /path:/%_prServiceName% /physicalPath:%_currentRepo%\src\System.Private.ServiceModel\tools\PRService -applicationPool:%_prServiceName% +if ERRORLEVEL 1 goto :Failure + +:: Grant app pool %_prServiceName% "Modify" access to %_currentRepo% and its subdirectories +echo Grant app pool %_prServiceName% "Read and Execute" access to the PRService and its subdirectories +call :Run icacls %_currentRepo%\src\System.Private.ServiceModel\tools\PRService /grant:r "IIS APPPOOL\%_prServiceName%":(OI)(CI)RX /Q +if ERRORLEVEL 1 goto :Failure + +:SkipPRService + +:: Grant master PR service's app pool access to current repo if master PRService exists +if /I '%_id%'=='%_idMaster%' goto :SkipGrantAccess +%_appcmd% list apppool %_prServiceMaster% >nul +if ERRORLEVEL 1 ( + echo SKIP granting PRService M permission to current repo. PRService not found: %_prServiceMaster%. + goto :SkipGrantAccess +) +echo Grant master PRService app pool: %_prServiceMaster% "Modify" access to %_currentRepo% and its sudirectories +call :Run icacls %_currentRepo% /grant:r "IIS APPPOOL\%_prServiceMaster%":(OI)(CI)M /Q +if ERRORLEVEL 1 goto :Failure + +:SkipGrantAccess + +:: Make sure there is an HTTPS binding in IIS site "Default Web Site" +%_appcmd% list site "Default Web Site" /text:* | findstr /i bindings | findstr /i https >nul +if ERRORLEVEL 1 ( + echo Add an HTTPS binding to "Default Web Site" + call :Run %_appcmd% set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:'] + if ERRORLEVEL 1 goto :Failure + :: Delete %_wcfTestDir% to force certificate regeneration later, which will fill in correct cert for https binding + if EXIST %_wcfTestDir% rmdir /s /q %_wcfTestDir% +) else ( + echo Found and will use existing HTTPS binding in "Default Web Site" +) + +:: Install certificates if %_wcfTestDir% does not exist; otherwise, assume certs are installed already +if EXIST %_wcfTestDir% ( + echo SKIP certificate generation. To force certificate generation, delete %_wcfTestDir% before running this script. + goto :SkipCertInstall +) + +:: Use master repo for cert generation if master repo exists; otherwise use current repo +if EXIST %_masterRepo% ( + set _certRepo=%_masterRepo% + set _certService=%_wcfServiceMaster% +) else ( + set _certRepo=%_currentRepo% + set _certService=%_wcfServiceName% +) +echo Use %_certService% for certificate service + +echo Build CertificateGenerator tool +call :Run %_certRepo%\src\System.Private.ServiceModel\tools\scripts\BuildCertUtil.cmd +if ERRORLEVEL 1 goto :Failure + +echo Run CertificateGenerator tool. This will take a little while... +md %_wcfTestDir% +set certGen=%_certRepo%\artifacts\bin\CertificateGenerator\Release\CertificateGenerator.exe +echo ^^^^^^^^^^^>%certGen%.config +call :Run %certGen% +if ERRORLEVEL 1 goto :Failure + +echo Configue SSL certificate ports +call :Run powershell -NoProfile -ExecutionPolicy unrestricted %_certRepo%\src\System.Private.ServiceModel\tools\scripts\ConfigHttpsPort.ps1 +if ERRORLEVEL 1 goto :Failure + +:: TODO: Grant all existing app pools named WCFService# 'Read' access to %_wcfTestDir%. This is not needed for now + +:: Grant app pool %_certService% "Read" access to %_wcfTestDir% and its subdirectories +echo Grant app pool %_certService% "Read" access to %_wcfTestDir% and its subdirectories +call :Run icacls %_wcfTestDir% /grant:r "IIS APPPOOL\%_certService%":(OI)(CI)R /Q +if ERRORLEVEL 1 goto :Failure + +:SkipCertInstall + +:: Unlock the configuration of sslFlags and Authentication +echo Unlock the IIS config section to allow sslFlags and Authentication methods to be overriden +call :Run %_appcmd% unlock config /section:"system.webServer/security/access" +if ERRORLEVEL 1 goto :Failure + +call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/anonymousAuthentication" +if ERRORLEVEL 1 goto :Failure + +call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/basicAuthentication" +if ERRORLEVEL 1 goto :Failure + +call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/digestAuthentication" +if ERRORLEVEL 1 goto :Failure + +call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/windowsAuthentication" +if ERRORLEVEL 1 goto :Failure + +:: Clean up log file if everything worked perfectly +if EXIST %_logFile% del %_logFile% /f /q + +echo. +echo All operations completed successfully! +goto :Done + +:Usage +echo. +echo Setup WCF test services hosted on IIS for the testing of WCF on .NET Core +echo. +echo Usage: %~n0 Id [/c] [/p:{PathToWcfRepo}] +echo Id: The Id of a WCF repo and its associated IIS hosted services to be created. +echo The Id will be appended to the name of all assets to be created. +echo %_idMaster%: if Id is '%_idMaster%', additional IIS hosted services such as PRService +echo will be created to serve as central services for other WCF repos. +echo /c: If specified, this will clean up any existing setup of Id instead of creating new. +echo /p: If an existing WCF repo is preferred to be used, use this parameter to provide the +echo path to a WCF repo. Otherwise, the script will clone a new WCF repo at %_repoHome% +echo to use as the source of WCF test service. +echo. +echo Examples: +echo %~n0 42 +echo :Create a WCF repo named 'wcf42' and IIS hosted services such as 'WcfService42' +echo %~n0 42 /c +echo :Clean up WCF repo 'wcf42' and all associated IIS hosted services such as 'WcfService42' +echo %~n0 42 /p:"c:\my\existing\wcf\repo" +echo :Create an IIS hosted service named 'wcfService42' by using existing WCF repo located at "c:\my\existing\wcf\repo". +goto :Done + +:Run +set _cmd=%* +if EXIST %_logFile% del %_logFile% /f /q +call %_cmd% >%_logFile% 2>&1 +exit /b + +:Failure +set _exitCode=1 +if DEFINED _cmd echo. & echo Failed to run: & echo %_cmd% +if EXIST %_logFile% type %_logFile% + +:Done +exit /b %_exitCode% +endlocal diff --git a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd index a677dd17217..02f6dd815ec 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd @@ -55,7 +55,7 @@ goto :NextArg :: Make sure this script is running in elevated if EXIST %_logFile% del %_logFile% /f /q -net session>nul 2>&1 +openfiles >nul 2>&1 if ERRORLEVEL 1 ( echo. & echo ERROR: Please run this script with elevated permission. goto :Failure @@ -181,9 +181,6 @@ if EXIST %_masterRepo% ( ) echo Use %_certService% for certificate service -echo Build CertificateGenerator tool -call :Run %_certRepo%\src\System.Private.ServiceModel\tools\scripts\BuildCertUtil.cmd -if ERRORLEVEL 1 goto :Failure echo Run CertificateGenerator tool. This will take a little while... md %_wcfTestDir% diff --git a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd new file mode 100644 index 00000000000..5bdf5aa410e --- /dev/null +++ b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd @@ -0,0 +1,91 @@ +@if "%_echo%" neq "on" echo off +setlocal + +REM This script should always be called from StartWCFSelfHostedSvc.cmd. +REM If PSEXEC_PATH is set to the full path of the folder containing psexec.exe, +REM it will be used to start the WCF self-hosted service as the Local System account. +REM If PSEXEC_PATH is not set, it will start the service under the current user. + +set _setuplog=%~dp0..\..\..\..\SelfHostedWcfServiceSetup.log +set _setupSemaphoreFile=%~dp0..\..\..\..\SelfHostedWcfServiceSemaphore.log + +echo Preparing to launch the WCF self hosted service + +if EXIST %_setupSemaphoreFile% del %_setupSemaphoreFile% + +REM Build tools +echo Building the WCF Self hosted service... +call %~dp0BuildWCFSelfHostedService.cmd >>%_setuplog% +SET __EXITCODE=%ERRORLEVEL% +if NOT [%__EXITCODE%]==[0] ( + echo ERROR: An error occurred while building WCF Self hosted Service. >>%_setuplog% + goto :done + ) + +echo Building the certificate generator ... +call %~dp0BuildCertUtil.cmd >>%_setuplog% +set __EXITCODE=%ERRORLEVEL% +if NOT [%__EXITCODE%]==[0] ( + echo ERROR: An error occurred while building the Certificate generator. >>%_setuplog% + goto :done + ) + +REM Config Certs +REM we need the direcotry to save the test.crl file. We are investigate a way to get rid of it +md c:\wcftest +REM Certificate configuration errors are all non fatal currently because we non cert tests will still pass +echo Generating certificates ... +%~dp0..\..\..\..\artifacts\bin\CertificateGenerator\Release\CertificateGenerator.exe >>%_setuplog% +if NOT [%ERRORLEVEL%]==[0] ( + echo Warning: An error occurred while running certificate generator. >>%_setuplog% + ) + +echo Configuring firewall... +call %~dp0OpenFirewallPorts.cmd >>%_setuplog% +if NOT [%ERRORLEVEL%]==[0] ( + echo Warning: An error occurred while running certificate generator. >>%_setuplog% + ) + +echo Configuring Https ports... +powershell -NoProfile -ExecutionPolicy unrestricted %~dp0ConfigHttpsPort.ps1 >>%_setuplog% +if NOT [%ERRORLEVEL%]==[0] ( + echo Warning: An error occurred while configuration https port. >>%_setuplog% + ) + +REM Write into our semaphore file to indicate our SelfHost test is running +echo Started Self host WCF service >>%_setupSemaphoreFile% + +REM +REM Start the self hosted WCF Test Service +if [%PSEXEC_PATH%]==[] ( + echo Starting the WCF Self hosted service under the local user account. >>%_setuplog% + REM This next call blocks until the service is terminated + call %~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe + set __EXITCODE=%ERRORLEVEL% + goto Cleanup +) + +if exist %PSEXEC_PATH%\psexec.exe ( + echo Starting the WCF Self hosted service under the Local System account using: >>%_setuplog% + echo call %PSEXEC_PATH%\psexec.exe -s -h %~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe >>%_setuplog% + REM This next call blocks until the service is terminated + call %PSEXEC_PATH%\psexec.exe -s -h %~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe + set __EXITCODE=%ERRORLEVEL% + goto Cleanup +) + +echo %PSEXEC_PATH% is not a valid path to psexec.exe +set __EXITCODE=1 + +:Cleanup +echo Cleaning up after the Self hosted service has completed +REM Update our semaphore file to indicate our SelfHost test is cleaning up +echo Cleaning up after Self host WCF service terminated. >>%_setupSemaphoreFile% +call %~dp0CleanUpWCFSelfHostedSvc.cmd +:done + +REM Deleting the semaphore file is an indication the cleanup script is done +REM and no longer writing to the setup log file. +if EXIST %_setupSemaphoreFile% del %_setupSemaphoreFile% + +exit /b %__EXITCODE% diff --git a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd index 5bdf5aa410e..8f087977667 100644 --- a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd @@ -13,23 +13,6 @@ echo Preparing to launch the WCF self hosted service if EXIST %_setupSemaphoreFile% del %_setupSemaphoreFile% -REM Build tools -echo Building the WCF Self hosted service... -call %~dp0BuildWCFSelfHostedService.cmd >>%_setuplog% -SET __EXITCODE=%ERRORLEVEL% -if NOT [%__EXITCODE%]==[0] ( - echo ERROR: An error occurred while building WCF Self hosted Service. >>%_setuplog% - goto :done - ) - -echo Building the certificate generator ... -call %~dp0BuildCertUtil.cmd >>%_setuplog% -set __EXITCODE=%ERRORLEVEL% -if NOT [%__EXITCODE%]==[0] ( - echo ERROR: An error occurred while building the Certificate generator. >>%_setuplog% - goto :done - ) - REM Config Certs REM we need the direcotry to save the test.crl file. We are investigate a way to get rid of it md c:\wcftest From 01fda6eebfd4cca41125b1da091b09b7986cef69 Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Thu, 4 Aug 2022 22:52:26 +0200 Subject: [PATCH 2/7] update docker scripts --- .gitignore | 4 +- Docker/Client/Linux.dockerfile | 3 +- Docker/Client/Windows.dockerfile | 2 +- .../tools/scripts/BuildTest.cmd | 7 +- .../tools/scripts/DockerStartWCFService.cmd | 13 +- .../scripts/DockerStartWCFTest-Linux.cmd | 21 +- .../scripts/DockerStartWCFTest-Windows.cmd | 17 +- .../tools/scripts/InstallRootCertificate.sh | 10 +- .../SetupWcfIISHostedService - Copy.cmd | 268 ------------------ .../scripts/SetupWcfIISHostedService.cmd | 7 + .../scripts/StartWCFSelfHostedSvcDoWork.cmd | 23 ++ 11 files changed, 79 insertions(+), 296 deletions(-) delete mode 100644 src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd diff --git a/.gitignore b/.gitignore index a79f8547f45..e7acbd3536e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ syntax: glob # Tool Runtime Dir /[Tt]ools/ .dotnet/ +.dotnet-linux/ # User-specific files *.suo @@ -14,6 +15,7 @@ syntax: glob # Build results artifacts/ +artifacts-linux/ .idea/ [Dd]ebug/ [Dd]ebugPublic/ @@ -279,4 +281,4 @@ config.ps1 # Debug files *.etl -*.dmp \ No newline at end of file +*.dmp diff --git a/Docker/Client/Linux.dockerfile b/Docker/Client/Linux.dockerfile index 2a3efdbb873..48a58653232 100644 --- a/Docker/Client/Linux.dockerfile +++ b/Docker/Client/Linux.dockerfile @@ -1,3 +1,4 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0.300-focal-amd64 -CMD /wcf/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh && /wcf/eng/common/cibuild.sh -configuration Release -prepareMachine -t --integrationTest +CMD /wcf/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh && /wcf/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh --cert-file /tmp/wcfrootca.crt && /wcf/eng/common/cibuild.sh -configuration Release --prepareMachine --ci --test --integrationTest + diff --git a/Docker/Client/Windows.dockerfile b/Docker/Client/Windows.dockerfile index a163c08829a..184c7c6a70b 100644 --- a/Docker/Client/Windows.dockerfile +++ b/Docker/Client/Windows.dockerfile @@ -2,6 +2,6 @@ FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] -CMD C:\wcf\src\System.Private.ServiceModel\tools\scripts\SetClientEnv-Windows.cmd; C:\wcf\eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Restore=false /p:Sign=false /p:Test=true /p:IntegrationTest=true /p:Pack=false /p:Publish=false; +CMD C:\wcf\src\System.Private.ServiceModel\tools\scripts\SetClientEnv-Windows.cmd; C:\wcf\eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Restore=true /p:Sign=false /p:Test=true /p:IntegrationTest=true /p:Pack=false /p:Publish=false; diff --git a/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd b/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd index 6f1a302d7d5..956261c9343 100644 --- a/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd @@ -1,8 +1,7 @@ :: Build tests -::Windows Build -cd ..\..\..\..\ -call eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false +::Windows Release Build +call ..\..\..\..\eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false -::Linux Build +::Linux Build - not used ::call eng\common\cibuild.sh -configuration Release -preparemachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd index 6d1d53828f7..9890b7b6ff0 100644 --- a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd @@ -6,9 +6,9 @@ echo ********************************** set _exitCode=0 ::todo use vars -set ServiceImageTag = "wcf:service" +set "ServiceImageTag=wcf:service" set "ServiceContainerName=WCFServiceContainer" - +set "ServiceHostName=wcfservicehost" :: Make sure docker is running docker ps>nul 2>&1 @@ -33,7 +33,7 @@ cd ../../../.. echo. & echo Building Docker image for WCF service :: Building docker image. -docker build -f ./Docker/Service/Dockerfile -t wcf:service . +docker build -f ./Docker/Service/Dockerfile -t %ServiceImageTag% . if ERRORLEVEL 1 ( echo. & echo ERROR: Building docker image failed. goto :Failure @@ -42,8 +42,8 @@ echo. & echo Building image success.. :: Starting docker container from the image. echo. & echo Starting WCF Service Container -:: mount current directory for wcf source as container volume - C:\wcf -docker run --name %ServiceContainerName% --rm -it -d -v "%cd%":"C:\wcf" wcf:service +:: run docker container and mount current directory for wcf source as container volume - C:\wcf +docker run --name %ServiceContainerName% --rm -it -d -h %ServiceHostName% -v "%cd%":"C:\wcf" %ServiceImageTag% if ERRORLEVEL 1 ( echo. & echo ERROR: Starting WCF service container failed. goto :Failure @@ -52,6 +52,7 @@ if ERRORLEVEL 1 ( echo. & echo Started WCF Service Container. :: print service container IP address docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" %ServiceContainerName% +echo %ServiceHostName% exit /b @@ -61,4 +62,4 @@ set _exitCode=1 :Done exit /b %_exitCode% -endlocal \ No newline at end of file +endlocal diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd index 75c3fa232c9..8c143b26078 100644 --- a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd @@ -5,6 +5,9 @@ echo Starting WCF Client on Docker echo ********************************** set _exitCode=0 +set "TestContainerName=WCFTestContainerLinux" +set "ServiceContainerName=WCFServiceContainer" +set "ServiceHostName=wcfservicehost" :: Make sure docker is running docker ps>nul 2>&1 @@ -16,23 +19,24 @@ if ERRORLEVEL 1 ( echo. & echo Checking WCF service container status and IP address. ::Switch to Windows Containers to check WCF Service status -CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine +START /B /WAIT "" "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine :: Check if WCF service is already running -docker container inspect -f '{{.State.Status}}' WCFServiceContainer +docker container inspect -f '{{.State.Status}}' %ServiceContainerName% if ERRORLEVEL 1 ( echo. & echo Warning: WCF Service container is not running. CALL DockerStartWCFService.cmd ) :: set ServiceUri -FOR /F "tokens=* USEBACKQ" %%F IN (`docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" WCFServiceContainer`) DO ( -SET ServiceUri=%%F/WcfService38 +FOR /F "tokens=* USEBACKQ" %%F IN (`docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" %ServiceContainerName%`) DO ( +:: SET ServiceIPAddress=%%F +SET ServiceUri=%ServiceHostName%/WcfService38 ) echo %ServiceUri% ::Switch to Linux Containers to run Linux tests -CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchLinuxEngine +START /B /WAIT "" "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchLinuxEngine :: change directory to wcf src cd ../../../.. @@ -49,7 +53,10 @@ echo. & echo Building image success.. :: Starting docker container from the image. echo. & echo Starting WCF client -docker run --name wcfclient_container --rm -it --memory=2g -v "%cd%":"/wcf" -e ServiceUri=%ServiceUri% wcf:client +:: run docker container and mount current directory for wcf source as container volume '/wcf' +:: mount volume '.dotnet-linux' CLI cache directory inside the container as '.dotnet' +:: mount volume 'artifacts-linux' inside the container as 'artifacts' +docker run --name %TestContainerName% --rm -it --memory=4g -v "%cd%":"/wcf" -v "%cd%/.dotnet-linux":"/wcf/.dotnet" -v "%cd%/artifacts-linux":"/wcf/artifacts" -v "%cd%/artifacts/bin":"/wcf/artifacts/bin" -v "%cd%/artifacts/obj":"/wcf/artifacts/obj" -e ServiceUri=%ServiceUri% wcf:client if ERRORLEVEL 1 ( echo. & echo ERROR: Starting WCF client container failed. goto :Failure @@ -64,4 +71,4 @@ set _exitCode=1 :Done exit /b %_exitCode% -endlocal \ No newline at end of file +endlocal diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd index 4a463f49dcc..3dbe6921ee4 100644 --- a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd @@ -5,6 +5,9 @@ echo Starting WCF Client on Docker echo ********************************** set _exitCode=0 +set "TestContainerName=WCFTestContainerWin" +set "ServiceContainerName=WCFServiceContainer" +set "ServiceHostName=wcfservicehost" :: Make sure docker is running docker ps>nul 2>&1 @@ -16,18 +19,19 @@ if ERRORLEVEL 1 ( echo. & echo Checking WCF service container status and IP address. ::Switch to Windows Containers to check WCF Service status -CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine +START /B /WAIT "" "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine :: Check if WCF service is already running -docker container inspect -f '{{.State.Status}}' WCFServiceContainer +docker container inspect -f '{{.State.Status}}' %ServiceContainerName% if ERRORLEVEL 1 ( echo. & echo Warning: WCF Service container is not running. CALL DockerStartWCFService.cmd ) :: set ServiceUri -FOR /F "tokens=* USEBACKQ" %%F IN (`docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" WCFServiceContainer`) DO ( -SET ServiceUri=%%F/WcfService38 +FOR /F "tokens=* USEBACKQ" %%F IN (`docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" %ServiceContainerName%`) DO ( +:: SET ServiceIPAddress=%%F +SET ServiceUri=%ServiceHostName%/WcfService38 ) echo %ServiceUri% @@ -47,7 +51,8 @@ echo. & echo Building image success.. :: Starting docker container from the image. echo. & echo Starting WCF client -docker run --name wcfclient_container --rm -it --memory=2g -v "%cd%":"C:\wcf" -e ServiceUri=%ServiceUri% wcf:client +:: run docker container and mount current directory for wcf source as container volume C:\wcf +docker run --name %TestContainerName% --rm -it --memory=4g -v "%cd%":"C:\wcf" -e ServiceUri=%ServiceUri% wcf:client if ERRORLEVEL 1 ( echo. & echo ERROR: Starting WCF client container failed. goto :Failure @@ -62,4 +67,4 @@ set _exitCode=1 :Done exit /b %_exitCode% -endlocal \ No newline at end of file +endlocal diff --git a/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh b/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh index fae4b6d8ff5..1cdf6807a4b 100755 --- a/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh +++ b/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh @@ -22,8 +22,14 @@ acquire_certificate() # Need to make a call as the original user as we need to write to the cert store for the current # user, not as root - echo "Making a call to '${__service_host}/TestHost.svc/RootCert' as user '$SUDO_USER'" - sudo -E -u $SUDO_USER $__curl_exe -o $__cafile "http://${__service_host}/TestHost.svc/RootCert?asPem=true" + if [ "$EUID" -ne 0 ]; then + echo "Making a call to '${__service_host}/TestHost.svc/RootCert' as user '$SUDO_USER'" + sudo -E -u $SUDO_USER $__curl_exe -o $__cafile "http://${__service_host}/TestHost.svc/RootCert?asPem=true" + else + # Docker containers has no Sudo installed, by default it is running root user + echo "Making a call to '${ServiceUri}/TestHost.svc/RootCert' as root user" + $__curl_exe -o $__cafile "http://${ServiceUri}/TestHost.svc/RootCert?asPem=true" + fi return $? } diff --git a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd deleted file mode 100644 index a677dd17217..00000000000 --- a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService - Copy.cmd +++ /dev/null @@ -1,268 +0,0 @@ -@echo off -setlocal - -set _id=%1 -set _idMaster=Master -set _wcfTestDir=c:\WCFTest -set _repoHome=c:\git -set _pathIISHostedWcfService=src\System.Private.ServiceModel\tools\IISHostedWcfService -set _currentRepo=%_repoHome%\wcf%_id% -set _masterRepo=%_repoHome%\wcf%_idMaster% -set _prServiceName=PRService%_id% -set _wcfServiceName=WcfService%_id% -set _prServiceMaster=PRService%_idMaster% -set _wcfServiceMaster=WcfService%_idMaster% -set _logFile="%~dp0%~n0.log" -set _certExpirationInDays=99 -set _githubWcfRepoUrl=https://github.com/dotnet/wcf -set _exitCode=0 -set _cmd= -set _cleanup= -set _useExistingRepo= - -if '%1'=='' goto :Usage -if '%1'=='/?' goto :Usage -if '%1'=='-?' goto :Usage -if '%1'=='/help' goto :Usage -if '%1'=='-help' goto :Usage - -echo. -echo %date% %time% -echo ============================== - -:: Parse command line arguments -:NextArg -shift -set arg=%1 - -if '%arg%'=='' goto :NoMoreArg - -if /I '%arg%'=='/c' ( - set _cleanup=true - goto :NextArg -) - -if /I '%arg:~0,2%'=='/p' ( - set _useExistingRepo=true - set _currentRepo=%arg:~3% - goto :NextArg -) - -echo IGNORED unknown argument ^(use /? for help^): %arg% -goto :NextArg - -:NoMoreArg - -:: Make sure this script is running in elevated -if EXIST %_logFile% del %_logFile% /f /q -net session>nul 2>&1 -if ERRORLEVEL 1 ( - echo. & echo ERROR: Please run this script with elevated permission. - goto :Failure -) - -:: Make sure IIS appcmd.exe is accessible -set _appcmd=%windir%\System32\inetsrv\appcmd.exe -if NOT EXIST %_appcmd% ( - echo Could not find: %_appcmd%. - echo Please make sure IIS is installed. - goto :Failure -) - -:: Clean up any existing setup -echo Deleting WCF repo at %_currentRepo% if exists and associated application pools and services hosted on IIS... -%_appcmd% delete app "Default Web Site/%_prServiceName%" >nul -%_appcmd% delete apppool %_prServiceName% >nul -%_appcmd% delete app "Default Web Site/%_wcfServiceName%" >nul -%_appcmd% delete apppool %_wcfServiceName% >nul -if EXIST %_currentRepo% if DEFINED _useExistingRepo (echo User provided repo is not deleted: %_currentRepo%) else (rmdir /s /q %_currentRepo%) -if EXIST %_wcfTestDir% if /I '%_id%'=='%_idMaster%' rmdir /s /q %_wcfTestDir% -echo Clean up done. -if DEFINED _cleanup goto :Done - -:: Determine if we need to clone a new WCF repo -if DEFINED _useExistingRepo ( - if NOT EXIST %_currentRepo% echo ERROR: The provided WCF repo was not found: %_currentRepo% & goto :Failure - echo Use provided WCF repo: %_currentRepo% - goto :SkipCloneRepo -) - -:: Make sure git.exe is available -where git.exe /Q -if ERRORLEVEL 1 ( - echo Could not find: git.exe. - echo Please make sure git is installed and its location is part of PATH environment. - goto :Failure -) - -:: Clone a WCF repo -set _cmd=git clone %_githubWcfRepoUrl% %_currentRepo% -call %_cmd% -if ERRORLEVEL 1 goto :Failure -pushd %_currentRepo% -call :Run git config --add origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" -if ERRORLEVEL 1 goto :Failure -popd - -:SkipCloneRepo - -:: Create a new application pool and an application for the WCF test service -echo Create IIS application pool: %_wcfServiceName% -call :Run %_appcmd% add apppool /name:%_wcfServiceName% /processModel.IdentityType:LocalSystem /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated -if ERRORLEVEL 1 goto :Failure -echo Create IIS application: %_wcfServiceName% -call :Run %_appcmd% add app /site.name:"Default Web Site" /path:/%_wcfServiceName% /physicalPath:%_currentRepo%\%_pathIISHostedWcfService% /applicationPool:%_wcfServiceName% /enabledProtocols:"http,net.tcp" -if ERRORLEVEL 1 goto :Failure - -:: Grant app pool %_wcfServiceName% "Read and Execute" access to the IISHostedWcfService and its subdirectories -echo Grant app pool %_wcfServiceName% "Read and Execute" access to %_currentRepo%\%_pathIISHostedWcfService% -call :Run icacls %_currentRepo%\%_pathIISHostedWcfService% /grant:r "IIS APPPOOL\%_wcfServiceName%":(OI)(CI)RX /Q -if ERRORLEVEL 1 goto :Failure - -:: Setup PR service only if this is a master service -if /I NOT '%_id%'=='%_idMaster%' ( - echo SKIP creating PRService. PRService will be created when Id=%_idMaster%. - goto :SkipPRService -) - -:: Create a new application pool and an application for the PR service -echo Create IIS application pool: %_prServiceName% -call :Run %_appcmd% add apppool /name:%_prServiceName% /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated -if ERRORLEVEL 1 goto :Failure -echo Create IIS application: %_prServiceName% -call :Run %_appcmd% add app /site.name:"Default Web Site" /path:/%_prServiceName% /physicalPath:%_currentRepo%\src\System.Private.ServiceModel\tools\PRService -applicationPool:%_prServiceName% -if ERRORLEVEL 1 goto :Failure - -:: Grant app pool %_prServiceName% "Modify" access to %_currentRepo% and its subdirectories -echo Grant app pool %_prServiceName% "Read and Execute" access to the PRService and its subdirectories -call :Run icacls %_currentRepo%\src\System.Private.ServiceModel\tools\PRService /grant:r "IIS APPPOOL\%_prServiceName%":(OI)(CI)RX /Q -if ERRORLEVEL 1 goto :Failure - -:SkipPRService - -:: Grant master PR service's app pool access to current repo if master PRService exists -if /I '%_id%'=='%_idMaster%' goto :SkipGrantAccess -%_appcmd% list apppool %_prServiceMaster% >nul -if ERRORLEVEL 1 ( - echo SKIP granting PRService M permission to current repo. PRService not found: %_prServiceMaster%. - goto :SkipGrantAccess -) -echo Grant master PRService app pool: %_prServiceMaster% "Modify" access to %_currentRepo% and its sudirectories -call :Run icacls %_currentRepo% /grant:r "IIS APPPOOL\%_prServiceMaster%":(OI)(CI)M /Q -if ERRORLEVEL 1 goto :Failure - -:SkipGrantAccess - -:: Make sure there is an HTTPS binding in IIS site "Default Web Site" -%_appcmd% list site "Default Web Site" /text:* | findstr /i bindings | findstr /i https >nul -if ERRORLEVEL 1 ( - echo Add an HTTPS binding to "Default Web Site" - call :Run %_appcmd% set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:'] - if ERRORLEVEL 1 goto :Failure - :: Delete %_wcfTestDir% to force certificate regeneration later, which will fill in correct cert for https binding - if EXIST %_wcfTestDir% rmdir /s /q %_wcfTestDir% -) else ( - echo Found and will use existing HTTPS binding in "Default Web Site" -) - -:: Install certificates if %_wcfTestDir% does not exist; otherwise, assume certs are installed already -if EXIST %_wcfTestDir% ( - echo SKIP certificate generation. To force certificate generation, delete %_wcfTestDir% before running this script. - goto :SkipCertInstall -) - -:: Use master repo for cert generation if master repo exists; otherwise use current repo -if EXIST %_masterRepo% ( - set _certRepo=%_masterRepo% - set _certService=%_wcfServiceMaster% -) else ( - set _certRepo=%_currentRepo% - set _certService=%_wcfServiceName% -) -echo Use %_certService% for certificate service - -echo Build CertificateGenerator tool -call :Run %_certRepo%\src\System.Private.ServiceModel\tools\scripts\BuildCertUtil.cmd -if ERRORLEVEL 1 goto :Failure - -echo Run CertificateGenerator tool. This will take a little while... -md %_wcfTestDir% -set certGen=%_certRepo%\artifacts\bin\CertificateGenerator\Release\CertificateGenerator.exe -echo ^^^^^^^^^^^>%certGen%.config -call :Run %certGen% -if ERRORLEVEL 1 goto :Failure - -echo Configue SSL certificate ports -call :Run powershell -NoProfile -ExecutionPolicy unrestricted %_certRepo%\src\System.Private.ServiceModel\tools\scripts\ConfigHttpsPort.ps1 -if ERRORLEVEL 1 goto :Failure - -:: TODO: Grant all existing app pools named WCFService# 'Read' access to %_wcfTestDir%. This is not needed for now - -:: Grant app pool %_certService% "Read" access to %_wcfTestDir% and its subdirectories -echo Grant app pool %_certService% "Read" access to %_wcfTestDir% and its subdirectories -call :Run icacls %_wcfTestDir% /grant:r "IIS APPPOOL\%_certService%":(OI)(CI)R /Q -if ERRORLEVEL 1 goto :Failure - -:SkipCertInstall - -:: Unlock the configuration of sslFlags and Authentication -echo Unlock the IIS config section to allow sslFlags and Authentication methods to be overriden -call :Run %_appcmd% unlock config /section:"system.webServer/security/access" -if ERRORLEVEL 1 goto :Failure - -call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/anonymousAuthentication" -if ERRORLEVEL 1 goto :Failure - -call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/basicAuthentication" -if ERRORLEVEL 1 goto :Failure - -call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/digestAuthentication" -if ERRORLEVEL 1 goto :Failure - -call :Run %_appcmd% unlock config /section:"system.webServer/security/authentication/windowsAuthentication" -if ERRORLEVEL 1 goto :Failure - -:: Clean up log file if everything worked perfectly -if EXIST %_logFile% del %_logFile% /f /q - -echo. -echo All operations completed successfully! -goto :Done - -:Usage -echo. -echo Setup WCF test services hosted on IIS for the testing of WCF on .NET Core -echo. -echo Usage: %~n0 Id [/c] [/p:{PathToWcfRepo}] -echo Id: The Id of a WCF repo and its associated IIS hosted services to be created. -echo The Id will be appended to the name of all assets to be created. -echo %_idMaster%: if Id is '%_idMaster%', additional IIS hosted services such as PRService -echo will be created to serve as central services for other WCF repos. -echo /c: If specified, this will clean up any existing setup of Id instead of creating new. -echo /p: If an existing WCF repo is preferred to be used, use this parameter to provide the -echo path to a WCF repo. Otherwise, the script will clone a new WCF repo at %_repoHome% -echo to use as the source of WCF test service. -echo. -echo Examples: -echo %~n0 42 -echo :Create a WCF repo named 'wcf42' and IIS hosted services such as 'WcfService42' -echo %~n0 42 /c -echo :Clean up WCF repo 'wcf42' and all associated IIS hosted services such as 'WcfService42' -echo %~n0 42 /p:"c:\my\existing\wcf\repo" -echo :Create an IIS hosted service named 'wcfService42' by using existing WCF repo located at "c:\my\existing\wcf\repo". -goto :Done - -:Run -set _cmd=%* -if EXIST %_logFile% del %_logFile% /f /q -call %_cmd% >%_logFile% 2>&1 -exit /b - -:Failure -set _exitCode=1 -if DEFINED _cmd echo. & echo Failed to run: & echo %_cmd% -if EXIST %_logFile% type %_logFile% - -:Done -exit /b %_exitCode% -endlocal diff --git a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd index 02f6dd815ec..941f5390e3a 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd @@ -185,6 +185,13 @@ echo Use %_certService% for certificate service echo Run CertificateGenerator tool. This will take a little while... md %_wcfTestDir% set certGen=%_certRepo%\artifacts\bin\CertificateGenerator\Release\CertificateGenerator.exe + +IF NOT EXIST "%certGen%" ( + echo Build CertificateGenerator tool + call :Run %_certRepo%\src\System.Private.ServiceModel\tools\scripts\BuildCertUtil.cmd + if ERRORLEVEL 1 goto :Failure +) + echo ^^^^^^^^^^^>%certGen%.config call :Run %certGen% if ERRORLEVEL 1 goto :Failure diff --git a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd index 8f087977667..5efd40c7048 100644 --- a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork.cmd @@ -13,6 +13,29 @@ echo Preparing to launch the WCF self hosted service if EXIST %_setupSemaphoreFile% del %_setupSemaphoreFile% +set wcfSelfhosted=%~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe +REM Build tools +IF NOT EXIST "%wcfSelfhosted%" ( + echo Building the WCF Self hosted service... + call %~dp0BuildWCFSelfHostedService.cmd >>%_setuplog% + SET __EXITCODE=%ERRORLEVEL% + if NOT [%__EXITCODE%]==[0] ( + echo ERROR: An error occurred while building WCF Self hosted Service. >>%_setuplog% + goto :done + ) +) + +set certGen=%~dp0..\..\..\..\artifacts\bin\CertificateGenerator\Release\CertificateGenerator.exe +IF NOT EXIST "%certGen%" ( + echo Building the certificate generator ... + call %~dp0BuildCertUtil.cmd >>%_setuplog% + set __EXITCODE=%ERRORLEVEL% + if NOT [%__EXITCODE%]==[0] ( + echo ERROR: An error occurred while building the Certificate generator. >>%_setuplog% + goto :done + ) +) + REM Config Certs REM we need the direcotry to save the test.crl file. We are investigate a way to get rid of it md c:\wcftest From 8e8dca9540b4d0c902244cd310fed06651e9b5e2 Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Thu, 4 Aug 2022 23:00:04 +0200 Subject: [PATCH 3/7] update docker ignore --- .dockerignore | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6269864134b..882b77e06af 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,2 @@ -# Ignore everything +# Ignore everything and use volumes * - -# Allow files and directories -#!global.json -#!NuGet.config -#!/eng -#!/src/System.Private.ServiceModel/tools -#!/artifacts/bin/CertificateGenerator -#!/artifacts/bin/SelfHostedWCFService \ No newline at end of file From 200a22e6b486ddcec68e7e57fd5f43620304b4bd Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Sat, 6 Aug 2022 17:38:49 +0200 Subject: [PATCH 4/7] update scripts --- .../tools/scripts/SetClientEnv-Linux.sh | 2 - .../tools/scripts/SetClientEnv-Windows.cmd | 2 - .../StartWCFSelfHostedSvcDoWork - Copy.cmd | 91 ------------------- 3 files changed, 95 deletions(-) delete mode 100644 src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh index 0b595cabcc6..0b2c1474447 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh @@ -4,8 +4,6 @@ export Server_Domain_Joined=true export Ambient_Credentials_Available=true export Domain_Available=true export Explicit_Credentials_Available=true -export ExplicitUserName=indgaunt -export ExplicitPassword=IU872_oR4189l6_HT8 export SSL_Available=true export Root_Certificate_Installed=true export Client_Certificate_Installed=true diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd index 99b2309b391..17e98f1da72 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd @@ -4,8 +4,6 @@ setx Ambient_Credentials_Available true setx SPN_Available true setx NTLM_Available true setx Server_Domain_Joined true -setx ExplicitUserName indgaunt -setx ExplicitPassword IU872_oR4189l6_HT8 setx Domain_Available true setx UPN_Available true setx Root_Certificate_Installed true diff --git a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd b/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd deleted file mode 100644 index 5bdf5aa410e..00000000000 --- a/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvcDoWork - Copy.cmd +++ /dev/null @@ -1,91 +0,0 @@ -@if "%_echo%" neq "on" echo off -setlocal - -REM This script should always be called from StartWCFSelfHostedSvc.cmd. -REM If PSEXEC_PATH is set to the full path of the folder containing psexec.exe, -REM it will be used to start the WCF self-hosted service as the Local System account. -REM If PSEXEC_PATH is not set, it will start the service under the current user. - -set _setuplog=%~dp0..\..\..\..\SelfHostedWcfServiceSetup.log -set _setupSemaphoreFile=%~dp0..\..\..\..\SelfHostedWcfServiceSemaphore.log - -echo Preparing to launch the WCF self hosted service - -if EXIST %_setupSemaphoreFile% del %_setupSemaphoreFile% - -REM Build tools -echo Building the WCF Self hosted service... -call %~dp0BuildWCFSelfHostedService.cmd >>%_setuplog% -SET __EXITCODE=%ERRORLEVEL% -if NOT [%__EXITCODE%]==[0] ( - echo ERROR: An error occurred while building WCF Self hosted Service. >>%_setuplog% - goto :done - ) - -echo Building the certificate generator ... -call %~dp0BuildCertUtil.cmd >>%_setuplog% -set __EXITCODE=%ERRORLEVEL% -if NOT [%__EXITCODE%]==[0] ( - echo ERROR: An error occurred while building the Certificate generator. >>%_setuplog% - goto :done - ) - -REM Config Certs -REM we need the direcotry to save the test.crl file. We are investigate a way to get rid of it -md c:\wcftest -REM Certificate configuration errors are all non fatal currently because we non cert tests will still pass -echo Generating certificates ... -%~dp0..\..\..\..\artifacts\bin\CertificateGenerator\Release\CertificateGenerator.exe >>%_setuplog% -if NOT [%ERRORLEVEL%]==[0] ( - echo Warning: An error occurred while running certificate generator. >>%_setuplog% - ) - -echo Configuring firewall... -call %~dp0OpenFirewallPorts.cmd >>%_setuplog% -if NOT [%ERRORLEVEL%]==[0] ( - echo Warning: An error occurred while running certificate generator. >>%_setuplog% - ) - -echo Configuring Https ports... -powershell -NoProfile -ExecutionPolicy unrestricted %~dp0ConfigHttpsPort.ps1 >>%_setuplog% -if NOT [%ERRORLEVEL%]==[0] ( - echo Warning: An error occurred while configuration https port. >>%_setuplog% - ) - -REM Write into our semaphore file to indicate our SelfHost test is running -echo Started Self host WCF service >>%_setupSemaphoreFile% - -REM -REM Start the self hosted WCF Test Service -if [%PSEXEC_PATH%]==[] ( - echo Starting the WCF Self hosted service under the local user account. >>%_setuplog% - REM This next call blocks until the service is terminated - call %~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe - set __EXITCODE=%ERRORLEVEL% - goto Cleanup -) - -if exist %PSEXEC_PATH%\psexec.exe ( - echo Starting the WCF Self hosted service under the Local System account using: >>%_setuplog% - echo call %PSEXEC_PATH%\psexec.exe -s -h %~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe >>%_setuplog% - REM This next call blocks until the service is terminated - call %PSEXEC_PATH%\psexec.exe -s -h %~dp0..\..\..\..\artifacts\bin\SelfHostedWcfService\Release\SelfHostedWcfService.exe - set __EXITCODE=%ERRORLEVEL% - goto Cleanup -) - -echo %PSEXEC_PATH% is not a valid path to psexec.exe -set __EXITCODE=1 - -:Cleanup -echo Cleaning up after the Self hosted service has completed -REM Update our semaphore file to indicate our SelfHost test is cleaning up -echo Cleaning up after Self host WCF service terminated. >>%_setupSemaphoreFile% -call %~dp0CleanUpWCFSelfHostedSvc.cmd -:done - -REM Deleting the semaphore file is an indication the cleanup script is done -REM and no longer writing to the setup log file. -if EXIST %_setupSemaphoreFile% del %_setupSemaphoreFile% - -exit /b %__EXITCODE% From e32c1286bfa51a4ebfe5243e4510e14c39e13fe4 Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Sat, 6 Aug 2022 17:49:06 +0200 Subject: [PATCH 5/7] env script updates --- .../tools/scripts/SetClientEnv-Linux.sh | 5 ++++- .../tools/scripts/SetClientEnv-Windows.cmd | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh index 0b2c1474447..5361ffa4510 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh @@ -4,8 +4,11 @@ export Server_Domain_Joined=true export Ambient_Credentials_Available=true export Domain_Available=true export Explicit_Credentials_Available=true +#set username and password +#export ExplicitUserName= +#export ExplicitPassword= export SSL_Available=true export Root_Certificate_Installed=true export Client_Certificate_Installed=true export Peer_Certificate_Installed=true -export NegotiateTestDomain=REDMOND.CORP.MICROSOFT.COM \ No newline at end of file +export NegotiateTestDomain=REDMOND.CORP.MICROSOFT.COM diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd index 17e98f1da72..a2e106f0560 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd @@ -4,8 +4,11 @@ setx Ambient_Credentials_Available true setx SPN_Available true setx NTLM_Available true setx Server_Domain_Joined true +::set username and password +::setx ExplicitUserName +::setx ExplicitPassword setx Domain_Available true setx UPN_Available true setx Root_Certificate_Installed true setx Client_Certificate_Installed true -setx Peer_Certificate_Installed true \ No newline at end of file +setx Peer_Certificate_Installed true From 59543364d683a9a9d501faf334458f7da32c635f Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Thu, 29 Sep 2022 12:03:09 +0200 Subject: [PATCH 6/7] Add extra comments --- .dockerignore | 6 +++++- Docker/Client/Linux.dockerfile | 5 +++++ Docker/Client/Windows.dockerfile | 5 +++++ Docker/Service/Dockerfile | 12 +++++++++--- .../tools/scripts/BuildSource.cmd | 5 ++++- .../tools/scripts/BuildTest.cmd | 9 +++++---- .../tools/scripts/DockerStartWCFService.cmd | 15 +++++++++------ .../tools/scripts/DockerStartWCFTest-Linux.cmd | 13 ++++++++----- .../tools/scripts/DockerStartWCFTest-Windows.cmd | 10 ++++++---- .../tools/scripts/InstallRootCertificate.sh | 6 +++--- .../tools/scripts/SetClientEnv-Linux.sh | 3 ++- .../tools/scripts/SetClientEnv-Windows.cmd | 3 ++- 12 files changed, 63 insertions(+), 29 deletions(-) diff --git a/.dockerignore b/.dockerignore index 882b77e06af..0905e52204a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,6 @@ -# Ignore everything and use volumes +# https://docs.docker.com/engine/reference/builder/#dockerignore-file +# Exclude files not relevant to the build +# This helps to avoid unnecessarily sending large or sensitive files and directories to Docker daemon + +# Ignore everything and use Docker volumes * diff --git a/Docker/Client/Linux.dockerfile b/Docker/Client/Linux.dockerfile index 48a58653232..f120ee49e97 100644 --- a/Docker/Client/Linux.dockerfile +++ b/Docker/Client/Linux.dockerfile @@ -1,4 +1,9 @@ +# Linux Docker image - Host WCF Client FROM mcr.microsoft.com/dotnet/sdk:6.0.300-focal-amd64 +# Run commands: +# Setup environment variables +# Install Root certificate +# Run WCF Tests CMD /wcf/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh && /wcf/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh --cert-file /tmp/wcfrootca.crt && /wcf/eng/common/cibuild.sh -configuration Release --prepareMachine --ci --test --integrationTest diff --git a/Docker/Client/Windows.dockerfile b/Docker/Client/Windows.dockerfile index 184c7c6a70b..809c7bc0815 100644 --- a/Docker/Client/Windows.dockerfile +++ b/Docker/Client/Windows.dockerfile @@ -1,7 +1,12 @@ +# Windows Docker image - Host WCF Client FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 +# Set Powershell as default Container shell SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] +# Run commands: +# Setup environment variables +# Run WCF Tests CMD C:\wcf\src\System.Private.ServiceModel\tools\scripts\SetClientEnv-Windows.cmd; C:\wcf\eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Restore=true /p:Sign=false /p:Test=true /p:IntegrationTest=true /p:Pack=false /p:Publish=false; diff --git a/Docker/Service/Dockerfile b/Docker/Service/Dockerfile index b268be72f4c..1549a87b88b 100644 --- a/Docker/Service/Dockerfile +++ b/Docker/Service/Dockerfile @@ -1,13 +1,19 @@ +# Windows Docker image - Host WCF Service FROM mcr.microsoft.com/dotnet/framework/wcf -# IIS Hosted +# Open IIS Hosted ports EXPOSE 80 808 443 44345 -# Self Hosted +# Open Self Hosted ports EXPOSE 8081 8083 8084 44285 809 +# Set Powershell as default Container shell SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] + +# Set ENTRYPOINT to Powershell +# Keeps the Service Container always running ENTRYPOINT ["powershell"] -# Setup WCF web hosted and self hosted services - Container Startup CMD +# Container Startup command: +# Setup WCF IIS Hosted and Self Hosted Services, using Docker Volume at C:\wcf CMD ./wcf/src/System.Private.ServiceModel/tools/scripts/SetupWcfIISHostedService.cmd 38 /p:"c:\wcf"; ./wcf/src/System.Private.ServiceModel/tools/scripts/StartWCFSelfHostedSvc.cmd; powershell diff --git a/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd b/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd index cb902351698..38247e6e38f 100644 --- a/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/BuildSource.cmd @@ -1,4 +1,7 @@ +:: Build tools on Docker host machine. +:: This saves time during container startup and running tests (simply mount a volume for the build artifacts) + :: Build certifcate generator tool call BuildCertUtil.cmd -:: Build Selfhosted service +:: Build Self Hosted service call BuildWCFSelfHostedService.cmd diff --git a/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd b/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd index 956261c9343..c66f8a028b8 100644 --- a/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/BuildTest.cmd @@ -1,7 +1,8 @@ -:: Build tests -::Windows Release Build +:: Build tests on Docker host machine. + +:: Windows Release Build call ..\..\..\..\eng\common\cibuild.cmd -configuration Release -prepareMachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false -::Linux Build - not used -::call eng\common\cibuild.sh -configuration Release -preparemachine /p:Root_Certificate_Installed=true /p:Client_Certificate_Installed=true /p:SSL_Available=true /p:Test=false + + diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd index 9890b7b6ff0..471072b29cf 100644 --- a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFService.cmd @@ -4,20 +4,22 @@ echo ********************************** echo Starting WCF Service on Docker echo ********************************** +:: Use this script to start docker container for WCF Services - IIS Hosted and Self Hosted + +:: Variables set _exitCode=0 -::todo use vars set "ServiceImageTag=wcf:service" set "ServiceContainerName=WCFServiceContainer" set "ServiceHostName=wcfservicehost" -:: Make sure docker is running +:: Check if docker is running docker ps>nul 2>&1 if ERRORLEVEL 1 ( echo. & echo ERROR: Please make sure docker is running. goto :Failure ) -::make sure we are using Windows Containers +:: Check if docker is using Windows Containers CALL "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine :: Check if WCF service is already running @@ -27,7 +29,7 @@ if %%F == 'running' ( goto :Done )) -:: change directory to wcf folder +:: Change directory to wcf folder cd ../../../.. echo. & echo Building Docker image for WCF service @@ -42,7 +44,7 @@ echo. & echo Building image success.. :: Starting docker container from the image. echo. & echo Starting WCF Service Container -:: run docker container and mount current directory for wcf source as container volume - C:\wcf +:: Run docker container and mount current directory for wcf source as container volume - C:\wcf docker run --name %ServiceContainerName% --rm -it -d -h %ServiceHostName% -v "%cd%":"C:\wcf" %ServiceImageTag% if ERRORLEVEL 1 ( echo. & echo ERROR: Starting WCF service container failed. @@ -50,7 +52,8 @@ if ERRORLEVEL 1 ( ) echo. & echo Started WCF Service Container. -:: print service container IP address +:: Print service container IP address and host name +echo. & echo WCF Service Container IP address and Host name: docker inspect --format="{{.NetworkSettings.Networks.nat.IPAddress}}" %ServiceContainerName% echo %ServiceHostName% diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd index 8c143b26078..19200d21a99 100644 --- a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Linux.cmd @@ -4,12 +4,15 @@ echo ********************************** echo Starting WCF Client on Docker echo ********************************** +:: Use this script to start docker Linux container for WCF Client + +:: Variables set _exitCode=0 set "TestContainerName=WCFTestContainerLinux" set "ServiceContainerName=WCFServiceContainer" set "ServiceHostName=wcfservicehost" -:: Make sure docker is running +:: Check if docker is running docker ps>nul 2>&1 if ERRORLEVEL 1 ( echo. & echo ERROR: Please make sure docker is running. @@ -18,7 +21,7 @@ if ERRORLEVEL 1 ( echo. & echo Checking WCF service container status and IP address. -::Switch to Windows Containers to check WCF Service status +:: Switch to Windows Containers to check WCF Service status START /B /WAIT "" "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine :: Check if WCF service is already running @@ -35,10 +38,10 @@ SET ServiceUri=%ServiceHostName%/WcfService38 ) echo %ServiceUri% -::Switch to Linux Containers to run Linux tests +:: Switch to Linux Containers to run Linux tests START /B /WAIT "" "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchLinuxEngine -:: change directory to wcf src +:: Change directory to wcf src cd ../../../.. echo. & echo Building Docker image for WCF client @@ -56,13 +59,13 @@ echo. & echo Starting WCF client :: run docker container and mount current directory for wcf source as container volume '/wcf' :: mount volume '.dotnet-linux' CLI cache directory inside the container as '.dotnet' :: mount volume 'artifacts-linux' inside the container as 'artifacts' +:: mount volumes 'artifacts/bin' and 'artifacts/obj' inside the container, since it contains the test assemblies docker run --name %TestContainerName% --rm -it --memory=4g -v "%cd%":"/wcf" -v "%cd%/.dotnet-linux":"/wcf/.dotnet" -v "%cd%/artifacts-linux":"/wcf/artifacts" -v "%cd%/artifacts/bin":"/wcf/artifacts/bin" -v "%cd%/artifacts/obj":"/wcf/artifacts/obj" -e ServiceUri=%ServiceUri% wcf:client if ERRORLEVEL 1 ( echo. & echo ERROR: Starting WCF client container failed. goto :Failure ) - exit /b :Failure diff --git a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd index 3dbe6921ee4..470301145c6 100644 --- a/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/DockerStartWCFTest-Windows.cmd @@ -4,12 +4,15 @@ echo ********************************** echo Starting WCF Client on Docker echo ********************************** +:: Use this script to start docker Windows container for WCF Client + +:: Variables set _exitCode=0 set "TestContainerName=WCFTestContainerWin" set "ServiceContainerName=WCFServiceContainer" set "ServiceHostName=wcfservicehost" -:: Make sure docker is running +:: Check if docker is running docker ps>nul 2>&1 if ERRORLEVEL 1 ( echo. & echo ERROR: Please make sure docker is running. @@ -18,7 +21,7 @@ if ERRORLEVEL 1 ( echo. & echo Checking WCF service container status and IP address. -::Switch to Windows Containers to check WCF Service status +:: Switch to Windows Containers to check WCF Service status START /B /WAIT "" "C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine :: Check if WCF service is already running @@ -35,7 +38,7 @@ SET ServiceUri=%ServiceHostName%/WcfService38 ) echo %ServiceUri% -:: change directory to wcf src +:: Change directory to wcf src cd ../../../.. echo. & echo Building Docker image for WCF client @@ -58,7 +61,6 @@ if ERRORLEVEL 1 ( goto :Failure ) - exit /b :Failure diff --git a/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh b/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh index 1cdf6807a4b..b4ecaade001 100755 --- a/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh +++ b/src/System.Private.ServiceModel/tools/scripts/InstallRootCertificate.sh @@ -20,13 +20,13 @@ acquire_certificate() echo "Obtaining certificate from '$ServiceUri'" - # Need to make a call as the original user as we need to write to the cert store for the current - # user, not as root + # Need to make a call as the original user as we need to write to the cert store for the current user, not as root + # if $EUID = 0, user is 'root' if [ "$EUID" -ne 0 ]; then echo "Making a call to '${__service_host}/TestHost.svc/RootCert' as user '$SUDO_USER'" sudo -E -u $SUDO_USER $__curl_exe -o $__cafile "http://${__service_host}/TestHost.svc/RootCert?asPem=true" else - # Docker containers has no Sudo installed, by default it is running root user + # Docker containers has no Sudo installed, by default it is running root user echo "Making a call to '${ServiceUri}/TestHost.svc/RootCert' as root user" $__curl_exe -o $__cafile "http://${ServiceUri}/TestHost.svc/RootCert?asPem=true" fi diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh index 5361ffa4510..baaaef128cf 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh @@ -1,10 +1,11 @@ +# Setup environment variables export Windows_Authentication_Available=true export SPN_Available=true export Server_Domain_Joined=true export Ambient_Credentials_Available=true export Domain_Available=true export Explicit_Credentials_Available=true -#set username and password +# Set username and password #export ExplicitUserName= #export ExplicitPassword= export SSL_Available=true diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd index a2e106f0560..08534527e62 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Windows.cmd @@ -1,10 +1,11 @@ +:: Setup environment variables setx Windows_Authentication_Available true setx Digest_Authentication_Available true setx Ambient_Credentials_Available true setx SPN_Available true setx NTLM_Available true setx Server_Domain_Joined true -::set username and password +:: Set username and password ::setx ExplicitUserName ::setx ExplicitPassword setx Domain_Available true From 62bf3d130d3936811fb203c4a684a52550e0882d Mon Sep 17 00:00:00 2001 From: Abdelwahab Afifi Date: Wed, 26 Oct 2022 20:35:53 +0200 Subject: [PATCH 7/7] Update NegotiateTestDomain value --- .../tools/scripts/SetClientEnv-Linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh index baaaef128cf..279cfaa92e0 100644 --- a/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh +++ b/src/System.Private.ServiceModel/tools/scripts/SetClientEnv-Linux.sh @@ -12,4 +12,4 @@ export SSL_Available=true export Root_Certificate_Installed=true export Client_Certificate_Installed=true export Peer_Certificate_Installed=true -export NegotiateTestDomain=REDMOND.CORP.MICROSOFT.COM +#export NegotiateTestDomain=