|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +# Docker image file that describes an Alpine image with PowerShell installed from .tar.gz file(s) |
| 5 | +ARG hostRegistry=psdockercache.azurecr.io |
| 6 | +FROM ${hostRegistry}/alpine:3.16 AS installer-env |
| 7 | + |
| 8 | +# Define Args for the needed to add the package |
| 9 | +ARG PS_VERSION=7.3.0-preview.8 |
| 10 | +ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-alpine-x64.tar.gz |
| 11 | +ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} |
| 12 | +ARG PS_INSTALL_VERSION=7-preview |
| 13 | + |
| 14 | +# Download the Linux tar.gz and save it |
| 15 | +ADD ${PS_PACKAGE_URL} /tmp/linux.tar.gz |
| 16 | + |
| 17 | +# define the folder we will be installing PowerShell to |
| 18 | +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION |
| 19 | + |
| 20 | +# Create the install folder |
| 21 | +RUN mkdir -p ${PS_INSTALL_FOLDER} |
| 22 | + |
| 23 | +# Unzip the Linux tar.gz |
| 24 | +RUN tar zxf /tmp/linux.tar.gz -C ${PS_INSTALL_FOLDER} -v |
| 25 | + |
| 26 | +# Start a new stage so we lose all the tar.gz layers from the final image |
| 27 | +ARG hostRegistry=psdockercache.azurecr.io |
| 28 | +FROM ${hostRegistry}/alpine:3.16 |
| 29 | + |
| 30 | +# Copy only the files we need from the previous stage |
| 31 | +COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"] |
| 32 | + |
| 33 | +# Define Args and Env needed to create links |
| 34 | +ARG PS_INSTALL_VERSION=7-preview |
| 35 | +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \ |
| 36 | + \ |
| 37 | + # Define ENVs for Localization/Globalization |
| 38 | + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ |
| 39 | + LC_ALL=en_US.UTF-8 \ |
| 40 | + LANG=en_US.UTF-8 \ |
| 41 | + # set a fixed location for the Module analysis cache |
| 42 | + PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache \ |
| 43 | + POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-Alpine-3.16 |
| 44 | + |
| 45 | +# Install dotnet dependencies and ca-certificates |
| 46 | +RUN apk add --no-cache \ |
| 47 | + ca-certificates \ |
| 48 | + less \ |
| 49 | + \ |
| 50 | + # PSReadline/console dependencies |
| 51 | + ncurses-terminfo-base \ |
| 52 | + \ |
| 53 | + # .NET Core dependencies |
| 54 | + krb5-libs \ |
| 55 | + libgcc \ |
| 56 | + libintl \ |
| 57 | + libssl1.1 \ |
| 58 | + libstdc++ \ |
| 59 | + tzdata \ |
| 60 | + userspace-rcu \ |
| 61 | + zlib \ |
| 62 | + icu-libs \ |
| 63 | + && apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \ |
| 64 | + lttng-ust \ |
| 65 | + \ |
| 66 | + # PowerShell remoting over SSH dependencies |
| 67 | + openssh-client \ |
| 68 | + \ |
| 69 | + && apk update \ |
| 70 | + && apk upgrade \ |
| 71 | + # Create the pwsh symbolic link that points to powershell |
| 72 | + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh \ |
| 73 | + \ |
| 74 | + # Create the pwsh-preview symbolic link that points to powershell |
| 75 | + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh-preview \ |
| 76 | + # Give all user execute permissions and remove write permissions for others |
| 77 | + && chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \ |
| 78 | + # intialize powershell module cache |
| 79 | + # and disable telemetry |
| 80 | + && export POWERSHELL_TELEMETRY_OPTOUT=1 \ |
| 81 | + && pwsh \ |
| 82 | + -NoLogo \ |
| 83 | + -NoProfile \ |
| 84 | + -Command " \ |
| 85 | + \$ErrorActionPreference = 'Stop' ; \ |
| 86 | + \$ProgressPreference = 'SilentlyContinue' ; \ |
| 87 | + while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \ |
| 88 | + Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \ |
| 89 | + Start-Sleep -Seconds 6 ; \ |
| 90 | + }" |
| 91 | + |
| 92 | +CMD [ "pwsh" ] |
0 commit comments