Automatisera deployer på oåtkomliga servrar
Robin Helly, .NET-utvecklare
Shake ’n bake
Automatisera deployer på oåtkomliga servrar
Eller när shake ’n bake minskade kostnaderna för projektet
Robin Helly, .NET-utvecklare
Driftsättning
•Molnet
• Egna fysiska servrar
•Dedikerade servrar hos driftsleverantör
•Manuell deploy och autodeploy
Manuell deploy hos extern driftsleverantör
• Tidskrävande för flera parter
•Driftsättarna känner inte till koden och utvecklarna känner inte till miljön
•Mänsklig faktor
•Deployerna kan skilja sig från gång till gång
Deploy-script
•PowerShell script
•Backup och ny deploy av siten
•Körs hos och av driftsleverantören
Att göra en deploy
• .NET Site
•Visual studios ’publish’-funktion (Method: File system)
•Komprimera innehållet till en .zip-fil
• Flytta .zip-filen till samma plats som deploy-scriptet
•Kör scriptet
Hitta siten och stoppa den
Hitta siten och stoppa den
$website = Read-Host "Specify the name of the website"if((Test-Path "IIS:\Sites\$website") -and (Test-Path (Get-WebSite -name $website).physicalPath)){
$filePath = (Get-WebSite -name $website).physicalPath
Stop-WebSite $website
DeploySite $filePath
Start-WebSite $website
}
else {
Write-Host "The website does not exist (check that the spelling is correct)"
}
}
Hitta siten och stoppa den
$website = Read-Host "Specify the name of the website"if((Test-Path "IIS:\Sites\$website")
-and (Test-Path (Get-WebSite -name $website).physicalPath)){}else {
Write-Host "The website does not exist"} $filePath = (Get-WebSite -name $website).physicalPath
Stop-WebSite $website
DeploySite $filePath
Start-WebSite $website
}
Hitta siten och stoppa den
$website = Read-Host "Specify the name of the website"if((Test-Path "IIS:\Sites\$website")
-and (Test-Path (Get-WebSite -name $website).physicalPath)){}else {
Write-Host "The website does not exist"} $filePath = (Get-WebSite -name $website).physicalPath
Stop-WebSite $website
DeploySite $filePath
Start-WebSite $website
}
Hitta siten och stoppa den
$website = Read-Host "Specify the name of the website"if((Test-Path "IIS:\Sites\$website")
-and (Test-Path (Get-WebSite -name $website).physicalPath)){}else {
Write-Host "The website does not exist"} $filePath = (Get-WebSite -name $website).physicalPath
Stop-WebSite $website
DeploySite $filePath
Start-WebSite $website
}
Hitta siten och stoppa den
function SetUp(){
$website = Read-Host "Specify the name of the website"
if((Test-Path "IIS:\Sites\$website")
-and (Test-Path (Get-WebSite -name $website).physicalPath)){
$filePath = (Get-WebSite -name $website).physicalPath
}
}
Hitta siten och stoppa den
if(…){
$filePath = (Get-WebSite -name $website).physicalPath
Stop-WebSite $website
DeploySite $filePath
Start-WebSite $website
}
Hitta siten och stoppa den
if(…){
$filePath = (Get-WebSite -name $website).physicalPath
Stop-WebSite $website
DeploySite $filePath
Start-WebSite $website
}
Gör en deploy av paketet
function DeploySite($filePath){
BackUpSite $filePath
DeleteFolder $filePath
UnZip $filePath
CreateStatusFile $filePath
}
Gör en deploy av paketet
function DeploySite($filePath){
BackUpSite $filePath
DeleteFolder $filePath
UnZip $filePath
CreateStatusFile $filePath
}
Gör en deploy av paketet
function DeploySite($filePath){
BackUpSite $filePath
DeleteFolder $filePath
UnZip $filePath
CreateStatusFile $filePath
}
Gör en deploy av paketet
function DeploySite($filePath){
BackUpSite $filePath
DeleteFolder $filePath
UnZip $filePath
CreateStatusFile $filePath
}
Gör en deploy av paketet
function DeploySite($filePath){
BackUpSite $filePath
DeleteFolder $filePath
UnZip $filePath
CreateStatusFile $filePath
}
Gör en backup av siten
Gör en backup av sitenfunction BackUpSite($filePath){
$backupLocation = "$(get-location)\Backup\Site-backup"
[string]$pathToZipExe = "$(get-location)\7-Zip\7z.exe";
[Array]$arguments = "A", "-tzip", "$backupLocation.zip", $filePath;
& $pathToZipExe $arguments;
Move-Item $filePath\Logs $(get-location)
}
Gör en backup av sitenfunction BackUpSite($filePath){
$backupLocation = "$(get-location)\Backup\Site-backup"
[string]$pathToZipExe = "$(get-location)\7-Zip\7z.exe";
[Array]$arguments = "A", "-tzip", "$backupLocation.zip", $filePath;
& $pathToZipExe $arguments;
Move-Item $filePath\Logs $(get-location)
}
Gör en backup av sitenfunction BackUpSite($filePath){
$backupLocation = "$(get-location)\Backup\Site-backup"
[string]$pathToZipExe = "$(get-location)\7-Zip\7z.exe";
[Array]$arguments = "A", "-tzip", "$backupLocation.zip", $filePath;
& $pathToZipExe $arguments;
Move-Item $filePath\Logs $(get-location)
}
Gör en backup av sitenfunction BackUpSite($filePath){
$backupLocation = "$(get-location)\Backup\Site-backup"
[string]$pathToZipExe = "$(get-location)\7-Zip\7z.exe";
[Array]$arguments = "A", "-tzip", "$backupLocation.zip", $filePath;
& $pathToZipExe $arguments;
Move-Item $filePath\Logs $(get-location)
}
Gör en backup av siten
function BackUpSite($filePath){
$backupLocation = "$(get-location)\Backup\Site-backup"
[string]$pathToZipExe = "$(get-location)\7-Zip\7z.exe";
[Array]$arguments = "A", "-tzip", "$backupLocation.zip", $filePath;
& $pathToZipExe $arguments; ath\Logs $(get-location)
}
Gör en backup av siten
function BackUpSite($filePath){
$backupLocation = "$(get-location)\Backup\Site-backup"
[string]$pathToZipExe = "$(get-location)\7-Zip\7z.exe";
[Array]$arguments = "A", "-tzip", "$backupLocation.zip", $filePath;
& $pathToZipExe $arguments; $filePath\Logs $(get-location)
}
Ta bort den gamla sitenfunction DeleteFolder($filePath){
Remove-Item "$filePath\*" -Force -Recurse
}
Ta bort den gamla siten
function DeleteFolder($filePath){
Remove-Item "$filePath\*" -Force -Recurse
}
Ta bort den gamla siten
function DeleteFolder($filePath){
Remove-Item "$filePath\*" -Force -Recurse
}
Ta bort den gamla siten
function DeleteFolder($filePath){
Remove-Item "$filePath\*" -Force -Recurse
}
Deploy av den nya siten
Deploy av den nya siten
function UnZip($destination){
$shell = new-object -com shell.application
$zip = $shell.NameSpace("$(get-location)\deploy.zip")
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
Deploy av den nya siten
function UnZip($destination){
$shell = new-object -com shell.application
$zip = $shell.NameSpace("$(get-location)\deploy.zip")
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
Deploy av den nya siten
function UnZip($destination){
$shell = new-object -com shell.application
$zip = $shell.NameSpace("$(get-location)\deploy.zip")
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
Tidsstämpel på deployfunction CreateStatusFile($filePath){
New-Item $filePath\status.html -type file -force -value (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
}
Tidsstämpel på deploy
function CreateStatusFile($filePath){
New-Item $filePath\status.html -type file -force
-value (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
}
Tidsstämpel på deploy
function CreateStatusFile($filePath){
New-Item $filePath\status.html -type file -force
-value (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
}
Tidsstämpel på deploy
function CreateStatusFile($filePath){
New-Item $filePath\status.html -type file -force
-value (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
}
Demo
Varför underlättar scriptet?
Varför underlättar scriptet?
• Tidsinsparning
Varför underlättar scriptet?
• Tidsinsparning
•Garantera att deployen sker på samma sätt varje gång
Varför underlättar scriptet?
• Tidsinsparning
•Garantera att deployen sker på samma sätt varje gång
• Större kontroll över att få deployen som det var tänkt
Varför underlättar scriptet?
• Tidsinsparning
•Garantera att deployen sker på samma sätt varje gång
• Större kontroll över att få deployen som det var tänkt
•Minimera problem och konflikter
Varför underlättar scriptet?
• Tidsinsparning
•Garantera att deployen sker på samma sätt varje gång
• Större kontroll över att få deployen som det var tänkt
•Minimera problem och konflikter
•Hur gör ni med era deployer på externa servrar?
Deploy-paket
Deploy-paket Deploy-script
+
Deploy-paket Deploy-script
+Uppdaterad site
=
Tack för att ni lyssnade