The cached containers on a container host should be able to just be referenced with the container: method. If you reference the typical tag (e.g. :ltsc2019) it often doesn't match due to drift and you end up with an extra 5 minutes while it pulls additional layers.
I had to write this just to make sure I was using the cached layer every time, it shouldn't be this complicated, it should just be container: mcr.microsoft.com/windows/servercore@CACHED or something
jobs:
#Using a cached container saves ~5m of build time. They are a moving target though so they must be discovered
- job: GetCachedWindowsContainerHash
displayName: Get Cached Windows Container Information
pool:
vmimage: windows-2019
steps:
- checkout: none
- powershell: |
$serverCoreDigest = docker images --digests --format '{{json . }}' |
convertfrom-json |
where repository -eq 'mcr.microsoft.com/windows/servercore' |
% digest
"##vso[task.setvariable variable=serverCoreDigest;isOutput=true]$serverCoreDigest"
"$serverCoreDigest"
name: GetServerCoreDigest
- job: CachedContainer
dependsOn: GetCachedWindowsContainerHash
pool:
vmimage: windows-2019
variables:
serverCoreDigest: $[format('mcr.microsoft.com/windows/servercore@{0}',dependencies.GetCachedWindowsContainerHash.outputs['GetServerCoreDigest.serverCoreDigest']) ]
container: $[ variables['serverCoreDigest'] ]
steps:
- powershell: |
echo "hello world"
The cached containers on a container host should be able to just be referenced with the container: method. If you reference the typical tag (e.g. :ltsc2019) it often doesn't match due to drift and you end up with an extra 5 minutes while it pulls additional layers.
I had to write this just to make sure I was using the cached layer every time, it shouldn't be this complicated, it should just be
container: mcr.microsoft.com/windows/servercore@CACHED
or something