Skip to content

Commit

Permalink
chore: combine creating sku and publishing new image to PIR (Azure#559)
Browse files Browse the repository at this point in the history
* publish the final windows image version during official build

* Update pub tool version

* create sku when not exist

* Update pub tool path

* Use template to create SKU and new image

* Add sku and new image phase for containerd image

* update naming

* Update sku prefix

* Determine image version by current date or from branch name

* Fix toggle usage

* Use release date instead of branch cut date

* Add support for containerd sku and image to PIR

* Remove unused script

* use pipeline ID variables instead of a constant num

* fix comments

* Cache winzip for containerd from k8s 1.20

* Fix

* Fix test

* Update image version and containerd release notes
  • Loading branch information
Qingchuan Hao authored Feb 11, 2021
1 parent 85193d6 commit ac608f7
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 171 deletions.
37 changes: 37 additions & 0 deletions .pipelines/.vsts-Marketpalce-win.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: $(Date:yyyyMMdd)$(Rev:.r)_$(Build.SourceBranchName)_$(BuildID)
trigger: none

variables:
CONTAINER_IMAGE: 'mcr.microsoft.com/oss/azcu/go-dev:v1.28.5'

phases:
- phase: create_sku_and_publish_2019_image
condition: eq(variables.FOR_2019, 'True')
queue:
name: Hosted Ubuntu 1604
timeoutInMinutes: 180
steps:
- bash: |
echo '##vso[task.setvariable variable=PUBLISHER]microsoft-aks'
echo '##vso[task.setvariable variable=OFFER]aks-windows'
echo '##vso[task.setvariable variable=CONTAINER_RUNTIME]docker'
echo '##vso[task.setvariable variable=SKU_PREFIX]aks-2019-datacenter-core-smalldisk'
displayName: Setup Build Variables
- template: ./templates/.builder-Marketplace-win-template.yaml
parameters:
artifactName: 2019
- phase: create_sku_and_publish_2019_containerd_image
condition: eq(variables.FOR_2019_CONTAINERD, 'True')
queue:
name: Hosted Ubuntu 1604
timeoutInMinutes: 180
steps:
- bash: |
echo '##vso[task.setvariable variable=PUBLISHER]microsoft-aks'
echo '##vso[task.setvariable variable=OFFER]aks-windows'
echo '##vso[task.setvariable variable=CONTAINER_RUNTIME]containerd'
echo '##vso[task.setvariable variable=SKU_PREFIX]aks-2019-datacenter-core-ctrd'
displayName: Setup Build Variables
- template: ./templates/.builder-Marketplace-win-template.yaml
parameters:
artifactName: 2019-containerd
2 changes: 1 addition & 1 deletion .pipelines/.vsts-vhd-builder-release-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ phases:
echo '##vso[task.setvariable variable=HYPERV_GENERATION]V1'
echo '##vso[task.setvariable variable=AZURE_VM_SIZE]Standard_D4s_v3'
echo '##vso[task.setvariable variable=CONTAINER_RUNTIME]containerd'
echo '##vso[task.setvariable variable=WINDOWS_SKU]2019'
echo '##vso[task.setvariable variable=WINDOWS_SKU]2019-containerd'
displayName: Setup Build Variables
- template: ./templates/.builder-release-template-windows.yaml
parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
trigger: none
pr: none

jobs:
- job: create_marketplace_sku
pool:
name: $(BUILD_POOL)
steps:
steps:
- task: DownloadPipelineArtifact@2
displayName: Download VHD publishing info
inputs:
source: 'specific'
path: artifacts/vhd
project: 'CloudNativeCompute'
pipeline: $(VHD_PIPELINE_ID)
runVersion: 'specific'
runId: $(VHD_PIPELINE_RUN_ID)
- script: |
docker run --rm \
-v ${PWD}:/go/src/github.com/Azure/AgentBaker \
-w /go/src/github.com/Azure/AgentBaker \
${DEIS_GO_DEV_IMAGE} make bootstrap
displayName: Update tools
${CONTAINER_IMAGE} make bootstrap
displayName: Setup tools
- script: |
docker run --rm \
-v ${PWD}:/go/src/github.com/Azure/AgentBaker \
Expand All @@ -24,17 +26,12 @@ jobs:
-e PUBLISHER=${PUBLISHER} \
-e OFFER=${OFFER} \
-e CONTAINER_RUNTIME=${CONTAINER_RUNTIME} \
${DEIS_GO_DEV_IMAGE} ./vhdbuilder/publish/Marketplace/new-windows-sku.sh
${CONTAINER_IMAGE} ./vhdbuilder/publish/Marketplace/new-sku-and-add-image-version.sh
displayName: Create a new marketplace SKU
- task: PublishPipelineArtifact@1
inputs:
artifact: 'sku_info'
path: 'sku-publishing-info.json'
- script: |
docker run --rm \
-v ${PWD}:/go/src/github.com/Azure/AgentBaker \
-w /go/src/github.com/Azure/AgentBaker \
${DEIS_GO_DEV_IMAGE} make tools-clean
${CONTAINER_IMAGE} make tools-clean
displayName: cleanup - clean hack/tools/bin
condition: always()
12 changes: 10 additions & 2 deletions .pipelines/templates/.builder-release-template-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ steps:
- bash: |
if [[ -n ${SIG_GALLERY_NAME} && -n ${SIG_IMAGE_NAME} && -n ${SIG_IMAGE_VERSION} ]]; then m="sigMode"; else m="default"; fi && \
echo "Set build mode to $m" && \
echo "##vso[task.setvariable variable=MODE]$m"
echo "##vso[task.setvariable variable=MODE]$m" && \
if [[ "${USE_RELEASE_DATE}" = "False" ]]; then \
echo "use current date as build date"; BUILD_DATE=$(date +"%y%m%d"); \
else \
echo "use release date as build date"; branchName=$(Build.SourceBranchName); BUILD_DATE=${branchName: -6}; \
fi && \
echo "Set build date to $BUILD_DATE" && \
echo "##vso[task.setvariable variable=BUILD_DATE]$BUILD_DATE"
displayName: Get Build Mode
- script: |
echo MODE=$(MODE) && \
Expand Down Expand Up @@ -113,6 +120,7 @@ steps:
OS_DISK_SAS="$(cat packer-output | grep "OSDiskUriReadOnlySas:" | cut -d " " -f 2)" && \
VHD_NAME="$(echo $OS_DISK_SAS | cut -d "/" -f 8 | cut -d "?" -f 1)" && \
WINDOWS_VERSION="$(grep "OS Version" < release-notes.txt | cut -d ":" -f 2 | tr -d "[:space:]")" && \
IMAGE_VERSION="$WINDOWS_VERSION.${BUILD_DATE}" && \
SKU_NAME="windows-$WINDOWS_SKU" && \
docker run --rm \
-v ${PWD}:/go/src/github.com/Azure/AgentBaker \
Expand All @@ -127,7 +135,7 @@ steps:
-e OS_NAME="Windows" \
-e SKU_NAME=${SKU_NAME} \
-e OFFER_NAME="Windows" \
-e IMAGE_VERSION=${WINDOWS_VERSION} \
-e IMAGE_VERSION=${IMAGE_VERSION} \
-e HYPERV_GENERATION="V1" \
${CONTAINER_IMAGE} make -f packer.mk generate-sas
displayName: Getting Shared Access Signature URI
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $(LOCALBIN)/golangci-lint:
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(LOCALBIN) v1.21.0

$(LOCALBIN)/pub:
GOBIN=$(LOCALBIN) $(GO) get github.com/devigned/pub/[email protected].3
GOBIN=$(LOCALBIN) $(GO) get github.com/devigned/pub/[email protected].6

.PHONY: reload
reload: clean install
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Azure/aks-engine/hack/tools
go 1.12

require (
github.com/devigned/pub v0.2.3 // indirect
github.com/devigned/pub v0.2.6 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/mitchellh/gox v1.0.1
github.com/onsi/ginkgo v1.10.1
Expand Down
2 changes: 2 additions & 0 deletions hack/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devigned/pub v0.2.3 h1:GFdcC2zrTqPCh55DZvUF38mOi4HkYDkxaTtscLBTzoU=
github.com/devigned/pub v0.2.3/go.mod h1:XLFqwlVUlxn4ALCFZpjZHqE7tK6vLBypht2PivPFRnM=
github.com/devigned/pub v0.2.6 h1:NsjET4//z4WzjkhE6It4fgepqK2+2rFwaw6rZvqN1mY=
github.com/devigned/pub v0.2.6/go.mod h1:XLFqwlVUlxn4ALCFZpjZHqE7tK6vLBypht2PivPFRnM=
github.com/devigned/tab v0.0.1 h1:RFMMQ40ds0zAPabPGbNT7C269NbQQyStQUsKqxwm654=
github.com/devigned/tab v0.0.1/go.mod h1:oVYrfgGyond090gxCvvbjZji79+peOiSV6vhZhKJM0Y=
github.com/devigned/tab/opencensus v0.1.2 h1:IkqF46qN8f1WCGwNlvMSVOPxAdFug29n9zLIlxGL7ms=
Expand Down
24 changes: 20 additions & 4 deletions vhdbuilder/packer/configure-windows-vhd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Get-ContainerImages {
$imagesToPull = @()

switch ($windowsSKU) {
'2019' {
{ '2019', '2019-containerd'} {
$imagesToPull = @(
"mcr.microsoft.com/windows/servercore:ltsc2019",
"mcr.microsoft.com/windows/nanoserver:1809",
Expand Down Expand Up @@ -92,7 +92,12 @@ function Get-ContainerImages {
}

function Get-FilesToCacheOnVHD {
Write-Log "Caching misc files on VHD"

param (
$containerRuntime
)

Write-Log "Caching misc files on VHD, container runtimne: $containerRuntime"

$map = @{
"c:\akse-cache\" = @(
Expand Down Expand Up @@ -156,6 +161,17 @@ function Get-FilesToCacheOnVHD {

foreach ($URL in $map[$dir]) {
$fileName = [IO.Path]::GetFileName($URL)

# Windows containerD supports Windows containerD, starting from Kubernetes 1.20
if ($containerRuntime -eq 'containerd' -And $dir -eq "c:\akse-cache\win-k8s\") {
$k8sMajorVersion = $fileName.split(".",3)[0]
$k8sMinorVersion = $fileName.split(".",3)[1]
if ($k8sMinorVersion -lt "20" -And $k8sMajorVersion -eq "v1") {
Write-Log "Skip to download $url for containerD is supported from Kubernets 1.20"
continue
}
}

$dest = [IO.Path]::Combine($dir, $fileName)

Write-Log "Downloading $URL to $dest"
Expand Down Expand Up @@ -306,7 +322,7 @@ if (-not ($validContainerRuntimes -contains $containerRuntime)) {
}

$windowsSKU = $env:WindowsSKU
$validSKU = @('2019', '2004')
$validSKU = @('2019', '2019-containerd', '2004')
if (-not ($validSKU -contains $windowsSKU)) {
Write-Host "Unsupported windows image SKU: $windowsSKU"
exit 1
Expand All @@ -332,7 +348,7 @@ switch ($env:ProvisioningPhase) {
Install-ContainerD
}
Get-ContainerImages -containerRuntime $containerRuntime -windowsSKU $windowsSKU
Get-FilesToCacheOnVHD
Get-FilesToCacheOnVHD -containerRuntime $containerRuntime
(New-Guid).Guid | Out-File -FilePath 'c:\vhd-id.txt'
}
default {
Expand Down
2 changes: 1 addition & 1 deletion vhdbuilder/packer/init-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ WINDOWS_IMAGE_VERSION=""
if [ ! -z "${WINDOWS_SKU}" ]; then
source $CDIR/windows-image.env
case "${WINDOWS_SKU}" in
"2019")
"2019"|"2019-containerd")
WINDOWS_IMAGE_SKU=$WINDOWS_2019_BASE_IMAGE_SKU
WINDOWS_IMAGE_VERSION=$WINDOWS_2019_BASE_IMAGE_VERSION
;;
Expand Down
30 changes: 25 additions & 5 deletions vhdbuilder/packer/test/vhd-content-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function Compare-AllowedSecurityProtocols

function Test-FilesToCacheOnVHD
{
param (
$containerRuntime
)

# TODO(qinhao): share this map variable with `configure-windows-vhd.ps1`
$map = @{
"c:\akse-cache\" = @(
Expand All @@ -60,7 +64,10 @@ function Test-FilesToCacheOnVHD
"c:\akse-cache\csi-proxy\" = @(
"https://acs-mirror.azureedge.net/csi-proxy/v0.2.2/binaries/csi-proxy-v0.2.2.tar.gz"
);
"c:\akse-cache\win-k8s\" = @(
# winzip paths here are not valid, but will be changed to the actual path.
# we don't resue the code the validate the winzip used for different container runtimes, but use the real list to
# validat the code and winzip downloaded.
"c:\akse-cache\win-k8s-docker\" = @(
"https://acs-mirror.azureedge.net/kubernetes/v1.16.10-hotfix.20200817/windowszip/v1.16.10-hotfix.20200817-1int.zip",
"https://acs-mirror.azureedge.net/kubernetes/v1.16.13-hotfix.20210118/windowszip/v1.16.13-hotfix.20210118-1int.zip",
"https://acs-mirror.azureedge.net/kubernetes/v1.16.15-hotfix.20210118/windowszip/v1.16.15-hotfix.20210118-1int.zip",
Expand All @@ -78,7 +85,10 @@ function Test-FilesToCacheOnVHD
"https://acs-mirror.azureedge.net/kubernetes/v1.19.1-hotfix.20200923/windowszip/v1.19.1-hotfix.20200923-1int.zip",
"https://acs-mirror.azureedge.net/kubernetes/v1.19.3-hotfix.20210118/windowszip/v1.19.3-hotfix.20210118-1int.zip",
"https://acs-mirror.azureedge.net/kubernetes/v1.19.6-hotfix.20210118/windowszip/v1.19.6-hotfix.20210118-1int.zip",
"https://acs-mirror.azureedge.net/kubernetes/v1.19.7-hotfix.20210122/windowszip/v1.19.7-hotfix.20210122-1int.zip",
"https://acs-mirror.azureedge.net/kubernetes/v1.19.7-hotfix.20210122/windowszip/v1.19.7-hotfix.20210122-1int.zip"
);
# Please add new winzips with Kuberentes version >= 1.20 here
"c:\akse-cache\win-k8s-docker-and-containerd\" = @(
"https://acs-mirror.azureedge.net/kubernetes/v1.20.2/windowszip/v1.20.2-1int.zip"
);
"c:\akse-cache\win-vnet-cni\" = @(
Expand All @@ -96,18 +106,28 @@ function Test-FilesToCacheOnVHD
$missingPaths = @()
foreach ($dir in $map.Keys)
{
$fakeDir = $dir
if ($dir.StartsWith("c:\akse-cache\win-k8s"))
{
$dir = "c:\akse-cache\win-k8s\"
}
if(!(Test-Path $dir))
{
Write-Error "Directory $dir does not exit"
$missingPaths = $missingPaths + $dir
continue
}

foreach ($URL in $map[$dir])
foreach ($URL in $map[$fakeDir])
{
$fileName = [IO.Path]::GetFileName($URL)
$dest = [IO.Path]::Combine($dir, $fileName)

if ($containerRuntime -eq "containerd" -And $fakeDir -eq "c:\akse-cache\win-k8s-docker\")
{
continue
}

if(![System.IO.File]::Exists($dest))
{
Write-Error "File $dest does not exist"
Expand Down Expand Up @@ -162,7 +182,7 @@ function Test-ImagesPulled
)
$imagesToPull = @()
switch ($WindowsSKU) {
'2019' {
{'2019', '2019-containerd'} {
$imagesToPull = @(
"mcr.microsoft.com/windows/servercore:ltsc2019",
"mcr.microsoft.com/windows/nanoserver:1809",
Expand Down Expand Up @@ -219,6 +239,6 @@ function Test-ImagesPulled
}

Compare-AllowedSecurityProtocols
Test-FilesToCacheOnVHD
Test-FilesToCacheOnVHD -containerRuntime $containerRuntime
Test-PatchInstalled
Test-ImagesPulled -containerRuntime $containerRuntime -WindowsSKU $WindowsSKU
3 changes: 2 additions & 1 deletion vhdbuilder/packer/windows-vhd-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
"BUILD_COMMIT={{user `build_commit`}}",
"BUILD_ID={{user `build_id`}}",
"BUILD_NUMBER={{user `build_number`}}",
"BUILD_REPO={{user `build_repo`}}"
"BUILD_REPO={{user `build_repo`}}",
"ContainerRuntime={{user `container_runtime`}}"
],
"type": "powershell",
"script": "vhdbuilder/packer/write-release-notes-windows.ps1"
Expand Down
8 changes: 7 additions & 1 deletion vhdbuilder/packer/write-release-notes-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ foreach ($key in $wuRegistryKeys) {
}
Log ""

if (Test-Path 'C:\Program Files\Docker\') {
if ($env:containerRuntime -eq 'docker') {
Log "Docker Info"
$dockerVersion = (docker --version) | Out-String
Log ("Version: {0}" -f $dockerVersion)
Log "Images:"
LOG (docker images --format='{{json .}}' | ConvertFrom-Json | Format-Table Repository, Tag, ID)
} else {
Log "ContainerD Info"
$containerDVersion = (ctr.exe --version) | Out-String
Log ("Version: {0}" -f $containerDVersion)
Log "Images:"
LOG (ctr.exe -n k8s.io image ls)
}
Log ""

Expand Down
Loading

0 comments on commit ac608f7

Please sign in to comment.