Modifying Chocolatey and Boxstarter packages for internal use

Reference Note:  I wrote this assuming the reader has an understanding of NuGet, Chocolatey, and Boxstarter technologies (because why else would you want to build your own if you didn’t know what is was), but just in case, here are some links to check out:
http://docs.nuget.org/
https://github.com/chocolatey/chocolatey/wiki
http://boxstarter.org/WhyBoxstarter

Earlier I made a post on using Boxstarter to setup a Chocolatey repository. It’s a very useful tool for being able to publish your own set of packages. And with my MSI packaging background, I can make custom installers for licensed software with everything ready to go. But say you need to take the repository a step further and set it up inside an isolated system; to do that you’ll need to build your own installers for Chocolatey and Boxstarter that configures them to only use the internal repo.

Server Config

For starters we’ll need to add two mime types to IIS, one for ps1 files and another for msu packages. There are several ways you can get that done (WMI and appcmd come to mind), but since the web.config file that comes with the chocolatey.server package already has a mime type for nupkg files, I went ahead and added them there. Scroll down to line 32 in the file and you’ll see the nupkg entry. Add two more entries:
<mimeMap fileExtension=”.ps1″ mimeType=”text/plain”/>
<mimeMap fileExtension=”.msu” mimeType=”application/octet-stream”/>

While digging through web.config, there are a few things to make note of under the appSettings section. First is the apiKey. By default it is set to “chocolateyrocks”, but feel free to change it to anything. Or, another option is to set requireApiKey to false and not worry about it at all. The rest of the options, like packagesPath, may be worth playing with as well, but aren’t in the scope of what I’m doing here.

Chocolatey Installer

Grab a copy of https://chocolatey.org/install.ps1 and place it in wwwroot. Crack it open and make two quick changes. First look for $url at line 20 and set it to ‘http://SERVER/chocolatey.0.9.8.28.nupkg&#8217;. Next, locate where 7za.exe is downloaded at line 44 and change the server path there as well. While we’re talking about 7za.exe, grab a copy of it and place it at wwwroot.

Next up, building the custom chocolatey nupkg file. Start by copying C:\ProgramData\chocolatey\lib\chocolatey.0.9.8.28 to a working directory, I’ll use C:\Temp\chocolatey.0.9.8.28 for this write up. Get a copy of the Chocolatey nuspec file and place it at C:\Temp\chocolatey.0.9.8.28. Then open C:\Temp\chocolatey.0.9.8.28\tools\chocolateyInstall\chocolatey.config and change ‘https://chocolatey.org/api/v2/&#8217; to ‘http://SERVER/chocolatey/&#8217;.

Important note, the last / in the value must be there or package installs from the server will not work correctly. Also, if you don’t use the chocolatey.server package and instead compile your own NuGet server in Visual Studio (like I did on my first test build), the path will be ‘http://SERVER/nuget/&#8217;, instead of ‘http://SERVER/chocolatey/&#8217;. I’d rather not mention how long those two little gotchas took me to work out.

With the chocolatey.config file updated, open PowerShell, change directories to C:\Temp\chocolatey.0.9.8.28 and run the command ‘cpack’. Take the new chocolatey.0.9.8.28.nupkg and copy it to wwwroot. Chocolatey is now ready to install!

One last thing you’ll want to do before moving on to the Boxstarter packages is set your NuGet install to include the ApiKey for your server (if you didn’t turn it off). Once again, don’t forget the trailing / in the url or you won’t be able to push packages to your repository. Run the command:

nuget.exe SetApiKey chocolateyrocks -source http://SERVER/

Boxstarter Installer

Copy all the Boxstarter folders out of C:\ProgramData\chocolatey\lib and into C:\Temp.

To be honest, I’m not a fan of the current Boxstarter install path of C:\User\User\AppData\Temp\Roaming, so I went through each Boxstarter’s setup.ps1 and changed $boxstarterPath to use $env:programdata instead of $env:AppData. If you don’t care about this change, go ahead and skip it, the most important thing is the config file that must be changed in boxstarter.chocolatey.

Speaking of which, open up C:\Temp\boxstarter.chocolatey.2.4.123\tools\boxstarter.config and modify it as follows:
<ChocolateyPackage>http://SERVER/Packages</ChocolateyPackage&gt;
<ChocolateyRepo>http://SERVER/install.ps1</ChocolateyRepo&gt;
<NugetSources>http://SERVER/nuget</NugetSources&gt;

Then add a copy of boxstarter.config to C:\Temp\boxstarter.chocolatey.2.4.123\tools\Boxstarter.Chocolatey\Boxstarter.zip, overwriting the one already inside.

You can use pretty generic nuspec files in each folder and cpack them all to create the nupkg files. The only one to pay special attention to is the base Boxstarter’s nuspec file, where the dependencies must be set in a specific order.
<dependencies>
<dependency id=”BoxStarter.Common” version=”2.4.123″ />
<dependency id=”BoxStarter.WinConfig” version=”2.4.123″ />
<dependency id=”BoxStarter.Bootstrapper” version=”2.4.123″ />
<dependency id=”BoxStarter.Chocolatey” version=”2.4.123″ />
</dependencies>

As you use cpack in each directory, the last step is to push them to the repository with the following command:

cpush package_name.nupkg -source http://SERVER/

Once everything is in place, you can now to go a client and install everything.

iex ((new-object net.webclient).DownloadString('http://SERVER/install.ps1'))
cinst Boxstarter

Now granted, doing things this way means you can’t use the coolest feature of Boxstarter; Launch from the web.  However, it is still an amazing framework to help configure a system quickly.

Advertisements
This entry was posted in DevOps, Enterprise Management and tagged , , , , , . Bookmark the permalink.

One Response to Modifying Chocolatey and Boxstarter packages for internal use

  1. Pingback: Modifying Chocolatey and Boxstarter packages for internal use | Chocolatey

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s