FROM mcr.microsoft.com/windows/servercore:1709 AS base
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG PYTHON2_VERSION
ARG PYTHON3_VERSION
ENV NODEJS_VERSION 8.11.1
ENV DOTNETCORESDK_VERSION 2.1.402
ENV DOCKER_VERSION 17.09.0
ENV GIT_VERSION 2.18.0
ENV DESTINATION_FOLDER C:\\tools
WORKDIR /tmp
RUN $python_url = ('https://www.python.org/ftp/python/{0}/python-{0}.amd64.msi' -f $env:PYTHON2_VERSION); \
    Write-Host ('Downloading {0}...' -f $python_url); \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    (New-Object System.Net.WebClient).DownloadFile($python_url, '/tmp/python2-installer.msi'); \
    $install_folder = Join-Path -Path $env:DESTINATION_FOLDER -ChildPath 'python2'; \
    Write-Host ('Installing into {0}...' -f $install_folder); \
    Start-Process python2-installer.msi -Wait -ArgumentList @('/quiet', 'InstallAllUsers=1', 'TargetDir={0}' -f $install_folder, 'PrependPath=1', 'Shortcuts=0', 'Include_doc=0','Include_pip=1', 'Include_test=0');    
RUN $python_url = ('https://www.python.org/ftp/python/{0}/python-{0}-amd64.exe' -f $env:PYTHON3_VERSION); \
    Write-Host ('Downloading {0}...' -f $python_url); \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    (New-Object System.Net.WebClient).DownloadFile($python_url, '/tmp/python3-installer.exe'); \
    $install_folder = Join-Path -Path $env:DESTINATION_FOLDER -ChildPath 'python3'; \
    Write-Host ('Installing into {0}...' -f $install_folder); \
    Start-Process python3-installer.exe -Wait -ArgumentList @('/quiet', 'InstallAllUsers=1', 'TargetDir={0}' -f $install_folder, 'PrependPath=1', 'Shortcuts=0', 'Include_doc=0','Include_pip=1', 'Include_test=0');     
RUN $node_url = ('https://nodejs.org/dist/v{0}/node-v{0}-x64.msi' -f $env:NODEJS_VERSION); \
    Write-Host ('Downloading {0}...' -f $node_url); \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    (New-Object System.Net.WebClient).DownloadFile($node_url, '/tmp/nodejs-installer.msi'); \
    $install_folder = Join-Path -Path $env:DESTINATION_FOLDER -ChildPath 'node'; \
    Write-Host ('Installing into {0}...' -f $install_folder); \
    Start-Process nodejs-installer.msi -Wait -ArgumentList @('/quiet', '/q', 'InstallDir={0}' -f $install_folder); 
RUN $dotnetcoresdk_url = ('https://dotnetcli.blob.core.windows.net/dotnet/Sdk/{0}/dotnet-sdk-{0}-win-x64.zip' -f $env:DOTNETCORESDK_VERSION); \
    Write-Host ('Downloading {0}...' -f $dotnetcoresdk_url); \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    (New-Object System.Net.WebClient).DownloadFile($dotnetcoresdk_url, '/tmp/dotnetcoresdk.zip'); \
    $unpack_folder = Join-Path -Path $env:DESTINATION_FOLDER -ChildPath 'dotnetcoresdk'; \
    Write-Host ('Unpacking into {0}...' -f $unpack_folder); \
    Expand-Archive dotnetcoresdk.zip -DestinationPath $unpack_folder; 
RUN $docker_url = ('https://download.docker.com/win/static/stable/x86_64/docker-{0}-ce.zip'  -f $env:DOCKER_VERSION);\
    (New-Object System.Net.WebClient).DownloadFile($docker_url, '/tmp/docker.zip'); \
    $install_folder = Join-Path -Path $env:DESTINATION_FOLDER -ChildPath ''; \
    Expand-Archive -Path .\docker.zip -DestinationPath $install_folder; \
    Remove-Item ('{0}\docker\dockerd.exe' -f $env:DESTINATION_FOLDER)
RUN $git_url = ('https://github.com/git-for-windows/git/releases/download/v{0}.windows.1/MinGit-{0}-64-bit.zip' -f $env:GIT_VERSION); \
    Write-Host ('Downloading {0}...' -f $git_url); \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    (New-Object System.Net.WebClient).DownloadFile($git_url, '/tmp/git.zip'); \
    $unpack_folder = Join-Path -Path $env:DESTINATION_FOLDER -ChildPath 'git'; \
    Write-Host ('Unpacking into {0}...' -f $unpack_folder); \
    Expand-Archive .\git.zip -DestinationPath $unpack_folder;
    
FROM microsoft/nanoserver:1709
RUN mkdir c:\\tools 
COPY --from=base ["tools/", "/tools"]
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\tools\dotnetcoresdk;C:\tools\node\;C:\tools\python3;C:\tools\python3\Scripts;c:\tools\docker\;"
USER ContainerUser
RUN python -m pip install --upgrade pip
RUN pip install azure-cli cookiecutter docker-compose
RUN npm i -g iothub-explorer yo generator-azure-iot-edge-module
RUN az extension add --name azure-iot
WORKDIR /home/iotedge
COPY install-dev.bat /scripts/install-dev.bat