Skip to content

Commit

Permalink
fixup! Separate Build Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheyla Trudo committed Nov 25, 2024
1 parent 2ad54b0 commit 326c9e2
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 116 deletions.
54 changes: 54 additions & 0 deletions .pipelines/containers/build-variables-template.steps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
parameters:
- name: targetOs
type: string
values:
- linux
- windows

- name: targetArch
type: string
values:
- amd64
- arm64

- name: image
type: string
values:
- azure-ipam
- cni
- cns
- ipv6-hp-bpf
- npm


steps:
- bash: |
set -e
VAR_ID="${IMAGE}_${OS}_${ARCH}"
BUILD_CONTEXT=$(make "$MAKE_BUILD_CONTEXT")
echo >&2 "##vso[task.setvariable variable=BUILD_CONTEXT_${VAR_ID};]$BUILD_CONTEXT"
IMAGE_PLATFORM_TAG=$(make "$MAKE_IMAGE_TAG")
echo >&2 "##vso[task.setvariable variable=IMAGE_PLATFORM_TAG_${VAR_ID};]$IMAGE_PLATFORM_TAG"
IMAGE_NAME_AND_TAG=$(make "$MAKE_IMAGE_NAME_AND_TAG")
echo >&2 "##vso[task.setvariable variable=IMAGE_NAME_AND_TAG_${VAR_ID};]$IMAGE_NAME_AND_TAG"
DOCKERFILE_PATH=$(make "$MAKE_DOCKERFILE_PATH")
echo >&2 "##vso[task.setvariable variable=DOCKERFILE_PATH_${VAR_ID};]$DOCKERFILE_PATH"
EXTRA_BUILD_ARGS=$(make "$MAKE_EXTRA_BUILD_ARGS")
echo >&2 "##vso[task.setvariable variable=EXTRA_BUILD_ARGS_${VAR_ID};]$EXTRA_BUILD_ARGS"
displayName: "Get Image Build Data"
env:
IMAGE: ${{ parameters.image }}
OS: ${{ parameters.targetOs }}
ARCH: ${{ parameters.targetArch }}
PLATFORM: ${{ parameters.targetOs }}/${{ parameters.targetArch }}
MAKE_IMAGE_TAG: ${{ parameters.image }}-image-tag
MAKE_BUILD_CONTEXT: ${{ parameters.image }}-image-build-context
MAKE_IMAGE_NAME_AND_TAG: ${{ parameters.image }}-image-name-and-tag
MAKE_DOCKERFILE_PATH: ${{ parameters.image }}-dockerfile-path
MAKE_EXTRA_BUILD_ARGS: ${{ parameters.image }}-docker-build-args
31 changes: 8 additions & 23 deletions .pipelines/containers/container-template.steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,31 @@ parameters:
- name: dockerfilePath
type: string

- name: targetVersion
type: string
default: ""

- name: buildContextPath
type: string
default: ""

- name: targetPlatform
- name: buildPlatform
type: string
default: ""

- name: targetOs
type: string
values:
- linux
- windows

- name: targetArch
- name: buildArch
type: string
values:
- amd64
- arm64

- name: buildOs
type: string
values:
- linux
- windows

- name: buildArch
- name: targetVersion
type: string
values:
- amd64
- arm64
default: ""

- name: buildPlatform
- name: targetPlatform
type: string
default: ""

- name: targetOs
type: string

- name: addBuildArgs
type: object
default: ""
Expand Down
112 changes: 53 additions & 59 deletions .pipelines/containers/containerize.jobs.yaml
Original file line number Diff line number Diff line change
@@ -1,85 +1,79 @@
parameters:
- name: supportedPlatforms
type: jobList

- name: images
type: object
default: []

- name: targetOs
type: string
default: linux
values:
- linux
- windows

- name: targetArch
type: string


- name: buildPlatform
type: string
default: ''
default: amd64
values:
- amd64
- arm64

- name: buildOs
type: string
default: linux
values:
- linux
- windows

- name: buildArch
type: string
default: amd64
values:
- amd64
- arm64

- name: buildVariablesStepTemplate
type: string
default: ''


jobs:
- ${{ each supportedPlatformJob in parameters.supportedPlatforms }}:
- ${{ each imageName in supportedPlatformJob.images }}:
- job: ${{ replace(concat(imageName, '_', supportedPlatformJob.name), '-', '_') }}
displayName: Build Image - (${{ imageName }} ${{ parameters.targetOs }}/${{ parameters.targetArch }})
steps:
- checkout: self

- task: GoTool@0
inputs:
version: $(GO_VERSION)

- bash: |
set -e
VAR_ID="${IMAGE}_${OS}_${ARCH}"

BUILD_CONTEXT=$(make "$MAKE_BUILD_CONTEXT")
echo >&2 "##vso[task.setvariable variable=BUILD_CONTEXT_${VAR_ID};]$BUILD_CONTEXT"

IMAGE_PLATFORM_TAG=$(make "$MAKE_IMAGE_TAG")
echo >&2 "##vso[task.setvariable variable=IMAGE_PLATFORM_TAG_${VAR_ID};]$IMAGE_PLATFORM_TAG"

IMAGE_NAME_AND_TAG=$(make "$MAKE_IMAGE_NAME_AND_TAG")
echo >&2 "##vso[task.setvariable variable=IMAGE_NAME_AND_TAG_${VAR_ID};]$IMAGE_NAME_AND_TAG"

DOCKERFILE_PATH=$(make "$MAKE_DOCKERFILE_PATH")
echo >&2 "##vso[task.setvariable variable=DOCKERFILE_PATH_${VAR_ID};]$DOCKERFILE_PATH"

EXTRA_BUILD_ARGS=$(make "$MAKE_EXTRA_BUILD_ARGS")
echo >&2 "##vso[task.setvariable variable=EXTRA_BUILD_ARGS_${VAR_ID};]$EXTRA_BUILD_ARGS"
displayName: "Get Image Build Data"
env:
IMAGE: ${{ imageName }}
OS: ${{ parameters.targetOs }}
ARCH: ${{ parameters.targetArch }}
PLATFORM: ${{ parameters.targetOs }}/${{ parameters.targetArch }}
MAKE_IMAGE_TAG: ${{ imageName }}-image-tag
MAKE_BUILD_CONTEXT: ${{ imageName }}-image-build-context
MAKE_IMAGE_NAME_AND_TAG: ${{ imageName }}-image-name-and-tag
MAKE_DOCKERFILE_PATH: ${{ imageName }}-dockerfile-path
MAKE_EXTRA_BUILD_ARGS: ${{ imageName }}-docker-build-args

- template: ./container-template.steps.yaml
- ${{ each imageName in parameters.images }}:
- job: ${{ replace(concat(imageName, '_', parameters.), '-', '_') }}
displayName: Build Image - (${{ imageName }} ${{ parameters.targetOs }}/${{ parameters.targetArch }})
variables:
buildPlatform: ${{ parameters.buildOs }}/${{ parameters.buildArch }}
targetPlatform: ${{ parameters.targetOs }}/${{ parameters.targetArch }}
steps:
- checkout: self

- task: GoTool@0
inputs:
version: $(GO_VERSION)


# Requires creation of the following variables:
# - IMAGE_NAME_AND_TAG_${image}_${OS}_${ARCH}}
# - DOCKERFILE_PATH_${image}_${OS}_${ARCH}}
# - IMAGE_PLATFORM_TAG_${image}_${OS}_${ARCH}}
# - EXTRA_BUILD_ARGS_$${image}_${OS}_${ARCH}}
- ${{ if parameters.buildVariablesStepTemplate }}:
- template: ${{ parameters.buildVariablesStepTemplate }}
parameters:
imageNameAndTag: $(IMAGE_NAME_AND_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
dockerfilePath: $(DOCKERFILE_PATH_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
buildContextPath: $(Build.SourcesDirectory)
targetVersion: $(IMAGE_PLATFORM_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
targetOs: ${{ parameters.targetOs }}
targetArch: ${{ parameters.targetArch }}
targetPlatform: "${{ parameters.targetOs }}/${{ parameters.targetArch }}"
addBuildArgs: $(EXTRA_BUILD_ARGS_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
buildOs: ${{ supportedPlatformJob.templatContext.buildOs }}
buildArch: ${{ supportedPlatformJob.templateContext.buildArch }}
buildPlatform: "${{ supportedPlatformJob.templatContext.buildOs }}/${{ supportedPlatformJob.templateContext.buildArch }}"
image: ${{ imageName }}


- template: ./container-template.steps.yaml
parameters:
imageNameAndTag: $(IMAGE_NAME_AND_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
dockerfilePath: $(DOCKERFILE_PATH_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
buildContextPath: $(Build.SourcesDirectory)
buildPlatform: $(buildPlatform)
buildArch: ${{ parameters.buildArch }}
buildOs: ${{ parameters.buildOs }}
targetVersion: $(IMAGE_PLATFORM_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
targetPlatform: $(targetPlatform)
targetOs: ${{ parameters.targetOs }}
addBuildArgs: $(EXTRA_BUILD_ARGS_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }})
65 changes: 31 additions & 34 deletions .pipelines/run-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,38 @@ stages:
authenticatedContainerRegistries:
- serviceConnection: $(ACR_SERVICECONNECTION)
jobs:
- template: containerize.jobs.yaml
- template: containers/containerize.jobs.yaml
parameters:
buildArch: amd64
buildOs: linux
buildPlatform: linux/amd64
supportedPlatforms:
- template: ./containers/containerize.jobs.yaml
parameters:
targetOs: linux
targetArch: amd64
images:
- azure-ipam
- cni
- cns
- ipv6-hp-bpf
- npm
- template: ./containers/containerize.jobs.yaml
parameters:
targetOs: linux
targetArch: arm64
images:
- azure-ipam
- cni
- cns
- ipv6-hp-bpf
- npm
- template: ./containers/containerize.jobs.yaml
parameters:
targetOs: windows
targetArch: amd64
images:
- azure-ipam
- cni
- cns
- npm
targetOs: linux
targetArch: amd64
images:
- azure-ipam
- cni
- cns
- ipv6-hp-bpf
- npm
imageBuildStepTemplate: /.pipelines/containers/build-variables-template.steps.yaml
- template: containers/containerize.jobs.yaml
parameters:
targetOs: linux
targetArch: arm64
images:
- azure-ipam
- cni
- cns
- ipv6-hp-bpf
- npm
imageBuildStepTemplate: /.pipelines/containers/build-variables-template.steps.yaml
- template: containers/containerize.jobs.yaml
parameters:
targetOs: windows
targetArch: amd64
images:
- azure-ipam
- cni
- cns
- npm
imageBuildStepTemplate: /.pipelines/containers/build-variables-template.steps.yaml


- stage: publish
Expand Down

0 comments on commit 326c9e2

Please sign in to comment.