vmware / powerclicore

PowerCLI Core Dockerfile
Apache License 2.0
100 stars 47 forks source link

Support for Multi-platform images #72

Open bvoilar opened 11 months ago

bvoilar commented 11 months ago

Is your feature request related to a problem? Please describe.

It would be really helpful to provide images for multiple architectures (especially with the advent of the new apple silicon).

Unfortunately, the base image mcr.microsoft.com/powershell does not support multiple architectures by now as discussed for example in https://github.com/PowerShell/PowerShell-Docker/issues/520. However, in this discussion a workaround https://github.com/PowerShell/PowerShell-Docker/issues/520#issuecomment-983005441 is proposed that seems to work fine.

Describe the solution you'd like

Based on the aforementioned workaround the vmware/powerclicore image could be based on the mcr.microsoft.com/dotnet/runtime which supports multiple architectures. I quickly tested the solution based on this workaround by adjusting your Dockerfile accordingly and it builds fine (didn't test it yet). The difference in size is marginal (the image is huge anyways :grinning:).

Such change would also involve a change in the GitHub workflows that build and push the image(s).

My PoC for the Dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/sdk:7.0.401-bookworm-slim AS sdk
RUN dotnet tool install \
                --global \
                PowerShell

FROM mcr.microsoft.com/dotnet/runtime:7.0-bookworm-slim

LABEL authors="renoufa@vmware.com,jaker@vmware.com,dmilov@vmware.com,nklinkachev@vmware.com"

# Copy dotnet tools from base image
COPY --from=sdk /root/.dotnet/tools /bin

# Set PowerShell Gallery Repository

RUN pwsh -c 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted'

# Add Commuunity Examples
# Note: VMware.vSphere.SsoAdmin is removed and later installed from the PowerShell Gallery.

WORKDIR /root

ENV TZ=Etc/UTC
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata

RUN apt-get update && \
    apt-get install -y --no-install-recommends git dnsutils && \
    git clone https://github.com/vmware/PowerCLI-Example-Scripts.git && \
    mkdir --parents /usr/local/share/powershell/Modules && \
    mv ./PowerCLI-Example-Scripts/Modules/* /usr/local/share/powershell/Modules/ && \
    rm -rf /usr/local/share/powershell/Modules/VMware.vSphere.SsoAdmin && \
    apt-get remove -y git

# Install PowerShell Modules
## Invoke-DscResource is no longer an experimental feature starting with PSDesiredStateConfiguration version 2.0.6

RUN pwsh -c "Install-Module PSDesiredStateConfiguration -MinimumVersion 2.0.6" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name VMware.PowerCLI" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name VMware.vSphereDSC" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name VMware.CloudServices" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name VMware.vSphere.SsoAdmin" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name PowerVCF" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name PowerNSX" && \
    pwsh -c "\$ProgressPreference = \"SilentlyContinue\"; Install-Module -Name PowervRA" && \
    find / -name "net45" | xargs rm -rf

# Install VMware.DeployAutomation dependencies

RUN apt-get update && \
    apt-get install -y --no-install-recommends wget build-essential libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev && \
    cd /usr/src && \
    wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz && \
    tar xzf Python-3.7.9.tgz && \
    cd Python-3.7.9 && \
    ./configure  && \
    make && \
    make install

# Install required pip modules and set python path
RUN pip3 install six psutil lxml pyopenssl && \
    pwsh -c "Set-PowerCLIConfiguration -PythonPath /usr/local/bin/python3 -Scope AllUsers -Confirm:\$false"

I can also volunteer to create a PR if you are interested in this proposal.

Describe alternatives you've considered

No response

Additional context

No response