From 3496268e7733be07b4637f00121ca70fbb8a978e Mon Sep 17 00:00:00 2001 From: Suraj Deshmukh Date: Mon, 28 Oct 2024 16:55:10 -0700 Subject: [PATCH] Dockerfiles: Install az cli and powershell in base and tools image - Tools image overrides, az cli and the powershell installation. - The install steps check if there is any difference between installed and the downloaded az cli version. If there is a difference the downloaded az cli is installed, powershell is also installed as a part of that step. Signed-off-by: Suraj Deshmukh --- linux/base.Dockerfile | 24 +++++++++++----- linux/tools.Dockerfile | 64 ++++++++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/linux/base.Dockerfile b/linux/base.Dockerfile index f1022e6..4f30125 100644 --- a/linux/base.Dockerfile +++ b/linux/base.Dockerfile @@ -243,18 +243,26 @@ ENV PATH=~/.local/bin:~/bin:~/.dotnet/tools:$PATH \ POWERSHELL_DISTRIBUTION_CHANNEL=CloudShell \ POWERSHELL_UPDATECHECK=Off +# ------------------------------ Tools Dockerfile ------------------------------ # Copy and run script to install Powershell modules and setup Powershell machine # profile COPY ./linux/powershell/ powershell -RUN tdnf clean all && \ +# Install latest Azure CLI package. CLI team drops latest (pre-release) package +# here prior to public release We don't support using this location elsewhere - +# it may be removed or updated without notice. +RUN INSTALLED_VERSION=$(az version --output json 2>/dev/null | jq -r '."azure-cli"') && \ + wget https://azurecliprod.blob.core.windows.net/cloudshell-release/azure-cli-latest-mariner2.0.rpm && \ + # Get the version of the downloaded Azure CLI + DOWNLOADED_VERSION=$(rpm --queryformat="%{VERSION}" -qp ./azure-cli-latest-mariner2.0.rpm) && \ + # + # If the installed Azure CLI and the downloaded Azure CLI are different, then + # install the downloaded Azure CLI. + if [ "$DOWNLOADED_VERSION" != "$INSTALLED_VERSION" ]; then \ + tdnf clean all && \ tdnf repolist --refresh && \ ACCEPT_EULA=Y tdnf update -y && \ - # Install latest Azure CLI package. CLI team drops latest (pre-release) package here prior to public release - # We don't support using this location elsewhere - it may be removed or updated without notice - wget https://azurecliprod.blob.core.windows.net/cloudshell-release/azure-cli-latest-mariner2.0.rpm \ - && tdnf install -y ./azure-cli-latest-mariner2.0.rpm \ - && rm azure-cli-latest-mariner2.0.rpm && \ + tdnf install -y ./azure-cli-latest-mariner2.0.rpm && \ tdnf clean all && \ rm -rf /var/cache/tdnf/* && \ # @@ -272,5 +280,7 @@ RUN tdnf clean all && \ /usr/bin/pwsh -File ./powershell/setupPowerShell.ps1 -image Top && \ # Install Powershell warmup script mkdir -p linux/powershell && \ - cp powershell/Invoke-PreparePowerShell.ps1 linux/powershell/Invoke-PreparePowerShell.ps1 && \ + cp powershell/Invoke-PreparePowerShell.ps1 linux/powershell/Invoke-PreparePowerShell.ps1; \ + fi && \ + rm azure-cli-latest-mariner2.0.rpm && \ rm -rf ./powershell diff --git a/linux/tools.Dockerfile b/linux/tools.Dockerfile index 770242a..a6896a9 100644 --- a/linux/tools.Dockerfile +++ b/linux/tools.Dockerfile @@ -10,34 +10,44 @@ FROM ${IMAGE_LOCATION} LABEL org.opencontainers.image.source="https://github.com/Azure/CloudShell" +# ---------------------- Installation same as base image ---------------------- # Copy and run script to install Powershell modules and setup Powershell machine # profile COPY ./linux/powershell/ powershell -RUN tdnf clean all && \ - tdnf repolist --refresh && \ - ACCEPT_EULA=Y tdnf update -y && \ - # Install latest Azure CLI package. CLI team drops latest (pre-release) package here prior to public release - # We don't support using this location elsewhere - it may be removed or updated without notice - wget https://azurecliprod.blob.core.windows.net/cloudshell-release/azure-cli-latest-mariner2.0.rpm \ - && tdnf install -y ./azure-cli-latest-mariner2.0.rpm \ - && rm azure-cli-latest-mariner2.0.rpm && \ - tdnf clean all && \ - rm -rf /var/cache/tdnf/* && \ - # - # Install any Azure CLI extensions that should be included by default. - az extension add --system --name ai-examples -y && \ - az extension add --system --name ssh -y && \ - az extension add --system --name ml -y && \ - # - # Install kubectl - az aks install-cli && \ - # - # Powershell installation and setup - /usr/bin/pwsh -File ./powershell/setupPowerShell.ps1 -image Base && \ - cp -r ./powershell/PSCloudShellUtility /usr/local/share/powershell/Modules/PSCloudShellUtility/ && \ - /usr/bin/pwsh -File ./powershell/setupPowerShell.ps1 -image Top && \ - # Install Powershell warmup script - mkdir -p linux/powershell && \ - cp powershell/Invoke-PreparePowerShell.ps1 linux/powershell/Invoke-PreparePowerShell.ps1 && \ - rm -rf ./powershell +# Install latest Azure CLI package. CLI team drops latest (pre-release) package +# here prior to public release We don't support using this location elsewhere - +# it may be removed or updated without notice. +RUN INSTALLED_VERSION=$(az version --output json 2>/dev/null | jq -r '."azure-cli"') && \ + wget https://azurecliprod.blob.core.windows.net/cloudshell-release/azure-cli-latest-mariner2.0.rpm && \ + # Get the version of the downloaded Azure CLI + DOWNLOADED_VERSION=$(rpm --queryformat="%{VERSION}" -qp ./azure-cli-latest-mariner2.0.rpm) && \ + # + # If the installed Azure CLI and the downloaded Azure CLI are different, then + # install the downloaded Azure CLI. + if [ "$DOWNLOADED_VERSION" != "$INSTALLED_VERSION" ]; then \ + tdnf clean all && \ + tdnf repolist --refresh && \ + ACCEPT_EULA=Y tdnf update -y && \ + tdnf install -y ./azure-cli-latest-mariner2.0.rpm && \ + tdnf clean all && \ + rm -rf /var/cache/tdnf/* && \ + # + # Install any Azure CLI extensions that should be included by default. + az extension add --system --name ai-examples -y && \ + az extension add --system --name ssh -y && \ + az extension add --system --name ml -y && \ + # + # Install kubectl + az aks install-cli && \ + # + # Powershell installation and setup + /usr/bin/pwsh -File ./powershell/setupPowerShell.ps1 -image Base && \ + cp -r ./powershell/PSCloudShellUtility /usr/local/share/powershell/Modules/PSCloudShellUtility/ && \ + /usr/bin/pwsh -File ./powershell/setupPowerShell.ps1 -image Top && \ + # Install Powershell warmup script + mkdir -p linux/powershell && \ + cp powershell/Invoke-PreparePowerShell.ps1 linux/powershell/Invoke-PreparePowerShell.ps1; \ + fi && \ + rm azure-cli-latest-mariner2.0.rpm && \ + rm -rf ./powershell