Skip to content

Commit

Permalink
build: install dotnet and powershell from images (#5245)
Browse files Browse the repository at this point in the history
Install the .NET SDK and PowerShell from their container images so that
we avoid spending time running their installers, and we can control
their updates automatically.

Close #5243
  • Loading branch information
ferrarimarco committed Feb 10, 2024
1 parent 5b5e54a commit 49320c8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 49 deletions.
29 changes: 22 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ FROM zricethezav/gitleaks:v8.18.2 as gitleaks
FROM yoheimuta/protolint:0.47.5 as protolint
FROM ghcr.io/clj-kondo/clj-kondo:2023.12.15-alpine as clj-kondo
FROM dart:3.2.6-sdk as dart
FROM mcr.microsoft.com/dotnet/sdk:8.0.101-alpine3.19 as dotnet-sdk
FROM mcr.microsoft.com/powershell:7.3-alpine-3.17 as powershell

FROM python:3.12.1-alpine3.19 as clang-format

Expand Down Expand Up @@ -106,6 +108,12 @@ SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"]
COPY scripts/install-lintr.sh scripts/install-r-package-or-fail.R /
RUN /install-lintr.sh && rm -rf /install-lintr.sh /install-r-package-or-fail.R

FROM powershell as powershell-installer

# Copy the value of the PowerShell install directory to a file so we can reuse it
# when copying PowerShell stuff in the main image
RUN echo "${PS_INSTALL_FOLDER}" > /tmp/PS_INSTALL_FOLDER

FROM python:3.12.1-alpine3.19 as base_image

LABEL com.github.actions.name="Super-Linter" \
Expand Down Expand Up @@ -432,9 +440,6 @@ FROM base_image as standard

# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH
ARG PWSH_VERSION='latest'
ARG PWSH_DIRECTORY='/usr/lib/microsoft/powershell'
ARG PSSA_VERSION='1.21.0'

ENV ARM_TTK_PSD1="/usr/lib/microsoft/arm-ttk/arm-ttk.psd1"
ENV PATH="${PATH}:/var/cache/dotnet/tools:/usr/share/dotnet"
Expand All @@ -455,14 +460,24 @@ COPY --from=dotenv-linter /dotenv-linter /usr/bin/
###################################
# Install DotNet and Dependencies #
###################################
COPY scripts/install-dotnet.sh /
RUN /install-dotnet.sh && rm -rf /install-dotnet.sh
COPY --from=dotnet-sdk /usr/share/dotnet /usr/share/dotnet
# Trigger first run experience by running arbitrary cmd
RUN dotnet help

#########################################
# Install Powershell + PSScriptAnalyzer #
#########################################
COPY scripts/install-pwsh.sh /
RUN --mount=type=secret,id=GITHUB_TOKEN /install-pwsh.sh && rm -rf /install-pwsh.sh
COPY --from=powershell-installer /tmp/PS_INSTALL_FOLDER /tmp/PS_INSTALL_FOLDER
COPY --from=powershell /opt/microsoft/powershell /opt/microsoft/powershell
# Disable Powershell telemetry
ENV POWERSHELL_TELEMETRY_OPTOUT=1
ARG PSSA_VERSION='1.21.0'
RUN PS_INSTALL_FOLDER="$(cat /tmp/PS_INSTALL_FOLDER)" \
&& echo "PS_INSTALL_FOLDER: ${PS_INSTALL_FOLDER}" \
&& ln -s "${PS_INSTALL_FOLDER}/pwsh" /usr/bin/pwsh \
&& chmod a+x,o-w "${PS_INSTALL_FOLDER}/pwsh" \
&& pwsh -c "Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force" \
&& rm -rf /tmp/PS_INSTALL_FOLDER

#############################################################
# Install Azure Resource Manager Template Toolkit (arm-ttk) #
Expand Down
8 changes: 0 additions & 8 deletions scripts/install-dotnet.sh

This file was deleted.

34 changes: 0 additions & 34 deletions scripts/install-pwsh.sh

This file was deleted.

9 changes: 9 additions & 0 deletions test/inspec/super-linter/controls/super_linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
version_file_path = "/action/linterVersions.txt"

control "super-linter-environment-variables" do
impact 1
title "Super-Linter environment variables check"
desc "Check that environment variables that Super-Linter needs are defined."

describe os_env("VERSION_FILE") do
its("content") { should eq version_file_path }
Expand All @@ -14,6 +17,12 @@
describe os_env("IMAGE") do
its("content") { should match(/^(standard|slim)$/) }
end

if (image == "standard")
describe os_env("POWERSHELL_TELEMETRY_OPTOUT") do
its("content") { should eq "1" }
end
end
end

##################################################
Expand Down

0 comments on commit 49320c8

Please sign in to comment.