From 8a3a23131da8e8795c417690f7353f3c173b9238 Mon Sep 17 00:00:00 2001 From: Andrea Spadaccini Date: Thu, 7 Jul 2022 14:58:40 +0200 Subject: [PATCH] feat(test): improve test Dockerfile Install cURL if needed, and use a multi-stage build to have a cleaner image. --- test/Dockerfile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/Dockerfile b/test/Dockerfile index 8ba3278..14b9606 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,7 +1,8 @@ +# syntax=docker/dockerfile:1 # Dockerfile to test the library with multiple versions of PowerShell >= 7. # # Example run (from repo root): -# > $version="7.1.5"; docker build -f .\test\docker\Dockerfile . -t powershell-featureflags-test:$version --build-arg VERSION=$version --build-arg UBUNTU_VERSION=18.04 && docker run powershell-featureflags-test:$version +# PS > $version="7.1.5"; docker build -f .\test\docker\Dockerfile . -t powershell-featureflags-test:$version --build-arg VERSION=$version --build-arg UBUNTU_VERSION=18.04 && docker run powershell-featureflags-test:$version ARG VERSION=7.2.5 ARG UBUNTU_VERSION=16.04 @@ -11,16 +12,20 @@ FROM mcr.microsoft.com/powershell:${VERSION}-ubuntu-${UBUNTU_VERSION} # # Not using the dotnet SDK images because they bring their own powershell, # see for example https://github.com/dotnet/dotnet-docker/blob/main/src/sdk/6.0/focal/amd64/Dockerfile. +# For some reason, docker images for Powershell 6 don't have curl. ENV DOTNET_SDK_VERSION=6.0.301 -RUN curl -fSL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-sdk-$DOTNET_SDK_VERSION-linux-x64.tar.gz -RUN mkdir -p /usr/share/dotnet -RUN tar -oxzf dotnet.tar.gz -C /usr/share/dotnet -RUN rm dotnet.tar.gz -RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet +RUN if ! command -v curl &> /dev/null; then apt-get update; apt-get install -y curl; fi \ + && curl -fSL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-sdk-$DOTNET_SDK_VERSION-linux-x64.tar.gz \ + && mkdir -p /usr/share/dotnet \ + && tar -oxzf dotnet.tar.gz -C /usr/share/dotnet +FROM mcr.microsoft.com/powershell:${VERSION}-ubuntu-${UBUNTU_VERSION} +# Copy the dotnet installation. +COPY --from=0 /usr/share/dotnet /usr/share/dotnet +RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet # Copy the application code. WORKDIR /app COPY . . # Restore dependencies and run tests. -CMD pwsh tools/restore.ps1; pwsh tools/run-tests.ps1 \ No newline at end of file +CMD pwsh tools/restore.ps1; pwsh tools/run-tests.ps1