|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +# Docker image file that describes an Alpine3.x image with PowerShell installed from .tar.gz file(s) |
| 5 | + |
| 6 | +# Define arg(s) needed for the From statement |
| 7 | +ARG fromTag=3.9 |
| 8 | +ARG imageRepo=alpine |
| 9 | + |
| 10 | +FROM ${imageRepo}:${fromTag} AS installer-env |
| 11 | + |
| 12 | +# Define Args for the needed to add the package |
| 13 | +ARG PS_VERSION=6.2.0-preview.3 |
| 14 | +ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-alpine-x64.tar.gz |
| 15 | +ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} |
| 16 | +ARG PS_INSTALL_VERSION=7-preview |
| 17 | + |
| 18 | +# Download the Linux tar.gz and save it |
| 19 | +ADD ${PS_PACKAGE_URL} /tmp/linux.tar.gz |
| 20 | + |
| 21 | +# define the folder we will be installing PowerShell to |
| 22 | +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION |
| 23 | + |
| 24 | +# Create the install folder |
| 25 | +RUN mkdir -p ${PS_INSTALL_FOLDER} |
| 26 | + |
| 27 | +# Unzip the Linux tar.gz |
| 28 | +RUN tar zxf /tmp/linux.tar.gz -C ${PS_INSTALL_FOLDER} |
| 29 | + |
| 30 | +# Start a new stage so we lose all the tar.gz layers from the final image |
| 31 | +FROM ${imageRepo}:${fromTag} |
| 32 | + |
| 33 | +# Copy only the files we need from the previous stage |
| 34 | +COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"] |
| 35 | + |
| 36 | +# Define Args and Env needed to create links |
| 37 | +ARG PS_INSTALL_VERSION=7-preview |
| 38 | +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \ |
| 39 | + \ |
| 40 | + # Define ENVs for Localization/Globalization |
| 41 | + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ |
| 42 | + LC_ALL=en_US.UTF-8 \ |
| 43 | + LANG=en_US.UTF-8 \ |
| 44 | + # set a fixed location for the Module analysis cache |
| 45 | + PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache |
| 46 | + |
| 47 | +# Install dotnet dependencies and ca-certificates |
| 48 | +RUN apk add --no-cache \ |
| 49 | + ca-certificates \ |
| 50 | + less \ |
| 51 | + \ |
| 52 | + # PSReadline/console dependencies |
| 53 | + ncurses-terminfo-base \ |
| 54 | + \ |
| 55 | + # .NET Core dependencies |
| 56 | + krb5-libs \ |
| 57 | + libgcc \ |
| 58 | + libintl \ |
| 59 | + libssl1.1 \ |
| 60 | + libstdc++ \ |
| 61 | + tzdata \ |
| 62 | + userspace-rcu \ |
| 63 | + zlib \ |
| 64 | + icu-libs \ |
| 65 | + && apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \ |
| 66 | + lttng-ust \ |
| 67 | + \ |
| 68 | + # Create the pwsh symbolic link that points to powershell |
| 69 | + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh \ |
| 70 | + \ |
| 71 | + # Create the pwsh-preview symbolic link that points to powershell |
| 72 | + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh-preview \ |
| 73 | + # Give all user execute permissions and remove write permissions for others |
| 74 | + && chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \ |
| 75 | + # intialize powershell module cache |
| 76 | + && pwsh \ |
| 77 | + -NoLogo \ |
| 78 | + -NoProfile \ |
| 79 | + -Command " \ |
| 80 | + \$ErrorActionPreference = 'Stop' ; \ |
| 81 | + \$ProgressPreference = 'SilentlyContinue' ; \ |
| 82 | + while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \ |
| 83 | + Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \ |
| 84 | + Start-Sleep -Seconds 6 ; \ |
| 85 | + }" |
| 86 | + |
| 87 | +# Define args needed only for the labels |
| 88 | +ARG PS_VERSION=6.2.0-preview.2 |
| 89 | +ARG IMAGE_NAME=mcr.microsoft.com/powershell:preview-alpine-3.8 |
| 90 | +ARG VCS_REF="none" |
| 91 | + |
| 92 | +# Add label last as it's just metadata and uses a lot of parameters |
| 93 | +LABEL maintainer= "PowerShell Team <[email protected]>" \ |
| 94 | + readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ |
| 95 | + description="This Dockerfile will install the latest release of PowerShell." \ |
| 96 | + org.label-schema.usage="https://github.com/PowerShell/PowerShell/tree/master/docker#run-the-docker-image-you-built" \ |
| 97 | + org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ |
| 98 | + org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell-Docker" \ |
| 99 | + org.label-schema.name="powershell" \ |
| 100 | + org.label-schema.vendor="PowerShell" \ |
| 101 | + org.label-schema.vcs-ref=${VCS_REF} \ |
| 102 | + org.label-schema.version=${PS_VERSION} \ |
| 103 | + org.label-schema.schema-version="1.0" \ |
| 104 | + org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" \ |
| 105 | + org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" \ |
| 106 | + org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" \ |
| 107 | + org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" |
| 108 | + |
| 109 | +CMD [ "pwsh" ] |
0 commit comments