Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.ShouldUseLinuxVersion())
{
$psversion = $linuxVersion
}
Expand Down Expand Up @@ -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 {
Expand Down
97 changes: 97 additions & 0 deletions release/preview/alpine/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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 occur one the Alpine .tar.gz contains everything

# Define arg(s) needed for the From statement
ARG fromTag=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
# 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

# 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 \
\
# .NET Core dependencies
krb5-libs \
libgcc \
libintl \
libssl1.0 \
libstdc++ \
tzdata \
userspace-rcu \
zlib \
icu-libs \
&& apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \
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

# 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 <powershellteam@hotmail.com>" \
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" ]
14 changes: 14 additions & 0 deletions release/preview/alpine/getLatestTag.ps1
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions release/preview/alpine/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"IsLinux" : true,
"UseLinuxVersion": false
}
4 changes: 4 additions & 0 deletions release/preview/alpine/tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"#psversion#-alpine-#tag#",
"preview-alpine-#shorttag#"
]
33 changes: 33 additions & 0 deletions tools/buildHelper/buildHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,36 @@ function Get-ImageList
Get-ChildItem -Path $previewPath -Directory | Select-Object -ExpandProperty Name | Where-Object { $dockerFileNames -notcontains $_ } | Write-Output
}
}

class DockerImageMetaData {
[Bool]
$IsLinux = $false

[System.Nullable[Bool]]
$UseLinuxVersion = $null

[bool] ShouldUseLinuxVersion() {
if($this.UseLinuxVersion -is [bool])
{
return $this.UseLinuxVersion
}

return $this.IsLinux
}
}

Function Get-DockerImageMetaData
{
param(
[parameter(Mandatory)]
$Path
)

if (Test-Path $Path)
{
$meta = Get-Content -Path $Path | ConvertFrom-Json
return [DockerImageMetaData] $meta
}

return [DockerImageMetaData]::new()
}