diff --git a/docker/tests/Templates/centos7/Dockerfile b/docker/tests/Templates/centos7/Dockerfile new file mode 100644 index 00000000000..89816a47828 --- /dev/null +++ b/docker/tests/Templates/centos7/Dockerfile @@ -0,0 +1,22 @@ +FROM centos:7 + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN yum install -y \ + curl \ + glibc-locale-source \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG + +RUN curl -L -o powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm $PACKAGELOCATIONSTUB/powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm +RUN yum install -y powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/debian.8/Dockerfile b/docker/tests/Templates/debian.8/Dockerfile new file mode 100644 index 00000000000..f6224837884 --- /dev/null +++ b/docker/tests/Templates/debian.8/Dockerfile @@ -0,0 +1,27 @@ +FROM debian:jessie + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + curl \ + apt-transport-https \ + locales \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +RUN curl -L -o powershell_$PSVERSIONSTUB-1.debian.8_amd64.deb $PACKAGELOCATIONSTUB/powershell_$PSVERSIONSTUB-1.debian.8_amd64.deb +RUN dpkg -i powershell_$PSVERSIONSTUB-1.debian.8_amd64.deb || : +RUN apt-get install -y -f +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/debian.9/Dockerfile b/docker/tests/Templates/debian.9/Dockerfile new file mode 100644 index 00000000000..80e21cd407b --- /dev/null +++ b/docker/tests/Templates/debian.9/Dockerfile @@ -0,0 +1,27 @@ +FROM debian:stretch + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + curl \ + apt-transport-https \ + locales \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +RUN curl -L -o powershell_$PSVERSIONSTUB-1.debian.9_amd64.deb $PACKAGELOCATIONSTUB/powershell_$PSVERSIONSTUB-1.debian.9_amd64.deb +RUN dpkg -i powershell_$PSVERSIONSTUB-1.debian.9_amd64.deb || : +RUN apt-get install -y -f +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/fedora25/Dockerfile b/docker/tests/Templates/fedora25/Dockerfile new file mode 100644 index 00000000000..828c3660078 --- /dev/null +++ b/docker/tests/Templates/fedora25/Dockerfile @@ -0,0 +1,22 @@ +FROM fedora:25 + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN dnf install -y \ + curl \ + glibc-locale-source \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG + +RUN curl -L -o powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm $PACKAGELOCATIONSTUB/powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm +RUN dnf install -y powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/fedora26/Dockerfile b/docker/tests/Templates/fedora26/Dockerfile new file mode 100644 index 00000000000..b4207d7c22a --- /dev/null +++ b/docker/tests/Templates/fedora26/Dockerfile @@ -0,0 +1,23 @@ +FROM fedora:26 + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN dnf install -y \ + curl \ + glibc-locale-source \ + compat-openssl10 \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG + +RUN curl -L -o powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm $PACKAGELOCATIONSTUB/powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm +RUN dnf install -y powershell-$PSVERSIONSTUBRPM-1.rhel.7.x86_64.rpm +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/kalilinux/Dockerfile b/docker/tests/Templates/kalilinux/Dockerfile new file mode 100644 index 00000000000..6d02c38a465 --- /dev/null +++ b/docker/tests/Templates/kalilinux/Dockerfile @@ -0,0 +1,29 @@ +FROM kalilinux/kali-linux-docker:latest + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + curl \ + apt-transport-https \ + locales \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +RUN curl -L -o libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb +RUN curl -L -o powershell_$PSVERSIONSTUB-1.ubuntu.16.04_amd64.deb $PACKAGELOCATIONSTUB/powershell_$PSVERSIONSTUB-1.ubuntu.16.04_amd64.deb +RUN dpkg -i libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb || : +RUN dpkg -i powershell_$PSVERSIONSTUB-1.ubuntu.16.04_amd64.deb || : +RUN apt-get install -y -f +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/opensuse42.2/Dockerfile b/docker/tests/Templates/opensuse42.2/Dockerfile new file mode 100644 index 00000000000..5ac50b1a01d --- /dev/null +++ b/docker/tests/Templates/opensuse42.2/Dockerfile @@ -0,0 +1,38 @@ +FROM opensuse:42.2 + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +ARG POWERSHELL_LINKFILE=/usr/bin/pwsh + +# Install dependencies +RUN zypper --non-interactive update --skip-interactive \ + && zypper --non-interactive install \ + glibc-locale \ + glibc-i18ndata \ + tar \ + curl \ + libunwind \ + libicu \ + openssl \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG + +RUN curl -L -o powershell-$PSVERSIONSTUB-linux-x64.tar.gz $PACKAGELOCATIONSTUB/powershell-$PSVERSIONSTUB-linux-x64.tar.gz + +# Create the target folder where powershell will be placed +RUN mkdir -p /opt/microsoft/powershell/$PSVERSIONSTUB +# Expand powershell to the target folder +RUN tar zxf powershell-$PSVERSIONSTUB-linux-x64.tar.gz -C /opt/microsoft/powershell/$PSVERSIONSTUB + +# Create the symbolic link that points to powershell +RUN ln -s /opt/microsoft/powershell/$PSVERSIONSTUB/pwsh $POWERSHELL_LINKFILE + +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/ubuntu14.04/Dockerfile b/docker/tests/Templates/ubuntu14.04/Dockerfile new file mode 100644 index 00000000000..1533bc2395d --- /dev/null +++ b/docker/tests/Templates/ubuntu14.04/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:trusty + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + curl \ + apt-transport-https \ + locales \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +RUN curl -L -o powershell_$PSVERSIONSTUB-1.ubuntu.14.04_amd64.deb $PACKAGELOCATIONSTUB/powershell_$PSVERSIONSTUB-1.ubuntu.14.04_amd64.deb +RUN dpkg -i powershell_$PSVERSIONSTUB-1.ubuntu.14.04_amd64.deb || : +RUN apt-get install -y -f +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/ubuntu16.04/Dockerfile b/docker/tests/Templates/ubuntu16.04/Dockerfile new file mode 100644 index 00000000000..db84a97f535 --- /dev/null +++ b/docker/tests/Templates/ubuntu16.04/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:xenial + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + curl \ + apt-transport-https \ + locales \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +RUN curl -L -o powershell_$PSVERSIONSTUB-1.ubuntu.16.04_amd64.deb $PACKAGELOCATIONSTUB/powershell_$PSVERSIONSTUB-1.ubuntu.16.04_amd64.deb +RUN dpkg -i powershell_$PSVERSIONSTUB-1.ubuntu.16.04_amd64.deb || : +RUN apt-get install -y -f +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/Templates/ubuntu17.04/Dockerfile b/docker/tests/Templates/ubuntu17.04/Dockerfile new file mode 100644 index 00000000000..506cb8b5112 --- /dev/null +++ b/docker/tests/Templates/ubuntu17.04/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:zesty + +ARG PSVERSIONSTUB +ARG PSVERSIONSTUBRPM +ARG PACKAGELOCATIONSTUB +ARG TESTLISTSTUB + +# Install dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + curl \ + apt-transport-https \ + locales \ + git + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +RUN curl -L -o powershell_$PSVERSIONSTUB-1.ubuntu.17.04_amd64.deb $PACKAGELOCATIONSTUB/powershell_$PSVERSIONSTUB-1.ubuntu.17.04_amd64.deb +RUN dpkg -i powershell_$PSVERSIONSTUB-1.ubuntu.17.04_amd64.deb || : +RUN apt-get install -y -f +RUN git clone --recursive https://github.com/PowerShell/PowerShell.git +RUN pwsh -c "Import-Module /PowerShell/build.psm1;exit (Invoke-Pester $TESTLISTSTUB -PassThru).FailedCount" diff --git a/docker/tests/containerTestCommon.psm1 b/docker/tests/containerTestCommon.psm1 index 5b3971e5cb2..a89e30bd21e 100644 --- a/docker/tests/containerTestCommon.psm1 +++ b/docker/tests/containerTestCommon.psm1 @@ -190,3 +190,69 @@ function Get-ContainerPowerShellVersion } return (Get-Content -Encoding Ascii $testContext.resolvedLogPath)[0] } + +# This function is used for basic validation of PS packages during a release; +# During the process Docker files are filled out and executed with Docker build; +# During the build PS packages are downloaded onto Docker containers, installed and selected Pester tests from PowerShell Github repo are executed. +# This function must be run on a Docker host machine in 'Linux containers' mode, such as Windows 10 server with Hyper-V role installed. +function Test-PSPackage +{ + param( + [string] + [Parameter(Mandatory=$true)] + $PSPackageLocation, # e.g. Azure storage + [string] + $PSVersion = "6.0.0-beta.9", + [string] + $TestList = "/PowerShell/test/powershell/Modules/PackageManagement/PackageManagement.Tests.ps1,/PowerShell/test/powershell/engine/Module" + ) + + $PSPackageLocation = $PSPackageLocation.TrimEnd('/','\') + Write-Verbose "Ensure that PowerShell packages of version $PSVersion exist at $PSPackageLocation" -Verbose + + $tempFolder = $env:Temp + if (-not $tempFolder) {$tempFolder = "~"} + $RootFolder = Join-Path $tempFolder 'PSPackageDockerValidation' + $SourceFolder = Join-Path $PSScriptRoot 'Templates' + + if (Test-Path $RootFolder) + { + Remove-Item $RootFolder -Recurse -Force + } + + Copy-Item -Recurse $SourceFolder $RootFolder + + $versionRpmStubName = 'PSVERSIONSTUBRPM' + $versionRpmStubValue = $PSVersion -replace '-','_' + $versionStubName = 'PSVERSIONSTUB' + $versionStubValue = $PSVersion + $testlistStubName = 'TESTLISTSTUB' + $testlistStubValue = $TestList + $packageLocationStubName = 'PACKAGELOCATIONSTUB' + $packageLocationStubValue = $PSPackageLocation + + + $results = @{} + $returnValue = $true + + # run builds sequentially, but don't block for errors so that configs after failed one can run + foreach($dir in Get-ChildItem -Path $RootFolder) + { + $buildArgs = @() + $buildArgs += "--build-arg","$versionRpmStubName=$versionRpmStubValue" + $buildArgs += "--build-arg","$versionStubName=$versionStubValue" + $buildArgs += "--build-arg","$testlistStubName=$testlistStubValue" + $buildArgs += "--build-arg","$packageLocationStubName=$packageLocationStubValue" + $buildArgs += $dir.FullName + + $dockerResult = Invoke-Docker -Command 'build' -Params $buildArgs -FailureAction warning + $results.Add($dir.Name, $dockerResult) + if (-not $dockerResult) {$returnValue = $false} + } + + # in the end print results for all configurations + Write-Verbose "Package validation results:" -Verbose + $results + + return $returnValue +}