While Linux servers have well-established and elegant methods for deploying web applications, Windows servers aren’t quite as simple. We use a combination of rake, Chocolatey, and BitVise SSH Server. This works well because generating a Chocolatey package gives us a target-independent deployment artifact which we can choose to deploy locally (on our development machines) for debugging the deployment process or to a remote server for testing, UAT, or production.
It also works behind a corporate firewall.
Why not just use Octopus deploy? It doesn’t support configuration as code at the time of writing. I felt that while the deployment lifecycle features were interesting, they were redundant if using an appropriate git branching workflow. I look forward to revisiting Octopus in the future and I expect to adopt it once it supports configuration as code.
This is the process we’re using now:
Step 1: Begin automated build
To trigger an automated deployment to production a developer must log into our CI server and fire off the “Deploy to Prod” job for a specific project. This is the first and last step that involves human intervention. This causes our CI server to invoke a rake script in the corresponding repository.
Step 2: Build with rake
Rake invokes the appropriate build toolchains (msbuild, webpack) to produce production-ready build artifacts. Unit tests are performed against these artifacts. If any tests fail the build is cancelled.
Step 3: Create chocolatey package
If all unit tests pass, the rake script invokes
choco pack which creates a Chocolatey package in accordance with a
projectname.nuspec Chocolatey script which is also in the repository.
Step 4: Transfer Chocolatey package
Once the Chocolatey package is created, rake invokes
pscp to transfer the package to a deployment packages directory
on the production server.
pscp takes advantage of Putty’s saved sessions feature so we can specify a session name
for the production server in the build script without having to embed private keys in the repository. It looks
pscp deploy/projectname.1.0.0.nupkg projectname-production:/packages/projectname.1.0.0.nupkg
BitVise SSH Server receives the SCP request and roots all file transfers in a
D:/deployments folder on the production
Step 5: Run Chocolatey package
Finally rake installs the Chocolatey package on the production server using
plink. At this point the deployment
process is handed over to the Chocolatey scripts we’ve written. The Chocolatey scripts invoke various powershell
commands to control services, application pools, web sites, and copies the build artifacts to an IIS-accessible
directory for the project. The
plink command looks like this:
plink projectname-production choco install PROJECTNAME -y -force -source D:/deployments/packages