For my 2-day Docker and Kubernetes virtual classes, I use DigitalOcean as the cloud provider because it's very easy to use and I can provide my students with a $100 usage credits using a referrer link. I provide them with a list of software to install, most installable on Windows using the Chocolatey package manager but DigitalOcean does not have one so I thought I'd fix that.
I first looked at the Chocolatey documentation saying to myself, how hard can this be? Well, after a couple of hours fiddling around I quit miserably and full of shame. The problem I found is the doc is complete but it's so intimidating. It's like learning a new language by reading a dictionary. You get all the words but you don't known how to put them into sentences.
Inspired by the great Commander Peter Quincy Taggart saying "Never Give Up Never Surrender", I tried again a couple of weeks later. Turns out that once you get rid of the non necessary comments and commands stuffed into the default choco project files, it's quite simple.
You need to edit the [packagename].nuspec file and fill the metadata info:
<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd"> <metadata> <id>doctl</id> <version>1.45.0</version> <packageSourceUrl>https://github.com/digitalocean/doctl</packageSourceUrl> <owners>Guy Barrette</owners> <!-- This section is about the software itself --> <title>doctl</title> <authors>DigitalOcean</authors> <!-- projectUrl is required for the community feed --> <projectUrl>https://github.com/digitalocean/doctl</projectUrl> <copyright>2020 DigitalOcean</copyright> <licenseUrl>https://github.com/digitalocean/doctl/blob/master/LICENSE.txt</licenseUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <docsUrl>https://www.digitalocean.com/docs/apis-clis/doctl/</docsUrl> <tags>doctl digitalocean</tags> <summary>doctl is a command line interface for the DigitalOcean API</summary> <description>doctl enables you to manage your DigitalOcean resources from the command line. 64bit only.</description> </metadata> <files> <file src="tools\**" target="tools" /> </files> </package>
Next, you need to get the download link and sha256 checksum of the tool you want to install. In my case I got the info from the release section of the doctl repo in the DigitalOcean GitHub account: https://github.com/digitalocean/doctl/releases
Edit the chocolateyinstall.ps1file and at the minimum, provide these info to the correct command. In this case, since the repo provides a zipped version, I had to use the Install-ChocolateyZipPackage command to unzip the file.
$ErrorActionPreference = 'Stop'; $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $url = 'https://github.com/digitalocean/doctl/releases/download/v1.45.0/doctl-1.45.0-windows-amd64.zip' $checksum64 = '9c7231dcd36afed12c1c9404e30d820523f327d4e732b0ff6dd0908ebcfd9c83' $checksumType64= 'sha256' Install-ChocolateyZipPackage $env:ChocolateyPackageName $url $toolsDir -checksum64 $checksum64 -checksumType64 $checksumType64
At the Terminal type create the package using:
You can test it locally using:
choco install doctl -dv -s .
When done testing, provide your Chocolatey API key:
choco apikey --key [yourKey] --source https://push.chocolatey.org/
And finally, push the package:
choco push [package].nupkg --source https://push.chocolatey.org/
And now for the excruciating part, you have to wait until a human being validates your package and that can take from a few days to a few months!
Here's the link for the doctl package: https://chocolatey.org/packages/doctl
The code is on GitHub:
Next Winget? 🤔
Learn Docker and Kubernetes
Like this blog post? I also teach Docker and Kubernetes online virtual classes at Kubernetes Academy.
Kubernetes Academy offers instructor led training workshop-style on Docker containers and Kubernetes for web developers, DevOps specialists, I.T. Pros.
Courses info: LearnK8s.ca