Skip to content

Instantly share code, notes, and snippets.

@smford22
Last active August 11, 2021 01:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smford22/2d720fef51d735c2c9efcfd890afc938 to your computer and use it in GitHub Desktop.
Save smford22/2d720fef51d735c2c9efcfd890afc938 to your computer and use it in GitHub Desktop.
Local Habitat Windows Workstation for Mac OS X with Vagrant and VirtualBox

Local Habitat Windows Workstation for Mac OS X with Vagrant and VirtualBox

The following document describes how to setup a Mac OS X workstation for developing Habitat Packages for Windows using Vagrant and VirtualBox

Software Tools Prereqs:

Before you begin you should have the following tools installed on your Mac workstation:

  • Vagrant
  • VirtualBox
  • vagrant-reload plugin - Open a terminal and run the command vagrant plugin install vagrant-reload

Windows Guest Vagrant Box

In order to provision a guest Windows workstation you need to first have a Windows Vagrant box. The example Vagrantfile in this repo references a private Windows 2016 (config.vm.box = "chef/windows-server-2016-standard"). The provisioning steps should work on either Windows 2012r2 or Windows 2016, but have only been tested on Windows 2016.

Provisioning with Vagrant

The following Vagrantfile can be copied and dropped into any directory that contains your habitat/plan.ps1. The configuration will mount the directory that the Vagrantfile is in to /vagrant on the Windows guest. That means that you can write code on your Mac OSX in your editor of choice and build on the guest.

# -*- mode: ruby -*-
# vi: set ft=ruby :
$main_provisioner = <<-SCRIPT
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
C:/ProgramData/chocolatey/choco install git -y --no-progress
C:/ProgramData/chocolatey/choco install GoogleChrome -y --no-progress
C:/ProgramData/chocolatey/choco install VisualStudioCode -y --no-progress
C:/ProgramData/chocolatey/choco install cmder -y --no-progress
New-NetFirewallRule -DisplayName \"Habitat TCP\" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 9631,9638
New-NetFirewallRule -DisplayName \"Habitat UDP\" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 9638
C:/ProgramData/chocolatey/choco install habitat -y --no-progress
#C:/ProgramData/chocolatey/choco install docker-for-windows --pre -y --no-progress
#C:/ProgramData/chocolatey/choco install docker -y --no-progress
C:/ProgramData/chocolatey/choco install powershell-core -y
Install-PackageProvider -Name NuGet -Force
Install-Module -Name DockerMsftProvider -Force
Install-Package -Name docker -ProviderName DockerMsftProvider -Force
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.box = "chef/windows-server-2016-standard" # <--- UPDATE THIS WITH YOUR OWN WINDOWS VAGRANT BOX
  config.vm.provider "virtualbox" do |v|
    v.gui = false
    v.linked_clone = true
    v.memory = 1024
    v.cpus = 2
  end
  config.vm.synced_folder ".", "/vagrant"
  config.vm.provision "shell", inline: "install-windowsfeature containers"
  config.vm.provision :reload
  config.vm.provision "shell", inline: $main_provisioner
  config.vm.provision :reload
  config.vm.provision "shell", inline: "docker pull habitat-docker-registry.bintray.io/win-studio"

end

Once you have created the Vagrantfile in your working directory, open a terminal on your Mac OSX workstation and run vagrant up`. Provisioning may take up to 10 minutes.

When provisioning completes you can run vagrant rdp to RDP into the instance. I use the Microsoft Remote Desktop App from the APP store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment