In this post, we will see how to resolve How to create local cache for choco package manager
Question:I am building a windows docker image and use a package manager called choco for automating package installation. I would like to avoid downloading packages from the internet every time I modify and rebuild the dockerfile. Locally we run an Artifactory server that purpose But the package I am installing has hardcoded url value which is pointing to microsoft.com
In the package installation script here https://community.chocolatey.org/packages/visualcpp-build-tools#files
Before discovering the hardcoded Url value inside the package installation script, I tried using the –source option with choco install as described in the guide here https://jfrog.com/blog/artifactory-as-a-caching-mechanism-for-package-managers/ but I noticed that the package is still downloaded from the internet.
Best Answer:Packages on the Chocolatey Community Repository often can’t include the original binaries due to licenses and distribution rights – leading to each user downloading the file from the source URL.
However, you can manually re-create the package with the downloaded file inside – to do so, you should:
- Extract the relevant content of the nupkg file (e.g. the tools directory and nuspec file)
- Download the file specified in
URL(which is the file being downloaded repeatedly during the package installation) to the tools directory (or somewhere else within the package)
- Replace the URL in
URLwith the relative path to the downloaded file
choco pack $PathToNuspecFile(in the root of the extracted files)
- Upload the resultant nupkg file to your Artifactory instance
Alternatively, you could host the binary file on your Artifactory server and update
URLto point to that. This would have the potential benefit of not downloading the full size if you had logic in the package that would short-circuit the installation before the actual install step, e.g. if you had gigantic MSU file you only wanted to download if you needed to apply it.
Finally, one of the parts of a licensed copy of Chocolatey for Business is the Package Internalizer.
This automates the process described above, allowing you to simply call
choco download visualcpp-build-tools --internalize.
If you have better answer, please add a comment about this, thank you!