From 7953cbe3a27974bd917487197fa0f26b756d8acd Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 7 Sep 2018 15:04:18 -0700 Subject: [PATCH 1/7] Add ability for an image to be Linux, but use the Windows Version format --- build.ps1 | 15 +++------------ tools/buildHelper/buildHelper.psm1 | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/build.ps1 b/build.ps1 index 0c82773c1..d10cd2bdd 100644 --- a/build.ps1 +++ b/build.ps1 @@ -145,7 +145,6 @@ Begin { # We are using all, so get the list off all images for the current channel $Name = Get-ImageList -Channel $Channel } - Write-Verbose "wv: $windowsVersion; lv: $linuxVersion" -Verbose } End { @@ -222,18 +221,10 @@ End { } $tagsTemplates = Get-Content -Path $tagsJsonPath | ConvertFrom-Json - $isContainerLinux = $false - if(Test-Path $metaJsonPath) - { - $meta = Get-Content -Path $metaJsonPath | ConvertFrom-Json - if($meta.IsLinux) - { - $isContainerLinux = [bool] $meta.IsLinux - } - } + $meta = Get-DockerImageMetaData -Path $metaJsonPath $psversion = $windowsVersion - if($isContainerLinux) + if($meta.UseLinuxVersion) { $psversion = $linuxVersion } @@ -274,7 +265,7 @@ End { $script:ErrorActionPreference = 'stop' $testsPath = Join-Path -Path $PSScriptRoot -ChildPath 'tests' Import-Module (Join-Path -Path $testsPath -ChildPath 'containerTestCommon.psm1') -Force - if ($isContainerLinux) { + if ($meta.IsLinux) { $os = 'linux' } else { diff --git a/tools/buildHelper/buildHelper.psm1 b/tools/buildHelper/buildHelper.psm1 index a46ea4b7e..d7595b80f 100644 --- a/tools/buildHelper/buildHelper.psm1 +++ b/tools/buildHelper/buildHelper.psm1 @@ -53,3 +53,26 @@ function Get-ImageList Get-ChildItem -Path $previewPath -Directory | Select-Object -ExpandProperty Name | Where-Object { $dockerFileNames -notcontains $_ } | Write-Output } } + +class DockerImageMetaData { + [Bool] + $IsLinux = $false + [Bool] + $UseLinuxVersion = $IsLinuxContainer +} + +Function Get-DockerImageMetaData +{ + param( + [parameter(Mandatory)] + $Path + ) + + if (Test-Path $Path) + { + $meta = Get-Content -Path $Path | ConvertFrom-Json + return [DockerImageMetaData] $meta + } + + return [DockerImageMetaData]::new() +} From 40ba1f8d1e6f8abcd0d9116314082ab7c2058246 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 7 Sep 2018 15:04:34 -0700 Subject: [PATCH 2/7] Add files to bootstrap alpine --- release/preview/alpine/docker/Dockerfile | 85 ++++++++++++++++++++++++ release/preview/alpine/getLatestTag.ps1 | 14 ++++ release/preview/alpine/meta.json | 4 ++ release/preview/alpine/tags.json | 4 ++ 4 files changed, 107 insertions(+) create mode 100644 release/preview/alpine/docker/Dockerfile create mode 100644 release/preview/alpine/getLatestTag.ps1 create mode 100644 release/preview/alpine/meta.json create mode 100644 release/preview/alpine/tags.json diff --git a/release/preview/alpine/docker/Dockerfile b/release/preview/alpine/docker/Dockerfile new file mode 100644 index 000000000..063c7ff94 --- /dev/null +++ b/release/preview/alpine/docker/Dockerfile @@ -0,0 +1,85 @@ +# Docker image file that describes an Alpine3.8 image with PowerShell installed from .tar.gz file(s) +# NOTE: the alpine tar.gz when this was written doesn't contain the modules. For that we need a container with modules. +# To accomplish this, we will get the modules from the full linux tar.gz package, then +# overlay the alpine tar.gz on top of it. +# There are TODO's in the file on updates that should occure one the Alpine .tar.gz contains everything + +ARG fromTag=16.04 + +FROM alpine:3.8 + +ARG PS_VERSION=6.1.0-rc.1 +ARG PS_VERSION_POSTFIX=-1.ubuntu.16.04 +# TODO: once the official build produces a full package for alpine, update this to the full package +ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-x64.tar.gz +ARG IMAGE_NAME=microsoft/powershell:ubuntu16.04 +ARG VCS_REF="none" + +LABEL maintainer="PowerShell Team " \ + readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ + description="This Dockerfile will install the latest release of PS." \ + org.label-schema.usage="https://github.com/PowerShell/PowerShell/tree/master/docker#run-the-docker-image-you-built" \ + org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ + org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell-Docker" \ + org.label-schema.name="powershell" \ + org.label-schema.vendor="PowerShell" \ + org.label-schema.vcs-ref=${VCS_REF} \ + org.label-schema.version=${PS_VERSION} \ + org.label-schema.schema-version="1.0" \ + org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" \ + org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" \ + org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" \ + org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" + +RUN apk add --no-cache \ + ca-certificates \ + \ + # .NET Core dependencies + krb5-libs \ + libgcc \ + libintl \ + libssl1.0 \ + libstdc++ \ + tzdata \ + userspace-rcu \ + zlib \ + && apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \ + lttng-ust + +RUN apk add --no-cache \ + curl + +# Set the invariant mode since icu_libs isn't included (see https://github.com/dotnet/announcements/issues/20) +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true + +# Get the InstallTarballPackage.sh script +ADD https://raw.githubusercontent.com/PowerShell/PowerShell/master/docker/InstallTarballPackage.sh /InstallTarballPackage.sh + +# Add execution permission +RUN chmod +x /InstallTarballPackage.sh + +# Install powershell from tarball package +RUN /InstallTarballPackage.sh $PS_VERSION $PS_PACKAGE + +# Create the preview symbolic link that points to powershell +# InstallTarballPackage creates the pwsh link +RUN ln -s /opt/microsoft/powershell/$S_VERSION/pwsh /usr/bin/pwsh-preview + +# Remove the script +RUN rm -f /InstallTarballPackage.sh + +# Begin region to overlay the alpine tag.gz +# TODO: once the official build produces a full package for alpine, remove this region + +# Download the powershell .tar.gz package +RUN curl -L -o /tmp/powershell.tar.gz https://github.com/TravisEz13/PowerShell/releases/download/v6.1.0-rc.1/powershell-6.1.0-fixalpine-linux-musl-x64.tar.gz + +# Expand powershell to the target folder +RUN tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/$PS_VERSION + +# remove tar.gz +RUN rm -f /tmp/powershell.tar.gz + +# End region to overlay the alpine tag.gz + +CMD [ "pwsh" ] diff --git a/release/preview/alpine/getLatestTag.ps1 b/release/preview/alpine/getLatestTag.ps1 new file mode 100644 index 000000000..16be03136 --- /dev/null +++ b/release/preview/alpine/getLatestTag.ps1 @@ -0,0 +1,14 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# return objects representing the tags we need to base the xenial image on + +# The versions of xenial we care about +$shortTags = @('3.8') + +$parent = Join-Path -Path $PSScriptRoot -ChildPath '..' +$repoRoot = Join-Path -path (Join-Path -Path $parent -ChildPath '..') -ChildPath '..' +$modulePath = Join-Path -Path $repoRoot -ChildPath 'tools\getDockerTags' +Import-Module $modulePath + +Get-DockerTags -ShortTags $shortTags -Image "alpine" -FullTagFilter '^3.8$' -OnlyShortTags diff --git a/release/preview/alpine/meta.json b/release/preview/alpine/meta.json new file mode 100644 index 000000000..1424d37f0 --- /dev/null +++ b/release/preview/alpine/meta.json @@ -0,0 +1,4 @@ +{ + "IsLinux" : true, + "UseLinuxVersion": false +} diff --git a/release/preview/alpine/tags.json b/release/preview/alpine/tags.json new file mode 100644 index 000000000..c58f3d648 --- /dev/null +++ b/release/preview/alpine/tags.json @@ -0,0 +1,4 @@ +[ + "#psversion#-alpine-#tag#", + "preview-alpine-#shorttag#" +] From 563aaa74120a5dd842293531de5aed614a478ce8 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 7 Sep 2018 16:13:55 -0700 Subject: [PATCH 3/7] Update the docker file to be multi-stage and use ADD instead of curl --- release/preview/alpine/docker/Dockerfile | 124 +++++++++++++---------- 1 file changed, 69 insertions(+), 55 deletions(-) diff --git a/release/preview/alpine/docker/Dockerfile b/release/preview/alpine/docker/Dockerfile index 063c7ff94..18002075b 100644 --- a/release/preview/alpine/docker/Dockerfile +++ b/release/preview/alpine/docker/Dockerfile @@ -4,33 +4,54 @@ # overlay the alpine tar.gz on top of it. # There are TODO's in the file on updates that should occure one the Alpine .tar.gz contains everything -ARG fromTag=16.04 +# Define arg(s) needed for the From statement +ARG fromTag=3.8 -FROM alpine:3.8 +FROM alpine:${fromTag} AS installer-env +# Define Args for the needed to add the package ARG PS_VERSION=6.1.0-rc.1 -ARG PS_VERSION_POSTFIX=-1.ubuntu.16.04 # TODO: once the official build produces a full package for alpine, update this to the full package ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-x64.tar.gz -ARG IMAGE_NAME=microsoft/powershell:ubuntu16.04 -ARG VCS_REF="none" +ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} +ARG PS_INSTALL_VERSION=6-preview -LABEL maintainer="PowerShell Team " \ - readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ - description="This Dockerfile will install the latest release of PS." \ - org.label-schema.usage="https://github.com/PowerShell/PowerShell/tree/master/docker#run-the-docker-image-you-built" \ - org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ - org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell-Docker" \ - org.label-schema.name="powershell" \ - org.label-schema.vendor="PowerShell" \ - org.label-schema.vcs-ref=${VCS_REF} \ - org.label-schema.version=${PS_VERSION} \ - org.label-schema.schema-version="1.0" \ - org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" \ - org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" \ - org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" \ - org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" +# downoad the Linux tar.gz and save it +ADD ${PS_PACKAGE_URL} /tmp/linux.tar.gz + +# define the folder we will be installing PowerShell to +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION + +# Create the install folder +RUN mkdir -p ${PS_INSTALL_FOLDER} + +# Unzip the Linux tar.gz +RUN tar zxf /tmp/linux.tar.gz -C ${PS_INSTALL_FOLDER} + +# TODO: once the official build produces a full package for alpine, remove this overlay of the apline files +# Download the apline powershell .tar.gz package +ADD https://github.com/TravisEz13/PowerShell/releases/download/v6.1.0-rc.1/powershell-6.1.0-fixalpine-linux-musl-x64.tar.gz /tmp/alpine.tar.gz +# Extract the alpine tar.gz +RUN tar zxf /tmp/alpine.tar.gz -C ${PS_INSTALL_FOLDER} + +# Start a new stage so we loose all the tar.gz layers from the final image +FROM alpine:${fromTag} + + +# Copy only the files we need from the previous stag +COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"] + +# Define Args and Env needed to create links +ARG PS_INSTALL_VERSION=6-preview +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \ + \ + # Define ENVs for Localization/Globalization + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ + LC_ALL=en_US.UTF-8 \ + LANG=en_US.UTF-8 + +# Install dotnet dependencies and ca-certificates RUN apk add --no-cache \ ca-certificates \ \ @@ -43,43 +64,36 @@ RUN apk add --no-cache \ tzdata \ userspace-rcu \ zlib \ + icu-libs \ && apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \ - lttng-ust - -RUN apk add --no-cache \ - curl - -# Set the invariant mode since icu_libs isn't included (see https://github.com/dotnet/announcements/issues/20) -ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true - -# Get the InstallTarballPackage.sh script -ADD https://raw.githubusercontent.com/PowerShell/PowerShell/master/docker/InstallTarballPackage.sh /InstallTarballPackage.sh - -# Add execution permission -RUN chmod +x /InstallTarballPackage.sh - -# Install powershell from tarball package -RUN /InstallTarballPackage.sh $PS_VERSION $PS_PACKAGE - -# Create the preview symbolic link that points to powershell -# InstallTarballPackage creates the pwsh link -RUN ln -s /opt/microsoft/powershell/$S_VERSION/pwsh /usr/bin/pwsh-preview - -# Remove the script -RUN rm -f /InstallTarballPackage.sh - -# Begin region to overlay the alpine tag.gz -# TODO: once the official build produces a full package for alpine, remove this region - -# Download the powershell .tar.gz package -RUN curl -L -o /tmp/powershell.tar.gz https://github.com/TravisEz13/PowerShell/releases/download/v6.1.0-rc.1/powershell-6.1.0-fixalpine-linux-musl-x64.tar.gz - -# Expand powershell to the target folder -RUN tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/$PS_VERSION + lttng-ust \ + \ + # Create the pwsh symbolic link that points to powershell + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh \ + \ + # Create the pwsh-preview symbolic link that points to powershell + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh-preview -# remove tar.gz -RUN rm -f /tmp/powershell.tar.gz -# End region to overlay the alpine tag.gz +# Define args needed only for the labels +ARG PS_VERSION=6.1.0-rc.1 +ARG IMAGE_NAME=microsoft/powershell:ubuntu16.04 +ARG VCS_REF="none" +# Add label last as it's just metadata and usere a lot a parameters +LABEL maintainer="PowerShell Team " \ + readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ + description="This Dockerfile will install the latest release of PS." \ + org.label-schema.usage="https://github.com/PowerShell/PowerShell/tree/master/docker#run-the-docker-image-you-built" \ + org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ + org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell-Docker" \ + org.label-schema.name="powershell" \ + org.label-schema.vendor="PowerShell" \ + org.label-schema.vcs-ref=${VCS_REF} \ + org.label-schema.version=${PS_VERSION} \ + org.label-schema.schema-version="1.0" \ + org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" \ + org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" \ + org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" \ + org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" CMD [ "pwsh" ] From f01189ccb1aaa15dae36afaea2dcb6201c6e2307 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 7 Sep 2018 16:46:11 -0700 Subject: [PATCH 4/7] fix regression in build.ps1 --- build.ps1 | 2 +- tools/buildHelper/buildHelper.psm1 | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build.ps1 b/build.ps1 index d10cd2bdd..db88166e0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -224,7 +224,7 @@ End { $meta = Get-DockerImageMetaData -Path $metaJsonPath $psversion = $windowsVersion - if($meta.UseLinuxVersion) + if($meta.ShouldUseLinuxVersion()) { $psversion = $linuxVersion } diff --git a/tools/buildHelper/buildHelper.psm1 b/tools/buildHelper/buildHelper.psm1 index d7595b80f..b1efc3cb9 100644 --- a/tools/buildHelper/buildHelper.psm1 +++ b/tools/buildHelper/buildHelper.psm1 @@ -57,8 +57,18 @@ function Get-ImageList class DockerImageMetaData { [Bool] $IsLinux = $false - [Bool] - $UseLinuxVersion = $IsLinuxContainer + + [System.Nullable[Bool]] + $UseLinuxVersion = $null + + [bool] ShouldUseLinuxVersion() { + if($this.UseLinuxVersion -is [bool]) + { + return $this.UseLinuxVersion + } + + return $this.IsLinux + } } Function Get-DockerImageMetaData From a5906db67de57b41d19703ea6f37dcf25bf8e2bf Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 7 Sep 2018 16:49:13 -0700 Subject: [PATCH 5/7] remove extra newlines --- release/preview/alpine/docker/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/release/preview/alpine/docker/Dockerfile b/release/preview/alpine/docker/Dockerfile index 18002075b..8b6363a15 100644 --- a/release/preview/alpine/docker/Dockerfile +++ b/release/preview/alpine/docker/Dockerfile @@ -38,7 +38,6 @@ RUN tar zxf /tmp/alpine.tar.gz -C ${PS_INSTALL_FOLDER} # Start a new stage so we loose all the tar.gz layers from the final image FROM alpine:${fromTag} - # Copy only the files we need from the previous stag COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"] @@ -74,7 +73,6 @@ RUN apk add --no-cache \ # Create the pwsh-preview symbolic link that points to powershell && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh-preview - # Define args needed only for the labels ARG PS_VERSION=6.1.0-rc.1 ARG IMAGE_NAME=microsoft/powershell:ubuntu16.04 From bd8ef49cb4e7c22fc223e0b92b6bda3894facd7f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 11 Sep 2018 12:27:33 -0700 Subject: [PATCH 6/7] address PR comments --- release/preview/alpine/docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release/preview/alpine/docker/Dockerfile b/release/preview/alpine/docker/Dockerfile index 8b6363a15..0921319d8 100644 --- a/release/preview/alpine/docker/Dockerfile +++ b/release/preview/alpine/docker/Dockerfile @@ -2,7 +2,7 @@ # NOTE: the alpine tar.gz when this was written doesn't contain the modules. For that we need a container with modules. # To accomplish this, we will get the modules from the full linux tar.gz package, then # overlay the alpine tar.gz on top of it. -# There are TODO's in the file on updates that should occure one the Alpine .tar.gz contains everything +# There are TODO's in the file on updates that should occur one the Alpine .tar.gz contains everything # Define arg(s) needed for the From statement ARG fromTag=3.8 @@ -11,7 +11,7 @@ FROM alpine:${fromTag} AS installer-env # Define Args for the needed to add the package ARG PS_VERSION=6.1.0-rc.1 -# TODO: once the official build produces a full package for alpine, update this to the full package +# TODO: once the official build produces a full package for alpine, update this to the full apline package ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-x64.tar.gz ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} ARG PS_INSTALL_VERSION=6-preview From e1af716be801867b9d9b457dc75661a32cf74c31 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 11 Sep 2018 13:54:17 -0700 Subject: [PATCH 7/7] fix spelling issue and capitalization --- release/preview/alpine/docker/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/release/preview/alpine/docker/Dockerfile b/release/preview/alpine/docker/Dockerfile index 0921319d8..dd03cc408 100644 --- a/release/preview/alpine/docker/Dockerfile +++ b/release/preview/alpine/docker/Dockerfile @@ -1,7 +1,7 @@ # Docker image file that describes an Alpine3.8 image with PowerShell installed from .tar.gz file(s) -# NOTE: the alpine tar.gz when this was written doesn't contain the modules. For that we need a container with modules. +# NOTE: the Alpine tar.gz when this was written doesn't contain the modules. For that we need a container with modules. # To accomplish this, we will get the modules from the full linux tar.gz package, then -# overlay the alpine tar.gz on top of it. +# overlay the Alpine tar.gz on top of it. # There are TODO's in the file on updates that should occur one the Alpine .tar.gz contains everything # Define arg(s) needed for the From statement @@ -11,7 +11,7 @@ FROM alpine:${fromTag} AS installer-env # Define Args for the needed to add the package ARG PS_VERSION=6.1.0-rc.1 -# TODO: once the official build produces a full package for alpine, update this to the full apline package +# TODO: once the official build produces a full package for Alpine, update this to the full Alpine package ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-x64.tar.gz ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} ARG PS_INSTALL_VERSION=6-preview @@ -28,11 +28,11 @@ RUN mkdir -p ${PS_INSTALL_FOLDER} # Unzip the Linux tar.gz RUN tar zxf /tmp/linux.tar.gz -C ${PS_INSTALL_FOLDER} -# TODO: once the official build produces a full package for alpine, remove this overlay of the apline files +# TODO: once the official build produces a full package for Alpine, remove this overlay of the apline files # Download the apline powershell .tar.gz package ADD https://github.com/TravisEz13/PowerShell/releases/download/v6.1.0-rc.1/powershell-6.1.0-fixalpine-linux-musl-x64.tar.gz /tmp/alpine.tar.gz -# Extract the alpine tar.gz +# Extract the Alpine tar.gz RUN tar zxf /tmp/alpine.tar.gz -C ${PS_INSTALL_FOLDER} # Start a new stage so we loose all the tar.gz layers from the final image