|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +# Docker image file that describes an Ubuntu20.04 image with PowerShell installed from Microsoft APT Repo |
| 5 | +ARG hostRegistry=psdockercache.azurecr.io |
| 6 | +FROM ${hostRegistry}/ubuntu:24.04 AS installer-env |
| 7 | + |
| 8 | +# Define Args for the needed to add the package |
| 9 | +ARG PS_VERSION=7.5.0-preview.5 |
| 10 | +ARG PS_PACKAGE=powershell-preview_${PS_VERSION}-1.deb_amd64.deb |
| 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 | +RUN --mount=type=cache,target=/var/lib/apt \ |
| 15 | + --mount=type=cache,target=/var/cache/apt \ |
| 16 | + apt-get update \ |
| 17 | + && apt-get install --no-install-recommends -y \ |
| 18 | + # curl is required to grab the Linux package |
| 19 | + curl \ |
| 20 | + # less is required for help in powershell |
| 21 | + less \ |
| 22 | + # requied to setup the locale |
| 23 | + locales \ |
| 24 | + # required for SSL |
| 25 | + ca-certificates \ |
| 26 | + # Download the Linux package and save it |
| 27 | + && echo ${PS_PACKAGE_URL} \ |
| 28 | + && curl -sSL ${PS_PACKAGE_URL} -o /tmp/powershell.deb |
| 29 | + |
| 30 | +# Install the deb file in this image and make powershell available |
| 31 | +ARG hostRegistry=psdockercache.azurecr.io |
| 32 | +FROM ${hostRegistry}/ubuntu:24.04 AS final-image |
| 33 | + |
| 34 | +# # Define args needed to add the package |
| 35 | +ARG PS_VERSION=7.5.0-preview.5 |
| 36 | +ARG PS_PACKAGE=powershell-preview_${PS_VERSION}-1.deb_amd64.deb |
| 37 | +ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} |
| 38 | +ARG PS_INSTALL_VERSION=7-preview |
| 39 | + |
| 40 | +# Define ENVs for Localization/Globalization |
| 41 | +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ |
| 42 | + LC_ALL=en_US.UTF-8 \ |
| 43 | + LANG=en_US.UTF-8 \ |
| 44 | + PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \ |
| 45 | + # set a fixed location for the Module analysis cache |
| 46 | + PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache \ |
| 47 | + POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-Ubuntu-24.04 |
| 48 | + |
| 49 | +# Install dependencies and clean up |
| 50 | +RUN --mount=from=installer-env,target=/mnt/pwsh,source=/tmp \ |
| 51 | + --mount=type=cache,target=/var/lib/apt \ |
| 52 | + --mount=type=cache,target=/var/cache/apt \ |
| 53 | + apt-get update \ |
| 54 | + && apt-get install --no-install-recommends -y /mnt/pwsh/powershell.deb \ |
| 55 | + && apt-get install --no-install-recommends -y \ |
| 56 | + # less is required for help in powershell |
| 57 | + less \ |
| 58 | + # requied to setup the locale |
| 59 | + locales \ |
| 60 | + # required for SSL |
| 61 | + ca-certificates \ |
| 62 | + gss-ntlmssp \ |
| 63 | + libicu74 \ |
| 64 | + libssl3 \ |
| 65 | + libc6 \ |
| 66 | + libgcc1 \ |
| 67 | + libgssapi-krb5-2 \ |
| 68 | + liblttng-ust1 \ |
| 69 | + libstdc++6 \ |
| 70 | + zlib1g \ |
| 71 | + # PowerShell remoting over SSH dependencies |
| 72 | + openssh-client \ |
| 73 | + && apt-get dist-upgrade -y \ |
| 74 | + && locale-gen $LANG && update-locale \ |
| 75 | + && export POWERSHELL_TELEMETRY_OPTOUT=1 \ |
| 76 | + # Give all user execute permissions and remove write permissions for others |
| 77 | + && chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \ |
| 78 | + # Create the pwsh symbolic link that points to powershell |
| 79 | + && ln -sf ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh \ |
| 80 | + # Create the pwsh-preview symbolic link that points to powershell |
| 81 | + && ln -sf ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh-preview \ |
| 82 | + && pwsh \ |
| 83 | + -NoLogo \ |
| 84 | + -NoProfile \ |
| 85 | + -Command " \ |
| 86 | + \$ErrorActionPreference = 'Stop' ; \ |
| 87 | + \$ProgressPreference = 'SilentlyContinue' ; \ |
| 88 | + while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \ |
| 89 | + Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \ |
| 90 | + Start-Sleep -Seconds 6 ; \ |
| 91 | + }" |
| 92 | + |
| 93 | +# Use PowerShell as the default shell |
| 94 | +# Use array to avoid Docker prepending /bin/sh -c |
| 95 | +CMD [ "pwsh-preview" ] |
0 commit comments