Top Banner
Charlie and the Chocolatey Factory Deploying your apps with Chocolatey NuGet Warner Godfrey
28

PUP: charlie and the chocolatey factory

Aug 08, 2015

Download

Technology

warnergodfrey
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PUP: charlie and the chocolatey factory

Charlie and the Chocolatey Factory

Deploying your apps with Chocolatey NuGet

Warner Godfrey

Page 2: PUP: charlie and the chocolatey factory

Disclaimer

I’m not a Windows guy.

I’m biased.

Don’t try this on a PaaS.

Page 3: PUP: charlie and the chocolatey factory

Practices

What we like

Page 4: PUP: charlie and the chocolatey factory

CI/CD Pipeline

1. Build & Test.

2. Package & Publish.

3. Deploy & Release.

Page 5: PUP: charlie and the chocolatey factory

Automate all the things!

■ Desktop focus.

■ PowerShell is pretty cool.

■ No standardised package format... yet.

■ Deployment tools.

Page 6: PUP: charlie and the chocolatey factory

“To the cloud”

■ Self-managed infrastructure.

■ Scorched earth deployments.

■ Deploy-time vs scale-time.

■ Late-binding of context.

Page 7: PUP: charlie and the chocolatey factory

Packaging

What changes together, stays together

Page 8: PUP: charlie and the chocolatey factory

Why the fuss?

■ Cohesiveness

■ Explicit dependencies

■ Automation

■ Confidence

Page 9: PUP: charlie and the chocolatey factory

Package It, then Ship It!

1. Receive an order.

2. Take assembled product off the shelf.

3. Pack it in a box with some instructions.

4. Slap an address on it.

5. Ship it!

Page 10: PUP: charlie and the chocolatey factory

But, doesn’t XYZ tool do that?

⌧ Does it have a CLI?

⌧ Can environment be specified at deploy time?

⌧ Can you declare dependencies?

⌧ Does it work without a server?

⌧ Are deployment scripts managed alongside application

code?

Page 11: PUP: charlie and the chocolatey factory

Chocolatey

Just like apt-get…

Page 12: PUP: charlie and the chocolatey factory

.nuspec

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">

<metadata>

<id>invokemsbuild</id>

<title>Invoke-MsBuild PowerShell Module</title>

<version>1.5</version>

...

</metadata>

</package>

Page 13: PUP: charlie and the chocolatey factory

.nuspec

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">

<metadata>...</metadata>

<files>

<file src="*.psm1" target="Modules\Invoke-MSBuild"/>

<file src="Install\**" target="tools"/>

</files>

</package>

Page 14: PUP: charlie and the chocolatey factory

chocolateyInstall.ps1

trap {

Write-ChocolateyFailure 'Invoke-MSBuild' $($_.Exception.Message)

Throw $_

}

...

Write-ChocolateySuccess 'Invoke-MSBuild'

Page 15: PUP: charlie and the chocolatey factory

chocolateyInstall.ps1

$params = ConvertFrom-StringData ($env:chocolateyPackageParameters -replace ';',

"`n")

$moduleRoot = $params.PSModuleDirectory

if (-not $moduleRoot) {

$moduleRoot = Join-Path $env:USERPROFILE "Documents\WindowsPowerShell\Modules"

}

$moduleTarget = Join-Path $env:chocolateyPackageFolder "Modules"

cmd /c mklink /j "$moduleRoot\Invoke-MSBuild" "$moduleTarget\Invoke-MSBuild"

Write-ChocolateySuccess 'Invoke-MSBuild'

Page 16: PUP: charlie and the chocolatey factory

choco install <package_id>

1. .nupkg file is downloaded from source.

2. .nupkg contents are extracted intoC:\ProgramData\chocolatey\lib

3. chocolateyInstall.ps1 script is executed.

4. Any .exe files contained within the package are put on the path via a batch redirect

Page 17: PUP: charlie and the chocolatey factory

Not at all like apt-get…

Not as easy as just overlaying some files and restarting a couple of services.

Install scripts get large!

How will it scale?

How do you maintain it?

Page 18: PUP: charlie and the chocolatey factory

chocolateyInstall.ps1 (with DSC)Configuration MyApi {

Import-DscResource -Module cNetworking

Import-DscResource -Module cTopShelf

Node 'localhost' {

cUrlReservation ReservePort80 {

Protocol = "http"

Hostname = "*"

Port = "80"

User = "NT AUTHORITY\Network Service"

}

cSelfHostedService Api {

Name = "My.Api"

Executable = $(Join-Path $env:chocolateyPackageFolder "lib\My.Api.exe")

AutoStart = "false"

Start = "false"

}

}

}

Page 19: PUP: charlie and the chocolatey factory

chocolateyInstall.ps1 (with DSC)

Configuration MyApi { ... }

MyApi -Force -OutputPath $env:TEMP | Out-Null

Start-DscConfiguration -Wait -Verbose -Path $env:TEMP -ErrorAction Stop

Write-ChocolateySuccess 'My Api'

Page 20: PUP: charlie and the chocolatey factory

.nuspec

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">

<metadata>

...

<dependencies>

<dependency id="seek-dsc-networking"/>

<dependency id="seek-dsc-topshelf"/>

<dependency id="logstash-forwarder"/>

</dependencies>

</metadata>

</package>

Page 21: PUP: charlie and the chocolatey factory

Bitter aftertaste

■ Chocolatey install does not play nice with proxies.

■ Package uninstall does not cascade.

■ Packages are installed globally.

■ Uses NuGet dependency resolution rules.

Page 22: PUP: charlie and the chocolatey factory

Putting it all together

Page 23: PUP: charlie and the chocolatey factory

CI Pipeline

1. Package => .nupkg file

2. Publish => Bundle saved to S3 bucket

Page 24: PUP: charlie and the chocolatey factory

Babushka packages

Deploying applications at scale-time often results in unacceptable server boot-time.

It may be necessary to create a machine image that is pre-baked and ready-to-go.

Remember: Keep it environment agnostic!

Page 25: PUP: charlie and the chocolatey factory

CD Pipeline

3. Package => AMI

4. Publish => ami.txt

5. Deploy => CloudFormation Stack

6. Release => Happy customers!

Page 26: PUP: charlie and the chocolatey factory

Same app, different context

Configuration management tools orchestrate the environment in which your app is deployed.

Application should be able to read configuration from environment variables at start-time.

It should be possible to deploy your package anywhere, even your local development environment.

Page 27: PUP: charlie and the chocolatey factory

What lies ahead?

■ One-Get

■ Chocolatey Professional

■ AWS::CloudFormation::Init

Page 28: PUP: charlie and the chocolatey factory

Thank You

[email protected]@warnergodfreyhttps://github.com/warnergodfrey/https://github.com/SEEK-Jobs/

https://www.slideshare.net/warnergodfrey/pup-charlie-and-the-chocolatey-factory