automating the software deployment lifecycle · paul broadwith @pauby automating the software...

32
Paul Broadwith @pauby https://blog.pauby.com Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Upload: others

Post on 20-May-2020

8 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Paul Broadwith@pauby

https://blog.pauby.com

Automating the Software Deployment Lifecyclewith Chocolatey, Jenkins and PowerShell

Page 2: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

• Paul Broadwith, Glasgow, Scotland

• 25+ years in defence, government, financial sectors

• Lead Engineer on Boxstarter and Chocolatey cChoco DSC Resource

Who Am I?

2@pauby

Page 3: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

3@pauby

Page 4: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Agenda

• What is Chocolatey?

• Chocolatey Sources;

• Internalizing packages;

• Recommended Organizational Architecture;

• Common scenarios where Chocolatey automation will help you;

• Based on a blog posthttps://blog.pauby.com/post/getting-started-with-chocolatey-and-jenkins/

4@pauby

Page 5: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Before We Start!

@pauby 5

C4B

Page 6: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 6

What Is Chocolatey?

Page 7: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

A Definition Of Chocolatey

Chocolatey is a package manager for Windows, like

apt-get or yum but for Windows. It was designed to

be a decentralized framework for quickly installing

applications and tools that you need. It is built on

the NuGet infrastructure currently using PowerShell

as its focus for delivering packages from the distros

to your door, err computer.

@pauby 7

Page 8: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 8

Page 9: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Chocolatey manages Packages

Packages manage Installers

@pauby 9

Page 10: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 10

Chocolatey Package SourcesWhere do packages come from?

Page 11: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Chocolatey Sources

• Where packages come from;

• C4B comes with two Chocolatey sources by default:• chocolatey – Chocolatey Community Repository• Chocolatey.licensed - Chocolatey Community Repository

cached binaries;

• Add your own sources:• Repository manager: Artifactory, Nexus, ProGet• Local folder

@pauby 11

Page 12: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 12

Demo 1Chocolatey Sources.

Page 13: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 13

Internalizing PackagesKeeping it in the family.

Page 14: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Why Internalize Packages?

• What is ‘package internalization’?

• Organizations recommended to disable the default sources.• Reliability• Trust• Bandwidth• Copyright Restrictions

• Using the default chocolatey source is subject to:• rate limiting;• excessive download limiting;

@pauby 14

Page 15: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

C4B Package Internalizer

• Automatically internalizes the vast majority of packages;

• Very fast;

• Don’t reinvent the wheel;

• Automation!

@pauby 15

Page 16: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 16

Demo 2Package Internalization.

Page 17: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 17

Organizational ArchitectureEvery organisation is a snowflake.(shield your eyes!)

Page 18: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 18

Page 19: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 19

InternalizationTestingProduction

Page 20: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Tools We Need.

@pauby 20

Package Repositories - Chocolatey.Server

Code - PowerShell

Automation - Jenkins

Recommended: Artifactory, Nexus, ProGet

Page 21: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 21

Demo 3Lets look at the Jenkins jobs.

Page 22: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 22

# Jenkins - Internalize Package and Push to Test Repo

$temp = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid()).GuidNew-Item -Path $temp -ItemType Directory | Out-NullWrite-Output "Created temporary directory '$temp'."

Set-Location (Join-Path -Path $env:SystemDrive -ChildPath 'scripts') .\Internalize-ChocoPackage.ps1 -Name $env:P_PKG_LIST `

-OutputDirectory $temp -Verbose

if ($LASTEXITCODE -eq 0) {Set-Location $tempGet-ChildItem -Path *.nupkg | ForEach-Object {

choco push $_.Name --source=$env:G_TEST_REPO `--apikey=$env:G_API_KEY --limitoutput

}}

Page 23: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 23

# Jenkins - Test Package and Push to Prod Repo

Set-Location (Join-Path -Path $env:SystemDrive -ChildPath 'scripts').\Update-ProdRepoFromTest.ps1 `

-ProdRepo $env:G_PROD_REPO `-ProdRepoApiKey $env:G_API_KEY `-TestRepo $env:G_TEST_REPO `-Verbose

Page 24: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 24

# Jenkins - Upgrade Outdated Packages in Test Repository

Set-Location (Join-Path -Path $env:SystemDrive -ChildPath 'scripts').\Get-UpdatedPackage.ps1 -LocalRepo $env:P_LOCAL_REPO_URL `

-LocalRepoApiKey $env:P_LOCAL_REPO_API_KEY `-RemoteRepo $env:P_REMOTE_REPO_URL `-Verbose

Page 25: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Jenkins Configuration

@pauby 25@pauby

Chocolatey Community Repository

Binary / Installer

Downloads

Internalize Package and Push

to Test Repo

Test Repository

Production Repository

Test Environment

(*maybe)

Production Environment

Test Package

and Push to

Prod Repo

Page 26: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 27

Common ScenariosYou helping Chocolatey help you.

Page 27: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 28

Demo 4Jenkins PowerShell Scripts and Common Scenarios

Page 28: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 31

Suggested Improvements.Ideas to extend and customise.

Page 29: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Suggested Improvements

• Schedule Updating Packages from Chocolatey Community Repository;

• Write your own Pester Tests that your organization needs;

• When packages are published to production send a message via email / Slack / Teams or whatever you use;

@pauby 32

Page 30: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Summary

• What Chocolatey is and how sources work;

• Understand package internalization and why it’s important for organizations;

• How to apply automation to Chocolatey package testing and deployment;

@pauby 33

Page 31: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

@pauby 34

Questions?

Page 32: Automating the Software Deployment Lifecycle · Paul Broadwith @pauby  Automating the Software Deployment Lifecycle with Chocolatey, Jenkins and PowerShell

Thank You!

linkedin.pauby.com

pau.by/talksPaul Broadwith

pauby.com

@pauby

github.com/pauby

@pauby 35