Skip to content

Commit

Permalink
Windows packaging changes (#962)
Browse files Browse the repository at this point in the history
* Enable Windows CAB packages (#807)

The installer script now installs a CAB package containing the IoT Edge daemon,
the Moby engine, and the Moby CLI.

Install-SecurityDaemon and Uninstall-SecurityDaemon have been renamed to
Install-IoTEdge and Uninstall-IoTEdge respectively. The original names have
been kept as aliases for backward-compatibility.

There are also three new commands - Deploy-IoTEdge, Initialize-IoTEdge and
Update-IoTEdge. Deploy-IoTEdge installs the CAB and Initialize-IoTEdge
generates the config.yaml. Install-IoTEdge just calls Deploy and Initialize
in sequence. Update-IoTEdge updates the CAB; there is no longer a need to
uninstall and reinstall to update the daemon.

The -DeleteMobyDataRoot and -DeleteConfig switches have been removed from\
Uninstall-IoTEdge since they only existed to maintain the container images
and config.yaml in update scenarios. Since Uninstall is no longer needed for
update scenarios, it will always delete the Moby data root and config.yaml

The Moby engine service is now always installed and started, even when
using Linux containers. Since it listens on a different named pipe, it will
not interfere with an existing Docker for Windows install.

* Fix homedir in config.yaml generated by Windows installer (#890)

* Cleanup logging (#889)

* Cleanup logging

* Don't let `takeown` block on a user prompt (#910)

`takeown` prompts the user to allow it to take ownership of a directory
if the user does not have the "List" permission for it. If this prompt
happens during the uninstaller, it blocks the uninstaller with no
indication that the user needs to press Y to continue.

With this change, the `/d y` switch is used to answer Y to the prompt
automatically.

This is likely the reason for issues like #793

* Fix of image auth regex (#913)

On a run of the E2E tests it was observed that the existing regex matched a comment containing the word 'auth' and the replace was consequently broken. This fix attempts to search for the auth under the agent section.

* Cleanup packaging to make it more suitable for the release job (#892)

* Cleanup packaging to make it more suitable for the release job

* Catch download failures properly

* Enable resigning of the package catalog
  • Loading branch information
jiria authored Mar 18, 2019
1 parent b902e8e commit ce232a8
Show file tree
Hide file tree
Showing 7 changed files with 1,278 additions and 616 deletions.
51 changes: 28 additions & 23 deletions builds/misc/packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trigger:
pr: none
variables:
REVISION: '1'
WINDOWS_CODESIGN_SERVICE_CONNECTION: 'Azure IoT Edge Code Sign 2'
jobs:

################################################################################
Expand Down Expand Up @@ -204,7 +205,7 @@ jobs:
steps:
- powershell: |
$base_version = Get-Content -Path "$(Build.SourcesDirectory)\edgelet\version.txt"
$version = "$base_version$(Build.BuildNumber)"
$version = ("{0}{1}" -f $base_version, $(Build.BuildNumber))
Write-Host ("##vso[task.setvariable variable=VERSION;]$version")
Write-Host ("##vso[task.setvariable variable=NO_VALGRIND;]true")
displayName: Set Version
Expand All @@ -222,33 +223,37 @@ jobs:
inputs:
workingDirectory: 'edgelet/hsm-sys/azure-iot-hsm-c/build'
cmakeArgs: '--build . --config Release'
- powershell: edgelet/build/windows/package.ps1 -CreateTemplate
displayName: Prepare package template
# - task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
# displayName: 'ESRP Package Catalog CodeSigning Internal'
# inputs:
# ConnectedServiceName: '$(WINDOWS_CODESIGN_SERVICE_CONNECTION)'
# FolderPath: '$(build.SourcesDirectory)'
# Pattern: 'Package-Template/update.cat'
# CertificateId: 302
# OpusName: 'Azure IoT Edge'
# OpusInfo: 'https://azure.microsoft.com/en-us/services/iot-edge/'
# SessionTimeout: 20
- powershell: edgelet/build/windows/package.ps1 -CreateCab
displayName: Generate CAB package
- task: CopyFiles@2
displayName: 'Copy iotedged to Artifact Staging'
displayName: 'Copy package to Artifact Staging'
inputs:
SourceFolder: edgelet/target/release
SourceFolder: .
Contents: |
*.exe
*.pdb
*.dll
*.cab
TargetFolder: '$(build.artifactstagingdirectory)'
- task: CopyFiles@2
displayName: 'Copy libiothsm to Artifact Staging'
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
displayName: 'ESRP Package CodeSigning Internal'
inputs:
SourceFolder: 'edgelet/hsm-sys/azure-iot-hsm-c/build/Release'
Contents: |
*.dll
*.pdb
TargetFolder: '$(build.artifactstagingdirectory)'
- task: CopyFiles@2
displayName: 'Copy legal docs to Artifact Staging'
inputs:
SourceFolder: edgelet/contrib/docs
TargetFolder: '$(build.artifactstagingdirectory)/LICENSE'
- task: CopyFiles@2
displayName: 'Copy config to Artifact Staging'
inputs:
SourceFolder: edgelet/contrib/config/windows
TargetFolder: '$(build.artifactstagingdirectory)'
ConnectedServiceName: '$(WINDOWS_CODESIGN_SERVICE_CONNECTION)'
FolderPath: '$(build.artifactstagingdirectory)'
Pattern: '*.cab'
CertificateId: 302
OpusName: 'Azure IoT Edge'
OpusInfo: 'https://azure.microsoft.com/en-us/services/iot-edge/'
SessionTimeout: 20
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: iotedged-windows'
inputs:
Expand Down
75 changes: 75 additions & 0 deletions edgelet/build/windows/iotedge.wm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<identity
xmlns="urn:Microsoft.CompPlat/ManifestSchema.v1.00"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="IoTEdge"
namespace="Azure"
owner="Microsoft"
>
<files>
<file source="$(_REPO_ROOT)\edgelet\contrib\config\windows\config.yaml" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_REPO_ROOT)\edgelet\target\release\iotedge.exe" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_REPO_ROOT)\edgelet\target\release\iotedged.exe" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_REPO_ROOT)\edgelet\target\release\iotedged.pdb" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_REPO_ROOT)\edgelet\target\release\iotedged_eventlog_messages.dll" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_REPO_ROOT)\edgelet\hsm-sys\azure-iot-hsm-c\build\Release\iothsm.dll" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_OPENSSL_ROOT_DIR)\bin\libeay32.dll" destinationDir="$(runtime.programFiles)\iotedge" />
<file source="$(_REPO_ROOT)\edgelet\contrib\docs\LICENSE" destinationDir="$(runtime.programFiles)\iotedge\LICENSE" />
<file source="$(_REPO_ROOT)\edgelet\contrib\docs\ThirdPartyNotices" destinationDir="$(runtime.programFiles)\iotedge\LICENSE" />
<file source="$(_REPO_ROOT)\edgelet\contrib\docs\trademark" destinationDir="$(runtime.programFiles)\iotedge\LICENSE" />

<file source="$(_REPO_ROOT)\moby-engine\dockerd.exe" destinationDir="$(runtime.programFiles)\iotedge-moby" />
<file source="$(_REPO_ROOT)\moby-engine\LICENSE" destinationDir="$(runtime.programFiles)\iotedge-moby\legal-engine" />
<file source="$(_REPO_ROOT)\moby-engine\ThirdPartyNotices" destinationDir="$(runtime.programFiles)\iotedge-moby\legal-engine" />

<file source="$(_REPO_ROOT)\moby-cli\docker.exe" destinationDir="$(runtime.programFiles)\iotedge-moby" />
<file source="$(_REPO_ROOT)\moby-cli\LICENSE" destinationDir="$(runtime.programFiles)\iotedge-moby\legal-cli" />
<file source="$(_REPO_ROOT)\moby-cli\ThirdPartyNotices" destinationDir="$(runtime.programFiles)\iotedge-moby\legal-cli" />
</files>
<regKeys>
<regKey keyName="$(hklm.system)\CurrentControlSet\Services\EventLog\Application\iotedged">
<regValue name="CustomSource" value="1" type="REG_DWORD" />
<regValue name="EventMessageFile" value="$(runtime.programFiles)\iotedge\iotedged_eventlog_messages.dll" type="REG_SZ" />
<regValue name="TypesSupported" value="7" type="REG_DWORD" />
</regKey>
<regKey keyName="$(hklm.system)\CurrentControlSet\Services\EventLog\Application\iotedge-moby">
<regValue name="CustomSource" value="1" type="REG_DWORD" />
<regValue name="EventMessageFile" value="$(runtime.programFiles)\iotedge-moby\dockerd.exe" type="REG_SZ" />
<regValue name="TypesSupported" value="7" type="REG_DWORD" />
</regKey>
</regKeys>
<service
description="Moby Engine"
displayName="Moby Engine"
errorControl="normal"
imagePath="$(runtime.programFiles)\iotedge-moby\dockerd.exe -H npipe:////./pipe/iotedge_moby_engine --exec-opt isolation=process --run-service --data-root $(runtime.programData)\iotedge-moby --exec-root $(runtime.programData)\iotedge-moby\\exec-root"
name="iotedge-moby"
objectName="LocalSystem"
sidType="unrestricted"
start="auto"
startAfterInstall="none"
type="win32OwnProcess"
/>
<service
dependOnService="iotedge-moby"
description="Azure IoT Edge Daemon"
displayName="Azure IoT Edge Daemon"
errorControl="normal"
imagePath="$(runtime.programFiles)\iotedge\iotedged.exe -c $(runtime.programData)\iotedge\config.yaml"
name="iotedge"
objectName="LocalSystem"
sidType="unrestricted"
start="auto"
startAfterInstall="none"
type="win32OwnProcess">
<failureActions resetPeriod="0">
<actions>
<action
delay="1000"
type="restartService"
/>
</actions>
</failureActions>
</service>
</identity>
141 changes: 141 additions & 0 deletions edgelet/build/windows/package.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
Param([Switch] $CreateTemplate, [Switch] $CreateCab, [Switch] $SkipInstallCerts)

$EdgeCab = "Microsoft-Azure-IoTEdge.cab"
$EdgeTemplate = "Package-Template"

Function New-Cabinet([String] $Destination, [String[]] $Files, [String] $Path)
{
$Ddf = [IO.Path]::GetTempFileName()
$CabinetName = Split-Path -Leaf $Destination
$DiskDirectory = Split-Path -Parent $Destination
if (-not $DiskDirectory) {
$DiskDirectory = "."
}
$DiskDirectory = (Get-Item -Path $DiskDirectory).FullName
$Directories = $Files | Group-Object -Property { Split-Path -Parent $_ }
$DdfContent = @"
.Option Explicit
.Set SourceDir=$Path
.Set DiskDirectoryTemplate=$DiskDirectory
.Set CabinetNameTemplate=$CabinetName
.Set CompressionType=LZX
.Set Compress=on
.Set UniqueFiles=Off
.Set Cabinet=On
.Set MaxDiskSize=0
"@
$Directories | ForEach-Object {
$Directory = $_.Name
if (-not $Directory)
{
$Directory = " ;"
}
$Files = $_.Group
$DdfContent += @"
.Set DestinationDir=$Directory
$($OFS="`r`n"; $Files)
"@
}
$DdfContent | Out-File $Ddf -Encoding Ascii

$DdfContent

makecab.exe /f $Ddf
if ($LASTEXITCODE) {
Throw "Failed to create cab"
}

Remove-Item $Ddf
}

Function New-Package([string] $Name, [string] $Version)
{
$pkggen = "${Env:ProgramFiles(x86)}\Windows Kits\10\tools\bin\i386\pkggen.exe"
$manifest = "edgelet\build\windows\$Name.wm.xml"
$cwd = "."
Invoke-Expression "& '$pkggen' $manifest /universalbsp /variables:'_REPO_ROOT=..\..\..;_OPENSSL_ROOT_DIR=$env:OPENSSL_ROOT_DIR' /cpu:amd64 /version:$Version"
if ($LASTEXITCODE) {
Throw "Failed to package cab"
}

if (Test-Path $EdgeTemplate) {
Remove-Item -Path $EdgeTemplate -Recurse -Force
}
New-Item -ItemType Directory -Path $EdgeTemplate
Invoke-Expression "& ${Env:SystemRoot}\system32\Expand.exe $EdgeCab -f:* $EdgeTemplate"
if ($LASTEXITCODE) {
Throw "Failed to expand cab"
}
Remove-Item -Path $EdgeCab
}

if ($CreateTemplate) {
$docker_cli_uri = "https://github.com/Azure/azure-iotedge/releases/download/1.0.5/moby-cli_3.0.2.zip"
$docker_engine_uri = "https://conteng.blob.core.windows.net/mby/moby-engine_3.0.3.zip"

$env:PATH = "$env:PATH;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\tools\bin\i386"
$env:SIGNTOOL_OEM_SIGN = '/a /s my /i "Windows OEM Intermediate 2017 (TEST ONLY)" /n "Windows OEM Test Cert 2017 (TEST ONLY)" /fd SHA256'
$env:SIGN_MODE = 'Test'
$env:SIGN_OEM = '1'
$env:SIGN_WITH_TIMESTAMP = '0'
$env:WSKCONTENTROOT = 'C:\Program Files (x86)\Windows Kits\10'

if (-not $SkipInstallCerts) {
cmd /c installoemcerts.cmd
}

$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest $docker_cli_uri -out "moby-cli.zip" -UseBasicParsing
if (Test-Path "moby-cli") {
Remove-Item -Path "moby-cli" -Recurse -Force
}
Expand-Archive -Path "moby-cli.zip" -DestinationPath "moby-cli"

Invoke-WebRequest $docker_engine_uri -out "moby-engine.zip" -UseBasicParsing
if (Test-Path "moby-engine") {
Remove-Item -Path "moby-engine" -Recurse -Force
}
Expand-Archive -Path "moby-engine.zip" -DestinationPath "moby-engine"

#
# IoTEdge
#

Write-Host ("IoTEdge source version '{0}'" -f $env:VERSION)

# VERSION is either 1.0.7~dev or 1.0.7
$splitVersion = $env:VERSION -split "~"
if ($splitVersion.Length -eq 1) {
$version = $env:VERSION
$splitVersion = $version -split "\."
if ($splitVersion.Length -eq 3) {
$version = ("{0}.0" -f $version)
}
if ($version -notmatch "\d+\.\d+\.\d+\.\d+") {
throw "Windows package requires VERSION in form major.minor.build.revision, each segment having 0-65535"
}
}
else {
# we need 255^2 tops per segment
$major = ($splitVersion[0] -split "\.")[0]
$splitSuffix = ($splitVersion[1] -split "\.")
$dateSegment = ($splitSuffix[-2])[-8..-1] -join ""
$date = [datetime]::ParseExact($dateSegment, "yyyyMMdd", $null)
$dateEncoded = ("{0}{1}" -f ($date.ToString("yy")), $date.DayOfYear.ToString("000"))
$buildPerDay = $splitSuffix[-1]
$version = "0.{0}.{1}.{2}" -f $major, $dateEncoded, $buildPerDay
}

Write-Host "IoTEdge using version '$version'"

New-Package -Name "iotedge" -Version $version
}
elseif ($CreateCab) {
$TemplateDirLength = ((Get-Item -Path $EdgeTemplate).FullName.Length + 1)
$Files = Get-ChildItem -Path $EdgeTemplate -Recurse | Where-Object { -not $_.PSIsContainer } | ForEach-Object {
return $_.FullName.Remove(0, $TemplateDirLength)
}
New-Cabinet -Destination $EdgeCab -Files $Files -Path $EdgeTemplate
}
Loading

0 comments on commit ce232a8

Please sign in to comment.