Skip to content

Commit

Permalink
Add pipeline for Azure community gallery image publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Oct 24, 2024
1 parent 5101ee6 commit d920039
Show file tree
Hide file tree
Showing 22 changed files with 494 additions and 923 deletions.
78 changes: 78 additions & 0 deletions images/capi/packer/azure/.pipelines/build-sig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Required pipeline variables:
# - BUILD_POOL - Azure DevOps build pool to use
# - KUBERNETES_VERSION - version of Kubernetes to build the image with, e.g. `1.31.1`
# - OS - operating system distro, such as 'Ubuntu', 'AzureLinux', or `Windows`
# - OS_VERSION - version of distro, such as `24.04` or `2022-containerd`
# - SERVICE_CONNECTION - Azure DevOps service connection to use for the Azure CLI
# Optional pipeline variables:
# - RESOURCE_GROUP - name of the Azure resource group to use for the compute galleries
# - STAGING_GALLERY_NAME - name of the Azure compute gallery for initial image publishing

jobs:
- job: build_sig
timeoutInMinutes: 120
strategy:
maxParallel: 0
pool:
name: $(BUILD_POOL)
steps:
- template: k8s-config.yaml
- script: |
set -euo pipefail
[[ -n ${DEBUG:-} ]] && set -o xtrace
kube_proxy_url="sigwindowstools/kube-proxy:v${KUBERNETES_VERSION/+/_}-calico-hostprocess"
echo "Checking for Windows kube-proxy image $kube_proxy_url"
if ! stderr="$(docker pull $kube_proxy_url 2>&1 > /dev/null)"; then
# It's a Windows image, so expect an error after pulling it on Linux
if [[ $stderr != *"cannot be used on this platform"* ]]; then
echo "Failed to pull kube-proxy image: $stderr"
exit 1
fi
fi
displayName: Check for Windows kube-proxy image
condition: and(eq(variables['PREFLIGHT_CHECKS'], 'true'), eq(variables['OS'], 'Windows'))
- task: AzureCLI@2
displayName: Build SIG Image
inputs:
azureSubscription: '$(SERVICE_CONNECTION)'
scriptLocation: inlineScript
scriptType: bash
workingDirectory: '$(system.defaultWorkingDirectory)/images/capi'
inlineScript: |
set -euo pipefail
[[ -n ${DEBUG:-} ]] && set -o xtrace
# Generate locales properly on Azure Linux or ansible will complain
sudo tdnf -y install glibc-i18n
sudo locale-gen.sh
export LC_ALL=en_US.UTF-8
export PATH=$PATH:$HOME/.local/bin
os=$(echo "${OS}" | tr '[:upper:]' '[:lower:]')
version=$(echo "${OS_VERSION}" | tr '[:upper:]' '[:lower:]' | tr -d .)
export RESOURCE_GROUP="${RESOURCE_GROUP:-cluster-api-gallery}"
export RESOURCE_GROUP_NAME="${RESOURCE_GROUP}"
export SIG_OFFER="reference-images"
# timestamp is in RFC-3339 format to match kubetest
export TIMESTAMP="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
export JOB_NAME="${JOB_NAME:-"image-builder-sig-${os}-${version}"}"
export TAGS="${TAGS:-creationTimestamp=${TIMESTAMP} jobName=${JOB_NAME} DO-NOT-DELETE=UpstreamInfra}"
printf "${TAGS}" | tee packer/azure/tags.out
export GALLERY_NAME="${STAGING_GALLERY_NAME:-staging_gallery}"
DISTRO="${os}-${version}"
echo "##vso[task.setvariable variable=DISTRO]$DISTRO"
# Add build tags in ADO
echo "##vso[build.addbuildtag]$KUBERNETES_VERSION"
echo "##vso[build.addbuildtag]$DISTRO"
export PACKER_FLAGS="${PACKER_FLAGS} --var sig_image_version=${KUBERNETES_VERSION}"
export USE_AZURE_CLI_AUTH="True"
make build-azure-sig-$os-$version | tee packer/azure/packer.out
- template: sig-publishing-info.yaml
- task: PublishPipelineArtifact@1
inputs:
artifact: 'publishing-info'
path: '$(system.defaultWorkingDirectory)/images/capi/packer/azure/sig-publishing-info.json'
62 changes: 0 additions & 62 deletions images/capi/packer/azure/.pipelines/build-vhd.yaml

This file was deleted.

48 changes: 48 additions & 0 deletions images/capi/packer/azure/.pipelines/clean-sig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Required pipeline variables:
# - BUILD_POOL - Azure DevOps build pool to use
# - SERVICE_CONNECTION - Azure DevOps service connection to use for the Azure CLI
# Optional pipeline variables:
# - RESOURCE_GROUP - name of the Azure resource group to use for the compute galleries
# - STAGING_GALLERY_NAME - name of the Azure compute gallery for initial image publishing

jobs:
- job: clean_sig
timeoutInMinutes: 120
strategy:
maxParallel: 0
pool:
name: $(BUILD_POOL)
steps:
- task: DownloadPipelineArtifact@2
inputs:
source: current
artifact: publishing-info
path: $(system.defaultWorkingDirectory)/images/capi/packer/azure/sig/
- script: |
set -euo pipefail
[[ -n ${DEBUG:-} ]] && set -o xtrace
SHARED_IMAGE_GALLERY_IMAGE_NAME=$(jq -r .shared_image_gallery_image_name $(system.defaultWorkingDirectory)/images/capi/packer/azure/sig/sig-publishing-info.json)
SHARED_IMAGE_GALLERY_IMAGE_VERSION=$(jq -r .shared_image_gallery_image_version $(system.defaultWorkingDirectory)/images/capi/packer/azure/sig/sig-publishing-info.json)
echo "##vso[task.setvariable variable=SHARED_IMAGE_GALLERY_IMAGE_NAME]$SHARED_IMAGE_GALLERY_IMAGE_NAME"
echo "##vso[task.setvariable variable=SHARED_IMAGE_GALLERY_IMAGE_VERSION]$SHARED_IMAGE_GALLERY_IMAGE_VERSION"
displayName: Import variables from build SIG job
- task: AzureCLI@2
displayName: Clean up staging resources
inputs:
azureSubscription: '$(SERVICE_CONNECTION)'
scriptLocation: inlineScript
scriptType: bash
workingDirectory: '$(system.defaultWorkingDirectory)/images/capi'
inlineScript: |
set -euo pipefail
GALLERY_NAME="${STAGING_GALLERY_NAME:-staging_gallery}"
RESOURCE_GROUP="${RESOURCE_GROUP:-cluster-api-gallery}"
az sig image-version delete \
--resource-group ${RESOURCE_GROUP} \
--gallery-name ${GALLERY_NAME} \
--gallery-image-definition ${SHARED_IMAGE_GALLERY_IMAGE_NAME} \
--gallery-image-version ${SHARED_IMAGE_GALLERY_IMAGE_VERSION}
43 changes: 0 additions & 43 deletions images/capi/packer/azure/.pipelines/cleanup.yaml

This file was deleted.

36 changes: 0 additions & 36 deletions images/capi/packer/azure/.pipelines/create-disk-version.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions images/capi/packer/azure/.pipelines/create-sku.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions images/capi/packer/azure/.pipelines/delete-storage-account.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions images/capi/packer/azure/.pipelines/generate-sas.yaml

This file was deleted.

Loading

0 comments on commit d920039

Please sign in to comment.