Skip to content

Commit 54b968b

Browse files
author
Sheyla Trudo
committed
fixup! Separate Build Changes
1 parent fdc112e commit 54b968b

File tree

3 files changed

+120
-179
lines changed

3 files changed

+120
-179
lines changed
Lines changed: 60 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,72 @@
11
parameters:
2+
- name: jobs
3+
type: jobList
4+
default: []
5+
26
- name: arch
37
type: string
4-
default: ""
5-
values:
6-
- amd64
7-
- arm64
88

99
- name: os
1010
type: string
11-
default: ""
12-
values:
13-
- windows
14-
- linux
1511

1612
- name: images
1713
type: object
18-
19-
- name: containerRegistry
20-
type: object
14+
default: []
2115

2216

2317
jobs:
24-
- ${{ each image in parameters.images }}:
25-
- job: ${{ replace(image, '-', '_') }}_${{ parameters.os }}_${{ parameters.arch }}
26-
displayName: Build Image - (${{ image }} ${{ parameters.os }}/${{ parameters.arch }})
27-
templateContext:
28-
authenticatedContainerRegistries:
29-
- serviceConnection: $(ACR_SERVICECONNECTION)
30-
31-
steps:
32-
- checkout: self
33-
34-
- task: GoTool@0
35-
inputs:
36-
version: $(GO_VERSION)
37-
38-
- bash: |
39-
set -e
40-
41-
echo >&2 "##vso[task.setvariable variable=${VAR_ID};]$VAR_ID"
42-
displayName: "Get Image ID"
43-
env:
44-
VAR_ID: ${{ image }}_${{ parameters.os }}_${{ parameters.arch }}
45-
46-
- bash: |
47-
set -e
48-
49-
VAR_ID="${IMAGE}_${OS}_${ARCH}"
50-
51-
BUILD_CONTEXT=$(make "$MAKE_BUILD_CONTEXT")
52-
echo >&2 "##vso[task.setvariable variable=BUILD_CONTEXT_${VAR_ID};]$BUILD_CONTEXT"
53-
54-
IMAGE_PLATFORM_TAG=$(make "$MAKE_IMAGE_TAG")
55-
echo >&2 "##vso[task.setvariable variable=IMAGE_PLATFORM_TAG_${VAR_ID};]$IMAGE_PLATFORM_TAG"
56-
57-
IMAGE_NAME_AND_TAG=$(make "$MAKE_IMAGE_NAME_AND_TAG")
58-
echo >&2 "##vso[task.setvariable variable=IMAGE_NAME_AND_TAG_${VAR_ID};]$IMAGE_NAME_AND_TAG"
59-
60-
DOCKERFILE_PATH=$(make "$MAKE_DOCKERFILE_PATH")
61-
echo >&2 "##vso[task.setvariable variable=DOCKERFILE_PATH_${VAR_ID};]$DOCKERFILE_PATH"
62-
63-
EXTRA_BUILD_ARGS=$(make "$MAKE_EXTRA_BUILD_ARGS")
64-
echo >&2 "##vso[task.setvariable variable=EXTRA_BUILD_ARGS_${VAR_ID};]$EXTRA_BUILD_ARGS"
65-
displayName: "Get Image Build Data"
66-
env:
67-
IMAGE: ${{ image }}
68-
OS: ${{ parameters.os }}
69-
ARCH: ${{ parameters.arch }}
70-
PLATFORM: ${{ parameters.os }}/${{ parameters.arch }}
71-
MAKE_IMAGE_TAG: ${{ image }}-image-tag
72-
MAKE_BUILD_CONTEXT: ${{ image }}-image-build-context
73-
MAKE_IMAGE_NAME_AND_TAG: ${{ image }}-image-name-and-tag
74-
MAKE_DOCKERFILE_PATH: ${{ image }}-dockerfile-path
75-
MAKE_EXTRA_BUILD_ARGS: ${{ image }}-docker-build-args
76-
77-
- template: ./container-template.steps.yaml
78-
parameters:
79-
imageNameAndTag: $(IMAGE_NAME_AND_TAG_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
80-
dockerfilePath: $(DOCKERFILE_PATH_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
81-
buildContextPath: $(Build.SourcesDirectory)
82-
targetVersion: $(IMAGE_PLATFORM_TAG_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
83-
targetOs: ${{ parameters.os }}
84-
targetArch: ${{ parameters.arch }}
85-
targetPlatform: "${{ parameters.os }}/${{ parameters.arch }}"
86-
addBuildArgs: $(EXTRA_BUILD_ARGS_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
87-
${{ if eq(variables.Agent.OSArchitecture, 'ARM') }}:
88-
buildArch: arm64
89-
90-
${{ if eq(variables.Agent.OS, 'Linux') }}:
91-
buildOs: linux
92-
buildPlatform: linux/amd64
93-
${{ else }}:
94-
buildOs: windows
95-
buildPlatform: windows/amd64
96-
97-
${{ else }}:
98-
buildArch: amd64
99-
100-
${{ if eq(variables.Agent.OS, 'Linux') }}:
101-
buildOs: linux
102-
buildPlatform: linux/amd64
103-
${{ else }}:
104-
buildOs: windows
105-
buildPlatform: windows/amd64
106-
107-
# - task: 1ES.BuildContainerImage@1
108-
# retryCountOnTaskFailure: 3
109-
# inputs:
110-
# image: ${{ parameters.imageNameAndTag }}
111-
# dockerfile: ${{ parameters.dockerfilePath }}
112-
# path: ${{ parameters.targetPath }} $(Build.SourcesDirectory)
113-
# buildArguments: |
114-
# --build-arg PLATFORM="${{ parameters.buildPlatform }}" \
115-
# --build-arg ARCH="${{ parameters.buildArch }}" \
116-
# --build-arg OS="${{ parameters.buildOs }}" \
117-
# --build-arg VERSION="${{ parameters.platformVersion }}" \
118-
# --platform "${{ parameters.targetPlatform }}" \
119-
# --target "${{ parameters.targetOs }}" \
120-
# ${{ parameters.addBuildArgs }}
121-
# enableNetwork: true
122-
# enablePull: false
123-
# enableCache: true
124-
# useBuildKit: true
125-
#
126-
# - task: 1ES.PushContainerImage@1
127-
# condition: ${{ eq(parameters.os, 'windows') }}
128-
# inputs:
129-
# image: ${{ parameters.imageNameAndTag }}
18+
- ${{ each job in parameters.jobs }}:
19+
- ${{ each image in parameters.images }}:
20+
- job: ${{ replace(image, '-', '_') }}_${{ parameters.os }}_${{ parameters.arch }}
21+
displayName: Build Image - (${{ image }} ${{ parameters.os }}/${{ parameters.arch }})
22+
steps:
23+
- checkout: self
24+
25+
- task: GoTool@0
26+
inputs:
27+
version: $(GO_VERSION)
28+
29+
- bash: |
30+
set -e
31+
32+
VAR_ID="${IMAGE}_${OS}_${ARCH}"
33+
34+
BUILD_CONTEXT=$(make "$MAKE_BUILD_CONTEXT")
35+
echo >&2 "##vso[task.setvariable variable=BUILD_CONTEXT_${VAR_ID};]$BUILD_CONTEXT"
36+
37+
IMAGE_PLATFORM_TAG=$(make "$MAKE_IMAGE_TAG")
38+
echo >&2 "##vso[task.setvariable variable=IMAGE_PLATFORM_TAG_${VAR_ID};]$IMAGE_PLATFORM_TAG"
39+
40+
IMAGE_NAME_AND_TAG=$(make "$MAKE_IMAGE_NAME_AND_TAG")
41+
echo >&2 "##vso[task.setvariable variable=IMAGE_NAME_AND_TAG_${VAR_ID};]$IMAGE_NAME_AND_TAG"
42+
43+
DOCKERFILE_PATH=$(make "$MAKE_DOCKERFILE_PATH")
44+
echo >&2 "##vso[task.setvariable variable=DOCKERFILE_PATH_${VAR_ID};]$DOCKERFILE_PATH"
45+
46+
EXTRA_BUILD_ARGS=$(make "$MAKE_EXTRA_BUILD_ARGS")
47+
echo >&2 "##vso[task.setvariable variable=EXTRA_BUILD_ARGS_${VAR_ID};]$EXTRA_BUILD_ARGS"
48+
displayName: "Get Image Build Data"
49+
env:
50+
IMAGE: ${{ image }}
51+
OS: ${{ parameters.os }}
52+
ARCH: ${{ parameters.arch }}
53+
PLATFORM: ${{ parameters.os }}/${{ parameters.arch }}
54+
MAKE_IMAGE_TAG: ${{ image }}-image-tag
55+
MAKE_BUILD_CONTEXT: ${{ image }}-image-build-context
56+
MAKE_IMAGE_NAME_AND_TAG: ${{ image }}-image-name-and-tag
57+
MAKE_DOCKERFILE_PATH: ${{ image }}-dockerfile-path
58+
MAKE_EXTRA_BUILD_ARGS: ${{ image }}-docker-build-args
59+
60+
- template: ./container-template.steps.yaml
61+
parameters:
62+
imageNameAndTag: $(IMAGE_NAME_AND_TAG_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
63+
dockerfilePath: $(DOCKERFILE_PATH_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
64+
buildContextPath: $(Build.SourcesDirectory)
65+
targetVersion: $(IMAGE_PLATFORM_TAG_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
66+
targetOs: ${{ parameters.os }}
67+
targetArch: ${{ parameters.arch }}
68+
targetPlatform: "${{ parameters.os }}/${{ parameters.arch }}"
69+
addBuildArgs: $(EXTRA_BUILD_ARGS_${{ image }}_${{ parameters.os }}_${{ parameters.arch }})
70+
buildOs: ${{ job.templatContext.buildOs }}
71+
buildArch: ${{ job.templateContext.buildArch }}
72+
buildPlatform: "${{ job.templatContext.buildOs }}/${{ job.templateContext.buildArch }}"

.pipelines/containers/container-template.steps.yaml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,26 @@ parameters:
5151

5252

5353
steps:
54-
- task: 1ES.BuildContainerImage@1
55-
retryCountOnTaskFailure: 3
56-
inputs:
57-
image: ${{ parameters.imageNameAndTag }}
58-
dockerfile: ${{ parameters.dockerfilePath }}
59-
path: ${{ parameters.buildContextPath }}
60-
buildArguments: |
61-
--build-arg PLATFORM="${{ parameters.buildPlatform }}"
62-
--build-arg ARCH="${{ parameters.buildArch }}"
63-
--build-arg OS="${{ parameters.buildOs }}"
64-
--build-arg VERSION="${{ parameters.targetVersion }}"
65-
--platform "${{ parameters.targetPlatform }}"
66-
--target "${{ parameters.targetOs }}"
67-
${{ parameters.addBuildArgs }}
68-
enableNetwork: true
69-
enablePull: false
70-
enableCache: true
71-
useBuildKit: true
72-
73-
- task: 1ES.PushContainerImage@1
74-
condition: ${{ eq(parameters.targetOs, 'windows') }}
75-
inputs:
76-
image: ${{ parameters.imageNameAndTag }}
54+
- task: 1ES.BuildContainerImage@1
55+
retryCountOnTaskFailure: 3
56+
inputs:
57+
image: ${{ parameters.imageNameAndTag }}
58+
dockerfile: ${{ parameters.dockerfilePath }}
59+
path: ${{ parameters.buildContextPath }}
60+
buildArguments: |
61+
--build-arg PLATFORM="${{ parameters.buildPlatform }}"
62+
--build-arg ARCH="${{ parameters.buildArch }}"
63+
--build-arg OS="${{ parameters.buildOs }}"
64+
--build-arg VERSION="${{ parameters.targetVersion }}"
65+
--platform "${{ parameters.targetPlatform }}"
66+
--target "${{ parameters.targetOs }}"
67+
${{ parameters.addBuildArgs }}
68+
enableNetwork: true
69+
enablePull: false
70+
enableCache: true
71+
useBuildKit: true
72+
73+
- task: 1ES.PushContainerImage@1
74+
condition: ${{ eq(parameters.targetOs, 'windows') }}
75+
inputs:
76+
image: ${{ parameters.imageNameAndTag }}

.pipelines/run-pipeline.yaml

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -73,45 +73,43 @@ stages:
7373
dependsOn:
7474
- setup
7575
- test
76-
jobs:
77-
- template: containers/container-template.jobs.yaml
78-
parameters:
79-
arch: amd64
80-
os: linux
81-
images:
82-
- azure-ipam
83-
- cni
84-
- cns
85-
- ipv6-hp-bpf
86-
- npm
87-
containerRegistry:
88-
name: $(ACR_NAME)
89-
clientId: $(ACR_CLIENTID)
90-
- template: containers/container-template.jobs.yaml
91-
parameters:
92-
arch: arm64
93-
os: linux
94-
images:
95-
- azure-ipam
96-
- cni
97-
- cns
98-
- ipv6-hp-bpf
99-
- npm
100-
containerRegistry:
101-
name: $(ACR_NAME)
102-
clientId: $(ACR_CLIENTID)
103-
- template: containers/container-template.jobs.yaml
104-
parameters:
105-
arch: amd64
106-
os: windows
107-
images:
108-
- azure-ipam
109-
- cni
110-
- cns
111-
- npm
112-
containerRegistry:
113-
name: $(ACR_NAME)
114-
clientId: $(ACR_CLIENTID)
76+
templateContext:
77+
buildArch: amd64
78+
buildOs: linux
79+
buildPlatform: linux/amd64
80+
authenticatedContainerRegistries:
81+
- serviceConnection: $(ACR_SERVICECONNECTION)
82+
parameters:
83+
jobs:
84+
- template: containers/container-template.jobs.yaml
85+
parameters:
86+
arch: amd64
87+
os: linux
88+
images:
89+
- azure-ipam
90+
- cni
91+
- cns
92+
- ipv6-hp-bpf
93+
- npm
94+
- template: containers/container-template.jobs.yaml
95+
parameters:
96+
arch: arm64
97+
os: linux
98+
images:
99+
- azure-ipam
100+
- cni
101+
- cns
102+
- ipv6-hp-bpf
103+
- npm
104+
- template: containers/container-template.jobs.yaml
105+
parameters:
106+
arch: amd64
107+
os: windows
108+
images:
109+
- azure-ipam
110+
- cni
111+
- cns
112+
- npm
115113

116114

117115
- stage: publish

0 commit comments

Comments
 (0)