Skip to content

Instantly share code, notes, and snippets.

@nellshamrell
Last active October 6, 2018 00:07
Show Gist options
  • Save nellshamrell/972280c0261846ff48e79d97774972a1 to your computer and use it in GitHub Desktop.
Save nellshamrell/972280c0261846ff48e79d97774972a1 to your computer and use it in GitHub Desktop.

Building

https://github.com/habitat-sh/habitat-aspnet-eff.git

choco install git
git clone https://github.com/habitat-sh/habitat-aspnet-eff 
(if the above errors - run 'C:\Program Files\Git\bin\git.exe' clone https://github.com/habitat-sh/habitat-aspnet-eff)
cd habitat-aspnet-eff
hab studio enter
build

Upload built artifact to Builder if desired.

Running

On Separate VMs

Create 2 Windows Server VMs - one for your database and one for your application.

Your database VM should have these ports open:

  • 3389 (rdp)
  • 9631 (tcp)
  • 9631 (udp)
  • 9638 (tcp)
  • 9638 (udp)
  • 8888 (tcp)

Your app VM should have these ports open

  • 3389 (rdp)
  • 9631 (tcp)
  • 9631 (udp)
  • 9638 (tcp)
  • 9638 (udp)
  • 8099 (tcp)

First Windows VM (SqlServer)

Open a new PowerShell Window and run (maybe need this, need to verify)

New-NetFirewallRule -DisplayName "Habitat TCP" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 9631,9638,8888
New-NetFirewallRule -DisplayName "Habitat UDP" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 9631,9638

Then run:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install habitat -y
$env:PATH += ";C:\ProgramData\chocolatey\bin"

Start the Habitat Supervisor:

hab sup run

Open up a new PowerShell Window

$env:PATH += ";C:\ProgramData\chocolatey\bin"
hab svc load core/sqlserver

This will take several minutes as it downloads and installs the .Net 2.0 runtime and SQL Server - go get some coffee.

Wait for SQL Server's post-run hook to complete. View the the output in the PowerShell window running the Supervisor and wait for this message

sqlserver.default hook[post-run]:(HK): 1> 2> 3> 4> 5> 6> Application user setup complete

Second Windows VM (App)

Open a new PowerShell Window and run (maybe need this, need to verify)

New-NetFirewallRule -DisplayName "Habitat TCP" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 9631,9638,8099
New-NetFirewallRule -DisplayName "Habitat UDP" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 9638
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install habitat -y
$env:PATH += ";C:\ProgramData\chocolatey\bin"

Start the Habitat Supervisor:

hab sup run --peer <1st Windows VM IP Address>

Open up a new PowerShell Window

$env:PATH += ";C:\ProgramData\chocolatey\bin"
hab svc load nshamrell/contosouniversity --bind database:sqlserver.default

When it is loaded, open up a new browser Window and navigate to

http://app_vm_public_ip:8099/hab_app

In Containers

Set up new AWS Windows VM with Containers

Then run:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install habitat -y
choco install googlechrome -y
$env:PATH += ";C:\ProgramData\chocolatey\bin"

Export sqlserver as a Docker image

hab pkg export docker core/sqlserver

Run it

docker run -it core/sqlserver

Find the IP address of the database container by running:

docker ps
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' DATABASE_CONTAINER_ID

Note it somewhere.

Open a new Powershell Window

$env:PATH += ";C:\ProgramData\chocolatey\bin"
hab pkg export docker nshamrell/contosouniversity
docker run -it nshamrell/contosouniversity --bind database:sqlserver.default --peer DATABASE_IP

Once it's up, open a new PowerShell Window and run this to get the ip address of the app container.

docker ps
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' APP_CONTAINER_ID

Then open a browser (separate from the VM) and navigate to

http://APP_IP:8099/hab_app

Through a Tarball

You will need 3 Windows VM - one to act as the database, one to do the export on, and one to run the app after it is extracted to a tarball

Creating the database VM

Do this the same as in the "On Separate VMs" section "First Windows VM (SqlServer)".

Doing the export

Create a Windows VM, install habitat, run hab setup, then

hab studio enter
hab pkg export tar nshamrell/ContosoUniversity

Will produce nshamrell-ContosoUniversity-0.2.0-20181005210432.tar.gz.

Copy the tarball by opening File Explorer and then Ctrl + C on the tarball file.

On the VM that will run the App

Open up File Explorer and CTRL + Z to paste the tarball file there (I put mine in C:\Users\Adminstrator)

Open up a PowerShell console and run:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install 7zip 

Go back to File explorer and find the tarball you copied onto the machine. Right click on it. Click "7zip" then "Extract Files"

In the form select C:\Users\Administrator\ to extract to, then by the checkbox fill in hab as the directory to extract as

Click "OK"

Back in a PowerShell console, start the Habitat supervisor

.\hab\hab\bin\hab.exe sup run --peer <DB VM IP Address>

Open up another PowerShell console and run:

.\hab\hab\bin\hab.exe svc load nshamrell/ContosoUniversity --bind database:sqlserver.default

Then open a browser (separate from the VM) and navigate to

http://APP_IP:8099/hab_app

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