|
1 | 1 | parameters: |
| 2 | +- name: jobs |
| 3 | + type: jobList |
| 4 | + default: [] |
| 5 | + |
2 | 6 | - name: arch |
3 | 7 | type: string |
4 | | - default: "" |
5 | | - values: |
6 | | - - amd64 |
7 | | - - arm64 |
8 | 8 |
|
9 | 9 | - name: os |
10 | 10 | type: string |
11 | | - default: "" |
12 | | - values: |
13 | | - - windows |
14 | | - - linux |
15 | 11 |
|
16 | 12 | - name: images |
17 | 13 | type: object |
18 | | - |
19 | | -- name: containerRegistry |
20 | | - type: object |
| 14 | + default: [] |
21 | 15 |
|
22 | 16 |
|
23 | 17 | 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 }}" |
0 commit comments