From b86b1f870a3f06a8be26c9dc59953ed827516fe4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Sep 2016 11:44:34 -0700 Subject: [PATCH 01/23] Fix memory leak in GetFullyQualifiedName() --- src/libpsl-native/src/getfullyqualifiedname.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libpsl-native/src/getfullyqualifiedname.cpp b/src/libpsl-native/src/getfullyqualifiedname.cpp index c33e11e8e..ef3605b4d 100644 --- a/src/libpsl-native/src/getfullyqualifiedname.cpp +++ b/src/libpsl-native/src/getfullyqualifiedname.cpp @@ -43,17 +43,18 @@ char *GetFullyQualifiedName() * POSIX compliant, and some are being deprecated. getaddrinfo seems * to be the best choice. */ + char *fullName = NULL; if (getaddrinfo(computerName, "http", &hints, &info) != 0) { - errno = ERROR_BAD_NET_NAME; - return NULL; + goto exit; } - // info is actually a link-list. We'll just return the first full name - - char *fullName = strndup(info->ai_canonname, strlen(info->ai_canonname)); + // return the first canonical name in the list + fullName = strndup(info->ai_canonname, strlen(info->ai_canonname)); + // only free info if getaddrinfo was successful freeaddrinfo(info); +exit: free(computerName); return fullName; } From e7537b7ef4d61ee18979a14386ff13fbe8ea0c0c Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Sep 2016 11:44:51 -0700 Subject: [PATCH 02/23] Improve GetFullyQualfiedName() test --- .../src/getfullyqualifiedname.cpp | 8 ------- .../test/test-getfullyqualifiedname.cpp | 23 ++++++++++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/libpsl-native/src/getfullyqualifiedname.cpp b/src/libpsl-native/src/getfullyqualifiedname.cpp index ef3605b4d..e88ab988e 100644 --- a/src/libpsl-native/src/getfullyqualifiedname.cpp +++ b/src/libpsl-native/src/getfullyqualifiedname.cpp @@ -11,15 +11,7 @@ //! @brief GetFullyQualifiedName retrieves the fully qualified dns name of the host //! -//! @exception errno Passes these errors via errno to GetLastError: -//! - ERROR_INVALID_FUNCTION: getlogin_r() returned an unrecognized error code (from GetComputerName) -//! - ERROR_INVALID_ADDRESS: buffer is an invalid address (from GetComputerName) -//! - ERROR_GEN_FAILURE: buffer not large enough (from GetComputerName) -//! - ERROR_BAD_NET_NAME: Cannot determine network short name -//! //! @retval username as UTF-8 string, or null if unsuccessful -//! - char *GetFullyQualifiedName() { errno = 0; diff --git a/src/libpsl-native/test/test-getfullyqualifiedname.cpp b/src/libpsl-native/test/test-getfullyqualifiedname.cpp index 7e11d740f..443ad2330 100644 --- a/src/libpsl-native/test/test-getfullyqualifiedname.cpp +++ b/src/libpsl-native/test/test-getfullyqualifiedname.cpp @@ -12,19 +12,30 @@ TEST(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName) { - std::string actual(GetFullyQualifiedName()); - std::string hostname(GetComputerName()); + char *hostname = GetComputerName(); + ASSERT_STRNE(NULL, hostname); + + // this might be fail + errno = 0; + char *actual = GetFullyQualifiedName(); + int fqdnErrno = errno; struct addrinfo hints, *info; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; - EXPECT_FALSE(getaddrinfo(hostname.c_str(), "http", &hints, &info)); + errno = 0; + if (getaddrinfo(hostname, "http", &hints, &info) != 0) + { + // test that getaddrinfo failed the same way + EXPECT_EQ(fqdnErrno, errno); + goto exit; + } // Compare canonical name to FQDN - EXPECT_STREQ(info->ai_canonname, actual.c_str()); - + EXPECT_STREQ(info->ai_canonname, actual); freeaddrinfo(info); - +exit: + free(hostname); } From bb476d4aef477963cd991154cf96d5becc750d53 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 12:53:40 -0700 Subject: [PATCH 03/23] Install groff when bootstrapping for packaging --- build.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index bb3443d3b..a8a969886 100644 --- a/build.psm1 +++ b/build.psm1 @@ -720,7 +720,7 @@ function Start-PSBootstrap { elseif ($IsUbuntu16) { $Deps += "libicu55" } # Packaging tools - if ($Package) { $Deps += "ruby-dev" } + if ($Package) { $Deps += "ruby-dev", "groff" } # Install dependencies sudo apt-get install -y -qq $Deps @@ -732,7 +732,7 @@ function Start-PSBootstrap { $Deps += "libicu", "libunwind" # Packaging tools - if ($Package) { $Deps += "ruby-devel", "rpm-build" } + if ($Package) { $Deps += "ruby-devel", "rpm-build", "groff" } # Install dependencies sudo yum install -y -q $Deps From 3687692802d90cfd37840c48b620778957a4d7fb Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:21:43 -0700 Subject: [PATCH 04/23] Guard fatal bootstrap steps with Start-NativeExecution --- build.psm1 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/build.psm1 b/build.psm1 index a8a969886..1d2cfc361 100644 --- a/build.psm1 +++ b/build.psm1 @@ -746,12 +746,17 @@ function Start-PSBootstrap { $Deps += "openssl" # Install dependencies - brew install $Deps + Start-NativeExecution { brew install $Deps } } # Install [fpm](https://github.com/jordansissel/fpm) and [ronn](https://github.com/rtomayko/ronn) if ($Package) { - gem install fpm ronn + try { + # We cannot guess if the user wants to run gem install as root + Start-NativeExecution { gem install fpm ronn } + } catch { + Write-Warning "Installation of fpm and ronn gems failed! Must resolve manually." + } } $obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain" @@ -766,18 +771,20 @@ function Start-PSBootstrap { } if ($uninstallScript) { - curl -s $obtainUrl/uninstall/$uninstallScript -o $uninstallScript - chmod +x $uninstallScript - sudo ./$uninstallScript + Start-NativeExecution { + curl -sO $obtainUrl/uninstall/$uninstallScript + Invoke-Expression "$sudo bash ./$uninstallScript" + } } else { Write-Warning "This script only removes prior versions of dotnet for Ubuntu 14.04 and OS X" } # Install new dotnet 1.0.0 preview packages $installScript = "dotnet-install.sh" - curl -s $obtainUrl/$installScript -o $installScript - chmod +x $installScript - bash ./$installScript -c $Channel -v $Version + Start-NativeExecution { + curl -sO $obtainUrl/$installScript + bash ./$installScript -c $Channel -v $Version + } # .NET Core's crypto library needs brew's OpenSSL libraries added to its rpath if ($IsOSX) { From 3a66c04f23cde0b4a542cabb5d32a4e828a50a21 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:21:20 -0700 Subject: [PATCH 05/23] Add -NoSudo option to Start-PSBootstrap --- build.psm1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index 1d2cfc361..977fc6284 100644 --- a/build.psm1 +++ b/build.psm1 @@ -688,6 +688,7 @@ function Start-PSBootstrap { [string]$Channel = "rel-1.0.0", [string]$Version = "latest", [switch]$Package, + [switch]$NoSudo, [switch]$Force ) @@ -695,6 +696,10 @@ function Start-PSBootstrap { Push-Location $PSScriptRoot/tools + # This allows sudo install to be optional; needed when running in containers / as root + # Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly + $sudo = if (!$NoSudo) { "sudo" } + try { # Update googletest submodule for linux native cmake if ($IsLinux -or $IsOSX) { @@ -723,7 +728,7 @@ function Start-PSBootstrap { if ($Package) { $Deps += "ruby-dev", "groff" } # Install dependencies - sudo apt-get install -y -qq $Deps + Start-NativeExecution { Invoke-Expression "$sudo apt-get install -y -qq $Deps" } } elseif ($IsCentOS) { # Build tools $Deps += "which", "curl", "gcc-c++", "cmake", "make" @@ -735,7 +740,9 @@ function Start-PSBootstrap { if ($Package) { $Deps += "ruby-devel", "rpm-build", "groff" } # Install dependencies - sudo yum install -y -q $Deps + Start-NativeExecution { + Invoke-Expression "$sudo yum install -y -q $Deps" + } } elseif ($IsOSX) { precheck 'brew' "Bootstrap dependency 'brew' not found, must install Homebrew! See http://brew.sh/" From fc2c1b9f7dfb59154fa7efe0bfa5934f1471e9bf Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:31:36 -0700 Subject: [PATCH 06/23] Update apt-get repo in Start-PSBootstrap yum does not need this as yum install does it automatically. This is needed when running, for example, in a container. --- build.psm1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 977fc6284..5f4d54630 100644 --- a/build.psm1 +++ b/build.psm1 @@ -728,7 +728,10 @@ function Start-PSBootstrap { if ($Package) { $Deps += "ruby-dev", "groff" } # Install dependencies - Start-NativeExecution { Invoke-Expression "$sudo apt-get install -y -qq $Deps" } + Start-NativeExecution { + Invoke-Expression "$sudo apt-get update" + Invoke-Expression "$sudo apt-get install -y -qq $Deps" + } } elseif ($IsCentOS) { # Build tools $Deps += "which", "curl", "gcc-c++", "cmake", "make" From 427435c8fd28adec2e008a636cca64ffb03023c8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Sep 2016 14:35:54 -0700 Subject: [PATCH 07/23] Refactor .NET CLI installation into Install-Dotnet So that it can be reinstalled separately if desired. Also removed the set validation as it was now wrong, and removed the warning about no Invoke-WebRequest on Core PowerShell (it is ported now). I don't like the duplicate parameter logic, especially around -NoSudo. --- build.psm1 | 102 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/build.psm1 b/build.psm1 index 5f4d54630..62397f6f4 100644 --- a/build.psm1 +++ b/build.psm1 @@ -679,12 +679,66 @@ function Start-PSxUnit { } +function Install-Dotnet { + [CmdletBinding()] + param( + [string]$Channel = "rel-1.0.0", + [string]$Version = "latest", + [switch]$NoSudo + ) + + # This allows sudo install to be optional; needed when running in containers / as root + # Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly + $sudo = if (!$NoSudo) { "sudo" } + + $obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain" + + # Install for Linux and OS X + if ($IsLinux -or $IsOSX) { + # Uninstall all previous dotnet packages + $uninstallScript = if ($IsUbuntu) { + "dotnet-uninstall-debian-packages.sh" + } elseif ($IsOSX) { + "dotnet-uninstall-pkgs.sh" + } + + if ($uninstallScript) { + Start-NativeExecution { + curl -sO $obtainUrl/uninstall/$uninstallScript + Invoke-Expression "$sudo bash ./$uninstallScript" + } + } else { + Write-Warning "This script only removes prior versions of dotnet for Ubuntu 14.04 and OS X" + } + + # Install new dotnet 1.0.0 preview packages + $installScript = "dotnet-install.sh" + Start-NativeExecution { + curl -sO $obtainUrl/$installScript + bash ./$installScript -c $Channel -v $Version + } + + # .NET Core's crypto library needs brew's OpenSSL libraries added to its rpath + if ($IsOSX) { + # This is the library shipped with .NET Core + # This is allowed to fail as the user may have installed other versions of dotnet + Write-Warning ".NET Core links the incorrect OpenSSL, correcting .NET CLI libraries..." + find $env:HOME/.dotnet -name System.Security.Cryptography.Native.dylib | xargs sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib + } + } elseif ($IsWindows) { + Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet + $installScript = "dotnet-install.ps1" + Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript + & ./$installScript -c $Channel -v $Version + } +} + + function Start-PSBootstrap { [CmdletBinding( SupportsShouldProcess=$true, ConfirmImpact="High")] param( - [ValidateSet("dev", "beta", "preview")] [string]$Channel = "rel-1.0.0", [string]$Version = "latest", [switch]$Package, @@ -769,49 +823,11 @@ function Start-PSBootstrap { } } - $obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain" - - # Install for Linux and OS X - if ($IsLinux -or $IsOSX) { - # Uninstall all previous dotnet packages - $uninstallScript = if ($IsUbuntu) { - "dotnet-uninstall-debian-packages.sh" - } elseif ($IsOSX) { - "dotnet-uninstall-pkgs.sh" - } - - if ($uninstallScript) { - Start-NativeExecution { - curl -sO $obtainUrl/uninstall/$uninstallScript - Invoke-Expression "$sudo bash ./$uninstallScript" - } - } else { - Write-Warning "This script only removes prior versions of dotnet for Ubuntu 14.04 and OS X" - } - - # Install new dotnet 1.0.0 preview packages - $installScript = "dotnet-install.sh" - Start-NativeExecution { - curl -sO $obtainUrl/$installScript - bash ./$installScript -c $Channel -v $Version - } - - # .NET Core's crypto library needs brew's OpenSSL libraries added to its rpath - if ($IsOSX) { - # This is the library shipped with .NET Core - # This is allowed to fail as the user may have installed other versions of dotnet - Write-Warning ".NET Core links the incorrect OpenSSL, correcting .NET CLI libraries..." - find $env:HOME/.dotnet -name System.Security.Cryptography.Native.dylib | xargs sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib - } - } + $DotnetArguments = @{ Channel=$Channel; Version=$Version; NoSudo=$NoSudo } + Install-Dotnet @DotnetArguments # Install for Windows - if ($IsWindows -and -not $IsCoreCLR) { - Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet - $installScript = "dotnet-install.ps1" - Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript - & ./$installScript -c $Channel -v $Version - + if ($IsWindows) { $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') $newMachineEnvironmentPath = $machinePath @@ -878,8 +894,6 @@ function Start-PSBootstrap { } } - } elseif ($IsWindows) { - Write-Warning "Start-PSBootstrap cannot be run in Core PowerShell on Windows (need Invoke-WebRequest!)" } } finally { Pop-Location From 3e269103b54725e9aa0b3c52fc05b5b600dced1a Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:27:36 -0700 Subject: [PATCH 08/23] Remove prototype Dockerfile --- Dockerfile | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 912ad0ffe..000000000 --- a/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:16.04 - -RUN apt-get update && apt-get install -y curl libunwind8 libicu55 libcurl3 -RUN curl -LO https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb -RUN dpkg -i powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb - -Entrypoint [ "powershell" ] From cbc658b52555e00dcc9c4f5483a00a56badcdbaf Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 6 Sep 2016 15:47:56 -0700 Subject: [PATCH 09/23] Add stable Dockerfile for Ubuntu 14.04 Dependencies and PowerShell are installed. --- docker/stable/ubuntu14.04/Dockerfile | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/stable/ubuntu14.04/Dockerfile diff --git a/docker/stable/ubuntu14.04/Dockerfile b/docker/stable/ubuntu14.04/Dockerfile new file mode 100644 index 000000000..000837a3f --- /dev/null +++ b/docker/stable/ubuntu14.04/Dockerfile @@ -0,0 +1,36 @@ +FROM ubuntu:trusty +MAINTAINER Andrew Schwartzmeyer + +ARG POWERSHELL_RELEASE=v6.0.0-alpha.9 +ARG POWERSHELL_PACKAGE=powershell_6.0.0-alpha.9-1ubuntu1.14.04.1_amd64.deb + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +# Install dependencies and clean up +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libc6 \ + libcurl3 \ + ca-certificates \ + libgcc1 \ + libicu52 \ + libssl1.0.0 \ + libstdc++6 \ + libtinfo5 \ + libunwind8 \ + libuuid1 \ + zlib1g \ + curl \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Install PowerShell package and clean up +RUN curl -SLO https://github.com/PowerShell/PowerShell/releases/download/$POWERSHELL_RELEASE/$POWERSHELL_PACKAGE \ + && dpkg -i $POWERSHELL_PACKAGE \ + && rm $POWERSHELL_PACKAGE + +# Use array to avoid Docker prepending /bin/sh -c +ENTRYPOINT [ "powershell" ] From 6bddaf6534c2df0483aafb4a24dfb2a7b74538fa Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 7 Sep 2016 16:27:23 -0700 Subject: [PATCH 10/23] Add unstable Dockerfile for Ubuntu 14.04 --- docker/unstable/ubuntu14.04/Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docker/unstable/ubuntu14.04/Dockerfile diff --git a/docker/unstable/ubuntu14.04/Dockerfile b/docker/unstable/ubuntu14.04/Dockerfile new file mode 100644 index 000000000..8b6b5d72c --- /dev/null +++ b/docker/unstable/ubuntu14.04/Dockerfile @@ -0,0 +1,6 @@ +FROM powershell/powershell:stable-ubuntu14.04 +MAINTAINER Andrew Schwartzmeyer + +COPY bootstrap.ps1 / +RUN powershell -f bootstrap.ps1 \ + && dpkg -i PowerShell/powershell*.deb From 7375ab58b19e658fd67d1c6af395f694def3b450 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 14:31:07 -0700 Subject: [PATCH 11/23] Add Docker scripts Common bootstrap.ps1 script to run PowerShell builds. Launch script to build and tag all containers. Test script to run tests in unstable containers. --- docker/launch.sh | 28 ++++++++++++++++++++++++++++ docker/test.sh | 19 +++++++++++++++++++ docker/unstable/.gitignore | 1 + docker/unstable/bootstrap.ps1 | 8 ++++++++ 4 files changed, 56 insertions(+) create mode 100755 docker/launch.sh create mode 100644 docker/test.sh create mode 100644 docker/unstable/.gitignore create mode 100644 docker/unstable/bootstrap.ps1 diff --git a/docker/launch.sh b/docker/launch.sh new file mode 100755 index 000000000..7cc29ae36 --- /dev/null +++ b/docker/launch.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -e + +# Build both sets by default +if [[ -z "$BUILDS" ]]; then + BUILDS="stable unstable" +fi + +# Build specified distributions +if [[ -z $DISTROS ]]; then + DISTROS="ubuntu14.04" +fi + +for build in $BUILDS; do + # cd so $distro is only the distro name + cd $build + for distro in $DISTROS; do + echo "Building $build/$distro" + # copy the common script because it lives outside the docker build context + if [[ "$build" = "unstable" ]]; then + cp bootstrap.ps1 $distro + fi + # build and tag the image so they can be derived from + docker build -t powershell/powershell:$build-$distro $distro + done + cd .. +done diff --git a/docker/test.sh b/docker/test.sh new file mode 100644 index 000000000..fb5d2163c --- /dev/null +++ b/docker/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -e + +# Build specified distributions +if [[ -z $DISTROS ]]; then + DISTROS="ubuntu14.04 ubuntu16.04 centos7" +fi + +build=unstable +command="cd PowerShell; Import-Module ./build.psm1; Start-PSPester" + +cd $build +for distro in $DISTROS; do + echo "Testing $build/$distro" + # Run Pester tests inside container + docker run -it powershell/powershell:$build-$distro powershell -c "$command" +done +cd .. diff --git a/docker/unstable/.gitignore b/docker/unstable/.gitignore new file mode 100644 index 000000000..c1ce1f3f4 --- /dev/null +++ b/docker/unstable/.gitignore @@ -0,0 +1 @@ +*/bootstrap.ps1 diff --git a/docker/unstable/bootstrap.ps1 b/docker/unstable/bootstrap.ps1 new file mode 100644 index 000000000..eda0de163 --- /dev/null +++ b/docker/unstable/bootstrap.ps1 @@ -0,0 +1,8 @@ +# This is intended to be used inside Docker containers + +git clone --recursive https://github.com/PowerShell/PowerShell.git +Set-Location PowerShell +Import-Module ./build.psm1 +Start-PSBootstrap -Package -NoSudo +Start-PSBuild -Crossgen +Start-PSPackage From da024ec2ba2598df9099a954012a2b5b654c995f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 15:06:53 -0700 Subject: [PATCH 12/23] Add stable Dockerfile for 16.04 --- docker/stable/ubuntu16.04/Dockerfile | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/stable/ubuntu16.04/Dockerfile diff --git a/docker/stable/ubuntu16.04/Dockerfile b/docker/stable/ubuntu16.04/Dockerfile new file mode 100644 index 000000000..07330603f --- /dev/null +++ b/docker/stable/ubuntu16.04/Dockerfile @@ -0,0 +1,36 @@ +FROM ubuntu:xenial +MAINTAINER Andrew Schwartzmeyer + +ARG POWERSHELL_RELEASE=v6.0.0-alpha.9 +ARG POWERSHELL_PACKAGE=powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN locale-gen $LANG && update-locale + +# Install dependencies and clean up +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libc6 \ + libcurl3 \ + ca-certificates \ + libgcc1 \ + libicu55 \ + libssl1.0.0 \ + libstdc++6 \ + libtinfo5 \ + libunwind8 \ + libuuid1 \ + zlib1g \ + curl \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Install PowerShell package and clean up +RUN curl -SLO https://github.com/PowerShell/PowerShell/releases/download/$POWERSHELL_RELEASE/$POWERSHELL_PACKAGE \ + && dpkg -i $POWERSHELL_PACKAGE \ + && rm $POWERSHELL_PACKAGE + +# Use array to avoid Docker prepending /bin/sh -c +ENTRYPOINT [ "powershell" ] From 7ac85f6ce028986632a344209d74b16cfb8236d9 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 15:09:25 -0700 Subject: [PATCH 13/23] Add unstable Dockerfile for Ubuntu 16.04 --- docker/launch.sh | 2 +- docker/unstable/ubuntu16.04/Dockerfile | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 docker/unstable/ubuntu16.04/Dockerfile diff --git a/docker/launch.sh b/docker/launch.sh index 7cc29ae36..9d275315a 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -9,7 +9,7 @@ fi # Build specified distributions if [[ -z $DISTROS ]]; then - DISTROS="ubuntu14.04" + DISTROS="ubuntu14.04 ubuntu16.04" fi for build in $BUILDS; do diff --git a/docker/unstable/ubuntu16.04/Dockerfile b/docker/unstable/ubuntu16.04/Dockerfile new file mode 100644 index 000000000..dafb8933f --- /dev/null +++ b/docker/unstable/ubuntu16.04/Dockerfile @@ -0,0 +1,6 @@ +FROM powershell/powershell:stable-ubuntu16.04 +MAINTAINER Andrew Schwartzmeyer + +COPY bootstrap.ps1 / +RUN powershell -f bootstrap.ps1 \ + && dpkg -i PowerShell/powershell*.deb From 2c7e68734019f2dc9007d9cddcf521f6a93b59e8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:26:03 -0700 Subject: [PATCH 14/23] Add stable Dockerfile for CentOS 7 --- docker/stable/centos7/Dockerfile | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/stable/centos7/Dockerfile diff --git a/docker/stable/centos7/Dockerfile b/docker/stable/centos7/Dockerfile new file mode 100644 index 000000000..1e96b20dd --- /dev/null +++ b/docker/stable/centos7/Dockerfile @@ -0,0 +1,36 @@ +FROM centos:7 +MAINTAINER Andrew Schwartzmeyer + +ARG POWERSHELL_RELEASE=v6.0.0-alpha.9 +ARG POWERSHELL_PACKAGE=powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm + +# Setup the locale +ENV LANG en_US.UTF-8 +ENV LC_ALL $LANG +RUN localedef --charmap=UTF-8 --inputfile=en_US $LANG + +# Install dependencies and clean up +RUN yum install -y \ + glibc \ + libcurl \ + ca-certificates \ + libgcc \ + libicu \ + openssl \ + libstdc++ \ + ncurses-base \ + libunwind \ + uuid \ + zlib \ + which \ + curl \ + git \ + && yum clean all + +# Install PowerShell package and clean up +RUN curl -SLO https://github.com/PowerShell/PowerShell/releases/download/$POWERSHELL_RELEASE/$POWERSHELL_PACKAGE \ + && yum install -y $POWERSHELL_PACKAGE \ + && rm $POWERSHELL_PACKAGE + +# Use array to avoid Docker prepending /bin/sh -c +ENTRYPOINT [ "powershell" ] From d76cc0f60053e44c494639787cc8b2cf8ec4c7ee Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:26:20 -0700 Subject: [PATCH 15/23] Add unstable Dockerfile for CentOS 7 --- docker/launch.sh | 2 +- docker/unstable/centos7/Dockerfile | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 docker/unstable/centos7/Dockerfile diff --git a/docker/launch.sh b/docker/launch.sh index 9d275315a..c3408b97a 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -9,7 +9,7 @@ fi # Build specified distributions if [[ -z $DISTROS ]]; then - DISTROS="ubuntu14.04 ubuntu16.04" + DISTROS="ubuntu14.04 ubuntu16.04 centos7" fi for build in $BUILDS; do diff --git a/docker/unstable/centos7/Dockerfile b/docker/unstable/centos7/Dockerfile new file mode 100644 index 000000000..7d4a73ac0 --- /dev/null +++ b/docker/unstable/centos7/Dockerfile @@ -0,0 +1,6 @@ +FROM powershell/powershell:stable-centos7 +MAINTAINER Andrew Schwartzmeyer + +COPY bootstrap.ps1 / +RUN powershell -f bootstrap.ps1 \ + && yum install -y PowerShell/powershell*.rpm From ceed98e33d4a4bdd8b0ab97efc2fbf3eb5ecf6f2 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 8 Sep 2016 16:57:32 -0700 Subject: [PATCH 16/23] Enable building arbitrary forks and branches --- docker/launch.sh | 11 ++++++++++- docker/unstable/bootstrap.ps1 | 2 +- docker/unstable/centos7/Dockerfile | 3 +++ docker/unstable/ubuntu14.04/Dockerfile | 3 +++ docker/unstable/ubuntu16.04/Dockerfile | 3 +++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docker/launch.sh b/docker/launch.sh index c3408b97a..49ada0977 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -2,6 +2,14 @@ set -e +if [[ -z "$FORK" ]]; then + FORK=PowerShell +fi + +if [[ -z "$BRANCH" ]]; then + BRANCH=master +fi + # Build both sets by default if [[ -z "$BUILDS" ]]; then BUILDS="stable unstable" @@ -20,9 +28,10 @@ for build in $BUILDS; do # copy the common script because it lives outside the docker build context if [[ "$build" = "unstable" ]]; then cp bootstrap.ps1 $distro + buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" fi # build and tag the image so they can be derived from - docker build -t powershell/powershell:$build-$distro $distro + docker build $buildargs -t powershell/powershell:$build-$distro $distro done cd .. done diff --git a/docker/unstable/bootstrap.ps1 b/docker/unstable/bootstrap.ps1 index eda0de163..d48c9468d 100644 --- a/docker/unstable/bootstrap.ps1 +++ b/docker/unstable/bootstrap.ps1 @@ -1,6 +1,6 @@ # This is intended to be used inside Docker containers -git clone --recursive https://github.com/PowerShell/PowerShell.git +git clone --recursive https://github.com/$env:fork/PowerShell.git -b $env:branch Set-Location PowerShell Import-Module ./build.psm1 Start-PSBootstrap -Package -NoSudo diff --git a/docker/unstable/centos7/Dockerfile b/docker/unstable/centos7/Dockerfile index 7d4a73ac0..0e23c9028 100644 --- a/docker/unstable/centos7/Dockerfile +++ b/docker/unstable/centos7/Dockerfile @@ -1,6 +1,9 @@ FROM powershell/powershell:stable-centos7 MAINTAINER Andrew Schwartzmeyer +ARG fork=PowerShell +ARG branch=master + COPY bootstrap.ps1 / RUN powershell -f bootstrap.ps1 \ && yum install -y PowerShell/powershell*.rpm diff --git a/docker/unstable/ubuntu14.04/Dockerfile b/docker/unstable/ubuntu14.04/Dockerfile index 8b6b5d72c..8754ba970 100644 --- a/docker/unstable/ubuntu14.04/Dockerfile +++ b/docker/unstable/ubuntu14.04/Dockerfile @@ -1,6 +1,9 @@ FROM powershell/powershell:stable-ubuntu14.04 MAINTAINER Andrew Schwartzmeyer +ARG fork=PowerShell +ARG branch=master + COPY bootstrap.ps1 / RUN powershell -f bootstrap.ps1 \ && dpkg -i PowerShell/powershell*.deb diff --git a/docker/unstable/ubuntu16.04/Dockerfile b/docker/unstable/ubuntu16.04/Dockerfile index dafb8933f..f72cc0edf 100644 --- a/docker/unstable/ubuntu16.04/Dockerfile +++ b/docker/unstable/ubuntu16.04/Dockerfile @@ -1,6 +1,9 @@ FROM powershell/powershell:stable-ubuntu16.04 MAINTAINER Andrew Schwartzmeyer +ARG fork=PowerShell +ARG branch=master + COPY bootstrap.ps1 / RUN powershell -f bootstrap.ps1 \ && dpkg -i PowerShell/powershell*.deb From 03237e91b60e1a4c55aec2c3f2ab313eda5f13b4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Sep 2016 14:24:24 -0700 Subject: [PATCH 17/23] Consolidate test script with launch script --- docker/launch.sh | 26 +++++++++++++++++++------- docker/test.sh | 19 ------------------- 2 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 docker/test.sh diff --git a/docker/launch.sh b/docker/launch.sh index 49ada0977..00558cc64 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -24,14 +24,26 @@ for build in $BUILDS; do # cd so $distro is only the distro name cd $build for distro in $DISTROS; do - echo "Building $build/$distro" - # copy the common script because it lives outside the docker build context - if [[ "$build" = "unstable" ]]; then - cp bootstrap.ps1 $distro - buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" + image="$build/$distro" + if [[ "$TEST" -eq 1 ]]; then + echo "Testing $image" + command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester" + # clone repo for stable images because it's not already done + if [[ "$build" = stable ]]; then + command="git clone --recursive https://github.com/$FORK/PowerShell -b $BRANCH; $command" + fi + # run Pester tests inside container + docker run --rm -it powershell/powershell:$build-$distro powershell -c "$command" + else + echo "Building $image" + # copy the common script because it lives outside the docker build context + if [[ "$build" = unstable ]]; then + cp bootstrap.ps1 $distro + buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" + fi + # build and tag the image so they can be derived from + docker build $buildargs -t powershell/powershell:$build-$distro $distro fi - # build and tag the image so they can be derived from - docker build $buildargs -t powershell/powershell:$build-$distro $distro done cd .. done diff --git a/docker/test.sh b/docker/test.sh deleted file mode 100644 index fb5d2163c..000000000 --- a/docker/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Build specified distributions -if [[ -z $DISTROS ]]; then - DISTROS="ubuntu14.04 ubuntu16.04 centos7" -fi - -build=unstable -command="cd PowerShell; Import-Module ./build.psm1; Start-PSPester" - -cd $build -for distro in $DISTROS; do - echo "Testing $build/$distro" - # Run Pester tests inside container - docker run -it powershell/powershell:$build-$distro powershell -c "$command" -done -cd .. From e1e014295b24899932a45a375d631ad6d6e18037 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Sep 2016 14:39:41 -0700 Subject: [PATCH 18/23] Add -powershell and -Pester options to Start-PSPester When testing containers, we want to use the in-box PowerShell. --- build.psm1 | 8 ++++---- docker/launch.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.psm1 b/build.psm1 index 62397f6f4..ad3891a66 100644 --- a/build.psm1 +++ b/build.psm1 @@ -557,13 +557,14 @@ function Start-PSPester { [string]$Path = "$PSScriptRoot/test/powershell", [switch]$ThrowOnFailure, [switch]$FullCLR, - [string]$binDir = (Split-Path (New-PSOptions -FullCLR:$FullCLR).Output) + [string]$binDir = (Split-Path (New-PSOptions -FullCLR:$FullCLR).Output), + [string]$powershell = (Join-Path $binDir 'powershell'), + [string]$Pester = ([IO.Path]::Combine($binDir, "Modules", "Pester")) ) Write-Verbose "Running pester tests at '$path' with tag '$($Tag -join ''', ''')' and ExcludeTag '$($ExcludeTag -join ''', ''')'" -Verbose # All concatenated commands/arguments are suffixed with the delimiter (space) $Command = "" - $powershell = Join-Path $binDir 'powershell' # Windows needs the execution policy adjusted if ($IsWindows) { @@ -571,10 +572,9 @@ function Start-PSPester { } $startParams = @{binDir=$binDir} - $PesterModule = [IO.Path]::Combine($binDir, "Modules", "Pester") if(!$FullCLR) { - $Command += "Import-Module '$PesterModule'; " + $Command += "Import-Module '$Pester'; " } $Command += "Invoke-Pester " diff --git a/docker/launch.sh b/docker/launch.sh index 00558cc64..022c60f25 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -27,13 +27,13 @@ for build in $BUILDS; do image="$build/$distro" if [[ "$TEST" -eq 1 ]]; then echo "Testing $image" - command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester" + command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester -powershell powershell -Pester ./src/Modules/Shared/Pester" # clone repo for stable images because it's not already done if [[ "$build" = stable ]]; then command="git clone --recursive https://github.com/$FORK/PowerShell -b $BRANCH; $command" fi # run Pester tests inside container - docker run --rm -it powershell/powershell:$build-$distro powershell -c "$command" + docker run --rm -it powershell/powershell:$build-$distro -c "$command" else echo "Building $image" # copy the common script because it lives outside the docker build context From 425305142142f1f01719f7830fa44fdb776e2672 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Sep 2016 20:14:58 -0700 Subject: [PATCH 19/23] Add RUNARGS and BUILDARGS for more flexibility E.g. RUNARGS="--rm" or BUILDARGS="--no-cache". --- docker/launch.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/launch.sh b/docker/launch.sh index 022c60f25..129e4c6f0 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -33,7 +33,8 @@ for build in $BUILDS; do command="git clone --recursive https://github.com/$FORK/PowerShell -b $BRANCH; $command" fi # run Pester tests inside container - docker run --rm -it powershell/powershell:$build-$distro -c "$command" + # RUNARGS can be set in the environment + docker run -it $RUNARGS powershell/powershell:$build-$distro -c "$command" else echo "Building $image" # copy the common script because it lives outside the docker build context @@ -42,7 +43,8 @@ for build in $BUILDS; do buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" fi # build and tag the image so they can be derived from - docker build $buildargs -t powershell/powershell:$build-$distro $distro + # BUILDARGS can be set in the environment + docker build $buildargs $BUILDARGS -t powershell/powershell:$build-$distro $distro fi done cd .. From 002d2a69113794d26a7d47f27568b1389274b383 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Sep 2016 11:09:38 -0700 Subject: [PATCH 20/23] Satisfy shellcheck Some variables left unquoted because they may be empty. --- docker/launch.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docker/launch.sh b/docker/launch.sh index 129e4c6f0..71430f0a6 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -22,9 +22,9 @@ fi for build in $BUILDS; do # cd so $distro is only the distro name - cd $build + pushd "$build" for distro in $DISTROS; do - image="$build/$distro" + image="powershell/powershell:$build-$distro" if [[ "$TEST" -eq 1 ]]; then echo "Testing $image" command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester -powershell powershell -Pester ./src/Modules/Shared/Pester" @@ -34,18 +34,18 @@ for build in $BUILDS; do fi # run Pester tests inside container # RUNARGS can be set in the environment - docker run -it $RUNARGS powershell/powershell:$build-$distro -c "$command" + docker run -it $RUNARGS "$image" -c "$command" else echo "Building $image" # copy the common script because it lives outside the docker build context if [[ "$build" = unstable ]]; then - cp bootstrap.ps1 $distro + cp bootstrap.ps1 "$distro" buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" fi # build and tag the image so they can be derived from # BUILDARGS can be set in the environment - docker build $buildargs $BUILDARGS -t powershell/powershell:$build-$distro $distro + docker build $buildargs $BUILDARGS -t "$image" "$distro" fi done - cd .. + popd done From f0314cd86e9ce1b8bc644e1bec75ccd170f8b86d Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Sep 2016 12:38:52 -0700 Subject: [PATCH 21/23] Parallelize Docker builds Log output to docker/logs. --- docker/.gitignore | 3 ++ docker/launch.sh | 56 ++++++++++++++++++++++---------------- docker/unstable/.gitignore | 1 - 3 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 docker/.gitignore delete mode 100644 docker/unstable/.gitignore diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 000000000..bb538ed89 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1,3 @@ +logs/*.log +packages/ +unstable/*/bootstrap.ps1 diff --git a/docker/launch.sh b/docker/launch.sh index 71430f0a6..91c8329ad 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -21,31 +21,39 @@ if [[ -z $DISTROS ]]; then fi for build in $BUILDS; do - # cd so $distro is only the distro name - pushd "$build" + # each distro can be done in parallel; but stable must be done before unstable for distro in $DISTROS; do - image="powershell/powershell:$build-$distro" - if [[ "$TEST" -eq 1 ]]; then - echo "Testing $image" - command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester -powershell powershell -Pester ./src/Modules/Shared/Pester" - # clone repo for stable images because it's not already done - if [[ "$build" = stable ]]; then - command="git clone --recursive https://github.com/$FORK/PowerShell -b $BRANCH; $command" + logfile="$build-$distro.log" + if [[ "$TEST" -eq 1 ]]; then logfile="test-$logfile"; fi + mkdir -p logs + logfile="logs/$logfile" + echo "Logging to docker/$logfile" + ( + image="powershell/powershell:$build-$distro" + cd "$build" + if [[ "$TEST" -eq 1 ]]; then + echo "LOG: testing $image" + command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester -powershell powershell -Pester ./src/Modules/Shared/Pester" + # clone repo for stable images because it's not already done + if [[ "$build" = stable ]]; then + command="git clone --recursive https://github.com/$FORK/PowerShell -b $BRANCH; $command" + fi + # run Pester tests inside container + # RUNARGS can be set in the environment + docker run $RUNARGS "$image" -c "$command" + else + echo "LOG: building $image" + # copy the common script because it lives outside the docker build context + if [[ "$build" = unstable ]]; then + cp bootstrap.ps1 "$distro" + buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" + fi + # build and tag the image so they can be derived from + # BUILDARGS can be set in the environment + docker build $buildargs $BUILDARGS -t "$image" "$distro" fi - # run Pester tests inside container - # RUNARGS can be set in the environment - docker run -it $RUNARGS "$image" -c "$command" - else - echo "Building $image" - # copy the common script because it lives outside the docker build context - if [[ "$build" = unstable ]]; then - cp bootstrap.ps1 "$distro" - buildargs="--build-arg fork=$FORK --build-arg branch=$BRANCH" - fi - # build and tag the image so they can be derived from - # BUILDARGS can be set in the environment - docker build $buildargs $BUILDARGS -t "$image" "$distro" - fi + ) &>> "$logfile" & done - popd + echo "Waiting for $build containers to finish; tail the logs for more information." + wait done diff --git a/docker/unstable/.gitignore b/docker/unstable/.gitignore deleted file mode 100644 index c1ce1f3f4..000000000 --- a/docker/unstable/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*/bootstrap.ps1 From fde942f6bba3840b6da1086aefc9eb1dab798fda Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Sep 2016 14:10:36 -0700 Subject: [PATCH 22/23] Copy artifacts from containers to docker/packages --- docker/launch.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/docker/launch.sh b/docker/launch.sh index 91c8329ad..118492652 100755 --- a/docker/launch.sh +++ b/docker/launch.sh @@ -2,6 +2,18 @@ set -e +# This is borrowed from https://github.com/dotnet/cli/blob/18456af5caeae44defc23ad5579c838c1fda3c3d/run.sh +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +# run from directory of launch.sh so artifacts are placed appropriately +pushd "$DIR" + if [[ -z "$FORK" ]]; then FORK=PowerShell fi @@ -30,7 +42,7 @@ for build in $BUILDS; do echo "Logging to docker/$logfile" ( image="powershell/powershell:$build-$distro" - cd "$build" + pushd "$build" if [[ "$TEST" -eq 1 ]]; then echo "LOG: testing $image" command="cd PowerShell; Import-Module ./build.psm1; Install-Dotnet -NoSudo; Start-PSPester -powershell powershell -Pester ./src/Modules/Shared/Pester" @@ -51,9 +63,19 @@ for build in $BUILDS; do # build and tag the image so they can be derived from # BUILDARGS can be set in the environment docker build $buildargs $BUILDARGS -t "$image" "$distro" + if [[ "$build" = unstable ]]; then + echo "LOG: Saving package to docker/packages" + popd + mkdir -p packages + command='cp -vf /PowerShell/powershell*{deb,rpm} /mnt 2> /dev/null' + # override entrypoint to be bash so we can use globbing + docker run --rm --volume "$(pwd)/packages:/mnt" --entrypoint bash "$image" -c "$command" + fi fi ) &>> "$logfile" & done echo "Waiting for $build containers to finish; tail the logs for more information." wait done + +popd From 832f1a679dbd3cacedc4bc698cd6e9ae7995e8eb Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Sep 2016 14:55:46 -0700 Subject: [PATCH 23/23] Update documentation --- README.md | 6 +- docker/README.md | 120 ++++++++++++++++++++++++++++++++++++ docs/installation/docker.md | 22 ------- 3 files changed, 123 insertions(+), 25 deletions(-) create mode 100644 docker/README.md delete mode 100644 docs/installation/docker.md diff --git a/README.md b/README.md index fe27c86a1..87cfb952c 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ You can download and install a PowerShell package for any of the following platf | Ubuntu 16.04 | [.deb][rl-ubuntu16] | [Instructions][in-ubuntu16] | | Ubuntu 14.04 | [.deb][rl-ubuntu14] | [Instructions][in-ubuntu14] | | CentOS 7 | [.rpm][rl-centos] | [Instructions][in-centos] | -| OS X 10.11 | [.pkg][rl-macos] | [Instructions][in-macos] | -| Docker | | [Instructions] [in-docker] | +| macOS 10.11 | [.pkg][rl-macos] | [Instructions][in-macos] | +| Docker | | [Instructions][in-docker] | [rl-windows10]: https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/PowerShell_6.0.0.9-alpha.9-win10-x64.msi [rl-windows81]: https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/PowerShell_6.0.0.9-alpha.9-win81-x64.msi @@ -43,7 +43,7 @@ You can download and install a PowerShell package for any of the following platf [in-ubuntu16]: docs/installation/linux.md#ubuntu-1604 [in-centos]: docs/installation/linux.md#centos-7 [in-macos]: docs/installation/linux.md#macos-1011 -[in-docker]: docs/installation/docker.md +[in-docker]: docker To install a specific version, visit [releases](https://github.com/PowerShell/PowerShell/releases). diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..189e92f07 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,120 @@ +Docker +====== + +These Dockerfiles enable building and running PowerShell in a container for each Linux distribution we support. +There are two sets: stable and unstable. + +This requires an up-to-date version of Docker, such as 1.12. +It also expects you to be able to run Docker without `sudo`. +Please follow [Docker's official instructions][install] to install `docker` correctly. + +> Note: we intend to publish automatically built containers on the Docker Hub, +> but this work is still pending. + +[install]: https://docs.docker.com/engine/installation/ + +Stable +------ + +The stable containers derive from the official distribution image, +such as `centos:7`, then install dependencies, +and finally install the PowerShell package. + +At about 440 megabytes, they are decently minimal, +with their size being the sum of the base image (200 megabytes) +plus the uncompressed package (120 megabytes), +and about 120 megabytes of .NET Core and bootstrapping dependencies. + +Unstable +-------- + +The unstable containers derive from their respective stable images, +such as `powershell/powershell:stable-centos7`, +then run the `bootstrap.ps1` script which clones the repository, +runs `Start-PSBootstrap -Package` to install building and packaging tools, +runs `Start-PSBuild -Crossgen` to build PowerShell with native-image DLLs, +runs `Start-PSPackage` to generate the platform's package, +and finally installs the generated package. + +At about 4 gigabytes, +these images are *much* larger due to having all the tools installed. +This is intended so that the containers are useful for reproducing packages. + +Automation +========== + +A script, `launch.sh`, exists to automatically build all the respective images. +It has a few configuration options, +passed in as environment variables: + +* `FORK`: the fork to clone in unstable builds (default: `PowerShell`) + * Set `FORK=andschwa` to clone https://github.com/andschwa/PowerShell + +* `BRANCH`: the branch to checkout in unstable builds (default: `master`) + * Set `BRANCH=feature-A` to checkout the `feature-A` branch + +* `BUILDS`: the type of builds to run (default: `stable unstable`) + * This is order dependent! Stable images must exist for unstable images to be built + * Set `BUILDS=stable` to run the script for just the stable images + +* `DISTROS`: the distributions of Linux to run (default: `ubuntu14.04 ubuntu16.04 centos7`) + * Set `DISTROS=centos7` to build just CentOS 7 images + * Combine with `BUILDS` to filter + +* `TEST`: set to 1 to `docker run Start-PSPester` inside the containers + * The containers *must* first exist; this skips the build step + +* `BUILDARGS`: additional arguments to be passed to `docker build` during building + * Set `BUILDARGS="--no-cache"` to rebuild and ignore cached layers + +* `RUNARGS`: additional arguments to be passed to `docker run` during testing + * Set `RUNARGS="--rm"` to automatically delete the test container when finished + +For each build type (stable and unstable), +the selected distributions will run in parallel. +The output is sent to log files in `docker/logs`. +For unstable builds, the generated packages are copied to `docker/packages`. + +This script is very new, and there may be bugs. +Use `set -x` to see exactly what commands it is running. + +Examples +-------- + +To build a CentOS container with the latest released package: + +```sh +$ BUILDS=stable DISTROS=centos7 ./launch.sh +Logging to docker/logs/stable-centos7.log +Waiting for stable containers to finish; tail the logs for more information. + +$ docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +powershell/powershell stable-centos7 f0a11a8009b7 20 minutes ago 438.3 MB +... +``` + +To generate an Ubuntu 16.04 package from andschwa's `docker` branch: + +```sh +$ DISTROS=ubuntu16.04 FORK=andschwa BRANCH=docker ./launch.sh +Logging to docker/logs/stable-ubuntu16.04.log +Waiting for stable containers to finish; tail the logs for more information. +Logging to docker/logs/unstable-ubuntu16.04.log +Waiting for unstable containers to finish; tail the logs for more information. + +$ ls packages +powershell_6.0.0-alpha.9-310-g5ded651-1ubuntu1.16.04.1_amd64.deb + +$ tail logs/unstable-ubuntu16.04.log +Step 5 : COPY bootstrap.ps1 / + ---> Using cache + ---> d18a28ff1e3d +Step 6 : RUN powershell -f bootstrap.ps1 && dpkg -i PowerShell/powershell*.deb + ---> Using cache + ---> 9cd8b1ef79b3 +Successfully built 9cd8b1ef79b3 +LOG: Saving package to docker/packages +~/src/PowerShell/docker ~/src/PowerShell/docker +'/PowerShell/powershell_6.0.0-alpha.9-310-g5ded651-1ubuntu1.16.04.1_amd64.deb' -> '/mnt/powershell_6.0.0-alpha.9-310-g5ded651-1ubuntu1.16.04.1_amd64.deb' +``` diff --git a/docs/installation/docker.md b/docs/installation/docker.md deleted file mode 100644 index 8de9b5841..000000000 --- a/docs/installation/docker.md +++ /dev/null @@ -1,22 +0,0 @@ -Docker -====== - -Build -===== - -If you want to build it yourself: -``` -docker build -t powershell . -``` - -Run -=== - -After you have built using Docker, running PowerShell very simple: - -``` -docker run -it powershell -``` - -This Docker image is based on Ubuntu 16.04, and follows the instructions from the [Linux Installation docs][u16]. -[u16]: linux.md#ubuntu-1604