microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.21k stars 934 forks source link

Request: Shorthand for Cached Containers #472

Closed JustinGrote closed 4 years ago

JustinGrote commented 4 years ago

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"
vtbassmatt commented 4 years ago

In order to consolidate to fewer feedback channels, we've moved suggestions and issue reporting to Developer Community. Sorry for the delay/confusion.