|
| 1 | +# Docker image file that describes an Debian image with PowerShell installed from Microsoft APT Repo |
| 2 | +ARG fromTag=buster-slim |
| 3 | +ARG imageRepo=debian |
| 4 | + |
| 5 | +FROM ${imageRepo}:${fromTag} AS installer-env |
| 6 | + |
| 7 | +# Define Args for the needed to add the package |
| 8 | +ARG PS_VERSION=6.1.0 |
| 9 | +ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-x64.tar.gz |
| 10 | +ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE} |
| 11 | +ARG PS_INSTALL_VERSION=7-preview |
| 12 | + |
| 13 | +# Download the Linux tar.gz and save it |
| 14 | +ADD ${PS_PACKAGE_URL} /tmp/linux.tar.gz |
| 15 | + |
| 16 | +# define the folder we will be installing PowerShell to |
| 17 | +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION |
| 18 | + |
| 19 | +# Create the install folder |
| 20 | +RUN mkdir -p ${PS_INSTALL_FOLDER} |
| 21 | + |
| 22 | +# Unzip the Linux tar.gz |
| 23 | +RUN tar zxf /tmp/linux.tar.gz -C ${PS_INSTALL_FOLDER} |
| 24 | + |
| 25 | +# Start a new stage so we lose all the tar.gz layers from the final image |
| 26 | +FROM ${imageRepo}:${fromTag} |
| 27 | + |
| 28 | +ARG PS_VERSION=6.2.0-preview.3 |
| 29 | +ARG PS_INSTALL_VERSION=7-preview |
| 30 | + |
| 31 | +# Copy only the files we need from the previous stage |
| 32 | +COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"] |
| 33 | + |
| 34 | +# Define Args and Env needed to create links |
| 35 | +ARG PS_INSTALL_VERSION=7-preview |
| 36 | +ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \ |
| 37 | + \ |
| 38 | + # Define ENVs for Localization/Globalization |
| 39 | + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ |
| 40 | + LC_ALL=en_US.UTF-8 \ |
| 41 | + LANG=en_US.UTF-8 \ |
| 42 | + # set a fixed location for the Module analysis cache |
| 43 | + PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache |
| 44 | + |
| 45 | +# Install dependencies and clean up |
| 46 | +RUN apt-get update \ |
| 47 | + && apt-get install -y \ |
| 48 | + # less is required for help in powershell |
| 49 | + less \ |
| 50 | + # requied to setup the locale |
| 51 | + locales \ |
| 52 | + # required for SSL |
| 53 | + ca-certificates \ |
| 54 | + gss-ntlmssp \ |
| 55 | + libicu63 \ |
| 56 | + libssl1.1 \ |
| 57 | + libc6 \ |
| 58 | + libgcc1 \ |
| 59 | + libgssapi-krb5-2 \ |
| 60 | + liblttng-ust0 \ |
| 61 | + libstdc++6 \ |
| 62 | + zlib1g \ |
| 63 | + && apt-get dist-upgrade -y \ |
| 64 | + && apt-get clean \ |
| 65 | + && rm -rf /var/lib/apt/lists/* \ |
| 66 | + # enable en_US.UTF-8 locale |
| 67 | + && sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen \ |
| 68 | + # generate locale |
| 69 | + && locale-gen && update-locale |
| 70 | + |
| 71 | + # Give all user execute permissions and remove write permissions for others |
| 72 | +RUN chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \ |
| 73 | + # Create the pwsh symbolic link that points to powershell |
| 74 | + && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/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 VCS_REF="none" |
| 89 | +ARG IMAGE_NAME=mcr.microsoft.com/powershell:debian-10 |
| 90 | + |
| 91 | +LABEL maintainer="PowerShell Team <powershellteam@hotmail.com>" \ |
| 92 | + readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ |
| 93 | + description="This Dockerfile will install the latest release of PowerShell." \ |
| 94 | + org.label-schema.usage="https://github.com/PowerShell/PowerShell/tree/master/docker#run-the-docker-image-you-built" \ |
| 95 | + org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" \ |
| 96 | + org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell-Docker" \ |
| 97 | + org.label-schema.name="powershell" \ |
| 98 | + org.label-schema.vendor="PowerShell" \ |
| 99 | + org.label-schema.version=${PS_VERSION} \ |
| 100 | + org.label-schema.schema-version="1.0" \ |
| 101 | + org.label-schema.vcs-ref=${VCS_REF} \ |
| 102 | + org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" \ |
| 103 | + org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" \ |
| 104 | + org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" \ |
| 105 | + org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" |
| 106 | + |
| 107 | +# Use PowerShell as the default shell |
| 108 | +# Use array to avoid Docker prepending /bin/sh -c |
| 109 | +CMD [ "pwsh" ] |
0 commit comments