0

TLDR;

I have an Azure Devops Pipeline that uses chocolatey to install dependencies. I would like to cache downloaded chocolatey packages similar to how node dependencies are cached (see below) or use a caching proxy server.

  1. Is it possible to cache downloaded packages from chocolatey to be available at the next run?

  2. If that is not currently easily possible, then is it possible to run a caching proxy server similar to AptCacherNg for chocolatey packages?

Current Setup

I currently have a pipeline setup in Azure Devops that requires packages from chocolatey community. The step runs the equivalent of:

choco install nasm --confirm --no-progress

enter image description here

I am caching node dependencies using the following:

steps:
- task: Cache@2
  displayName: 'Cache npm packages'
  inputs:
    key: '**/package-lock.json, !**/node_modules/**/package-lock.json, !**/.*/**/package-lock.json'
    path: '$(System.DefaultWorkingDirectory)/node_modules'

I have considered whether it was possible to modify the keys for this to check the choco packages or use a duplicate step that uses this plugin but I don't know specifically how to do this.

Backgound

Recently, one of the modules website went offline for a few hours. While it was offline I noticed that in the logs it stated that licensed users likely didn't have the issue as they cache packages. I checked into license pricing and it seems that there is a reasonable $96/year cost for a single user license of up to 8 machines but in the license it states that using this would violate the terms for business usage. The business license is $16/year/machine with a minimum of 100 machines. $1600/year is a bit more than I want to pay at this time for such a small dev team that only needs a few packages installed. They suggested community edition.

pcnate
  • 1,694
  • 1
  • 18
  • 34

1 Answers1

1

Choco has a handy --cache option that lets you specify the cache location. Use this option together with a dedicated Cache step:

- task: Cache@2
  displayName: 'Cache choco'
  inputs:
    key: 'path_to_a_file_or_just_a_string_that_you_update_manually'
    path: '$(System.DefaultWorkingDirectory)/choco_cache'
- script: choco install nasm --confirm --no-progress --cache $(System.DefaultWorkingDirectory)/choco_cache
  displayName: 'install choco packages'
qbik
  • 5,502
  • 2
  • 27
  • 33
  • I know about the choco cache option, should have added it to my question but one of the things that gets me hung up on how to use the cache task is: *What should the value of key really be?* – pcnate Jun 16 '21 at 17:28
  • I see two options there: 1. You put an arbitrary string as the key (i.e. 'version1') and change that string manually each time you want to invalidate the cache. 2. You put the list if packages in [packages.config](https://docs.chocolatey.org/en-us/choco/commands/install#packages.config) and that file becomes the key. This way, if you want to add another package or update version, you only change packages.config. – qbik Jun 17 '21 at 04:15