You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a slimmer docker image on windows. I would prefer windows as I can build for android, iOS, windows, macos (not maui I know), and maccatalyst. The problem is the only success I have had is to download the Visual Studio Build Tools and install all the necessary packages. Docker file looks like this:
# escape=`
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
ARG dockerHost=mcr.microsoft.com
ARG WindowsServerCoreRepo=windows/servercore
ARG tag=ltsc2022
# Use server core as an installer container to extract PowerShell,
# As this is a multi-stage build, this stage will eventually be thrown away
FROM mcr.microsoft.com/${WindowsServerCoreRepo}:${tag} AS installer-env
ARG PS_VERSION=6.2.0
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/PowerShell-${PS_VERSION}-win-x64.zip
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
ARG PS_PACKAGE_URL_BASE64
RUN Write-host "Verifying valid Version..."; `
if (!($env:PS_VERSION -match '^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$' )) { `
throw ('PS_Version ({0}) must match the regex "^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$"' -f $env:PS_VERSION) `
} `
$ProgressPreference = 'SilentlyContinue'; `
if($env:PS_PACKAGE_URL_BASE64){ `
Write-host "decoding: $env:PS_PACKAGE_URL_BASE64" ;`
$url = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($env:PS_PACKAGE_URL_BASE64)) `
} else { `
Write-host "using url: $env:PS_PACKAGE_URL" ;`
$url = $env:PS_PACKAGE_URL `
} `
Write-host "downloading: $url"; `
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; `
Invoke-WebRequest -Uri $url -outfile /powershell.zip -verbose; `
Expand-Archive powershell.zip -DestinationPath \PowerShell
# Install PowerShell into WindowsServerCore
FROM mcr.microsoft.com/${WindowsServerCoreRepo}:${tag}
# Copy PowerShell Core from the installer container
ENV ProgramFiles="C:\Program Files" `
# set a fixed location for the Module analysis cache
PSModuleAnalysisCachePath="C:\Users\Public\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache" `
# Persist %PSCORE% ENV variable for user convenience
PSCORE="$ProgramFiles\PowerShell\pwsh.exe" `
POWERSHELL_DISTRIBUTION_CHANNEL="PSDocker-WindowsServerCore-ltsc2022" `
POWERSHELL_TELEMETRY_OPTOUT="1"
# Copy PowerShell Core from the installer container
COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell\\latest"]
# Set the path
RUN setx /M PATH "%ProgramFiles%\PowerShell\latest;%PATH%;"
# intialize powershell module cache
RUN pwsh `
-NoLogo `
-NoProfile `
-Command " `
$stopTime = (get-date).AddMinutes(15); `
$ErrorActionPreference = 'Stop' ; `
$ProgressPreference = 'SilentlyContinue' ; `
while(!(Test-Path -Path $env:PSModuleAnalysisCachePath)) { `
Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; `
if((get-date) -gt $stopTime) { throw 'timout expired'} `
Start-Sleep -Seconds 6 ; `
}"
# re-enable telemetry
ENV POWERSHELL_TELEMETRY_OPTOUT="0"
CMD ["pwsh.exe"]
# Use the latest Windows Server Core 2022 image.
# FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
# Download the Build Tools bootstrapper.
RUN curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_buildtools.exe && `
# Install Build Tools
(start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
--add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools `
--add Microsoft.VisualStudio.Workload.MSBuildTools `
--add Microsoft.VisualStudio.Workload.XamarinBuildTools `
--add Component.Android.SDK.MAUI `
--add macos `
--add Microsoft.VisualStudio.Component.Windows10SDK.18362 `
--remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
--remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
--remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
--remove Microsoft.VisualStudio.Component.Windows81SDK `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0) && `
`
# Cleanup
del /q vs_buildtools.exe
# Install Workloads
# RUN dotnet workload install maui android ios macos maccatalyst # (oops, on my last build I forgot to uncomment this... Oh well, it still worked...)
And this TECHNICALLY works, but the problem is it comes in at 27GB, and anytime I want to update, it takes hours. I have attempted a slimmer version, by using the official dotnet images, but I can't figure out a way to install the android sdk in a way dotnet will find it; I keep getting "Android SDK not found" errors no matter where I put it.
I have seen successful Linux docker images for Android, but I wish to stick with windows so that can compile my nuget project with just the "dotnet pack" command; as far as I can tell, windows is the only platform this will work on.
And I can't use Github actions as I'm using a local Gitlab server.
Most annoyingly, I can't just run this directly on the build machine because the path length becomes too long for android >:(.
Any plan for an official MAUI docker image? and if not, has anybody successfully made a slightly slimmer docker image for MAUI on windows that can compile android?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to create a slimmer docker image on windows. I would prefer windows as I can build for android, iOS, windows, macos (not maui I know), and maccatalyst. The problem is the only success I have had is to download the Visual Studio Build Tools and install all the necessary packages. Docker file looks like this:
And this TECHNICALLY works, but the problem is it comes in at 27GB, and anytime I want to update, it takes hours. I have attempted a slimmer version, by using the official dotnet images, but I can't figure out a way to install the android sdk in a way dotnet will find it; I keep getting "Android SDK not found" errors no matter where I put it.
I have seen successful Linux docker images for Android, but I wish to stick with windows so that can compile my nuget project with just the "dotnet pack" command; as far as I can tell, windows is the only platform this will work on.
And I can't use Github actions as I'm using a local Gitlab server.
Most annoyingly, I can't just run this directly on the build machine because the path length becomes too long for android >:(.
Any plan for an official MAUI docker image? and if not, has anybody successfully made a slightly slimmer docker image for MAUI on windows that can compile android?
Beta Was this translation helpful? Give feedback.
All reactions