|
1 | 1 | parameters: |
2 | | -- name: supportedPlatforms |
3 | | - type: jobList |
| 2 | + |
| 3 | +- name: images |
| 4 | + type: object |
4 | 5 | default: [] |
5 | 6 |
|
6 | 7 | - name: targetOs |
7 | 8 | type: string |
| 9 | + default: linux |
| 10 | + values: |
| 11 | + - linux |
| 12 | + - windows |
8 | 13 |
|
9 | 14 | - name: targetArch |
10 | 15 | type: string |
11 | | - |
12 | | - |
13 | | -- name: buildPlatform |
14 | | - type: string |
15 | | - default: '' |
| 16 | + default: amd64 |
| 17 | + values: |
| 18 | + - amd64 |
| 19 | + - arm64 |
16 | 20 |
|
17 | 21 | - name: buildOs |
18 | 22 | type: string |
| 23 | + default: linux |
19 | 24 | values: |
20 | 25 | - linux |
21 | 26 | - windows |
22 | 27 |
|
23 | 28 | - name: buildArch |
24 | 29 | type: string |
| 30 | + default: amd64 |
25 | 31 | values: |
26 | 32 | - amd64 |
27 | 33 | - arm64 |
28 | 34 |
|
| 35 | +- name: buildVariablesStepTemplate |
| 36 | + type: string |
| 37 | + default: '' |
| 38 | + |
29 | 39 |
|
30 | 40 | jobs: |
31 | | -- ${{ each supportedPlatformJob in parameters.supportedPlatforms }}: |
32 | | - - ${{ each imageName in supportedPlatformJob.images }}: |
33 | | - - job: ${{ replace(concat(imageName, '_', supportedPlatformJob.name), '-', '_') }} |
34 | | - displayName: Build Image - (${{ imageName }} ${{ parameters.targetOs }}/${{ parameters.targetArch }}) |
35 | | - steps: |
36 | | - - checkout: self |
37 | | - |
38 | | - - task: GoTool@0 |
39 | | - inputs: |
40 | | - version: $(GO_VERSION) |
41 | | - |
42 | | - - bash: | |
43 | | - set -e |
44 | | - |
45 | | - VAR_ID="${IMAGE}_${OS}_${ARCH}" |
46 | | - |
47 | | - BUILD_CONTEXT=$(make "$MAKE_BUILD_CONTEXT") |
48 | | - echo >&2 "##vso[task.setvariable variable=BUILD_CONTEXT_${VAR_ID};]$BUILD_CONTEXT" |
49 | | - |
50 | | - IMAGE_PLATFORM_TAG=$(make "$MAKE_IMAGE_TAG") |
51 | | - echo >&2 "##vso[task.setvariable variable=IMAGE_PLATFORM_TAG_${VAR_ID};]$IMAGE_PLATFORM_TAG" |
52 | | - |
53 | | - IMAGE_NAME_AND_TAG=$(make "$MAKE_IMAGE_NAME_AND_TAG") |
54 | | - echo >&2 "##vso[task.setvariable variable=IMAGE_NAME_AND_TAG_${VAR_ID};]$IMAGE_NAME_AND_TAG" |
55 | | - |
56 | | - DOCKERFILE_PATH=$(make "$MAKE_DOCKERFILE_PATH") |
57 | | - echo >&2 "##vso[task.setvariable variable=DOCKERFILE_PATH_${VAR_ID};]$DOCKERFILE_PATH" |
58 | | - |
59 | | - EXTRA_BUILD_ARGS=$(make "$MAKE_EXTRA_BUILD_ARGS") |
60 | | - echo >&2 "##vso[task.setvariable variable=EXTRA_BUILD_ARGS_${VAR_ID};]$EXTRA_BUILD_ARGS" |
61 | | - displayName: "Get Image Build Data" |
62 | | - env: |
63 | | - IMAGE: ${{ imageName }} |
64 | | - OS: ${{ parameters.targetOs }} |
65 | | - ARCH: ${{ parameters.targetArch }} |
66 | | - PLATFORM: ${{ parameters.targetOs }}/${{ parameters.targetArch }} |
67 | | - MAKE_IMAGE_TAG: ${{ imageName }}-image-tag |
68 | | - MAKE_BUILD_CONTEXT: ${{ imageName }}-image-build-context |
69 | | - MAKE_IMAGE_NAME_AND_TAG: ${{ imageName }}-image-name-and-tag |
70 | | - MAKE_DOCKERFILE_PATH: ${{ imageName }}-dockerfile-path |
71 | | - MAKE_EXTRA_BUILD_ARGS: ${{ imageName }}-docker-build-args |
72 | | - |
73 | | - - template: ./container-template.steps.yaml |
| 41 | +- ${{ each imageName in parameters.images }}: |
| 42 | + - job: ${{ replace(concat(imageName, '_', parameters.), '-', '_') }} |
| 43 | + displayName: Build Image - (${{ imageName }} ${{ parameters.targetOs }}/${{ parameters.targetArch }}) |
| 44 | + variables: |
| 45 | + buildPlatform: ${{ parameters.buildOs }}/${{ parameters.buildArch }} |
| 46 | + targetPlatform: ${{ parameters.targetOs }}/${{ parameters.targetArch }} |
| 47 | + steps: |
| 48 | + - checkout: self |
| 49 | + |
| 50 | + - task: GoTool@0 |
| 51 | + inputs: |
| 52 | + version: $(GO_VERSION) |
| 53 | + |
| 54 | + |
| 55 | + # Requires creation of the following variables: |
| 56 | + # - IMAGE_NAME_AND_TAG_${image}_${OS}_${ARCH}} |
| 57 | + # - DOCKERFILE_PATH_${image}_${OS}_${ARCH}} |
| 58 | + # - IMAGE_PLATFORM_TAG_${image}_${OS}_${ARCH}} |
| 59 | + # - EXTRA_BUILD_ARGS_$${image}_${OS}_${ARCH}} |
| 60 | + - ${{ if parameters.buildVariablesStepTemplate }}: |
| 61 | + - template: ${{ parameters.buildVariablesStepTemplate }} |
74 | 62 | parameters: |
75 | | - imageNameAndTag: $(IMAGE_NAME_AND_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
76 | | - dockerfilePath: $(DOCKERFILE_PATH_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
77 | | - buildContextPath: $(Build.SourcesDirectory) |
78 | | - targetVersion: $(IMAGE_PLATFORM_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
79 | 63 | targetOs: ${{ parameters.targetOs }} |
80 | 64 | targetArch: ${{ parameters.targetArch }} |
81 | | - targetPlatform: "${{ parameters.targetOs }}/${{ parameters.targetArch }}" |
82 | | - addBuildArgs: $(EXTRA_BUILD_ARGS_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
83 | | - buildOs: ${{ supportedPlatformJob.templatContext.buildOs }} |
84 | | - buildArch: ${{ supportedPlatformJob.templateContext.buildArch }} |
85 | | - buildPlatform: "${{ supportedPlatformJob.templatContext.buildOs }}/${{ supportedPlatformJob.templateContext.buildArch }}" |
| 65 | + image: ${{ imageName }} |
| 66 | + |
| 67 | + |
| 68 | + - template: ./container-template.steps.yaml |
| 69 | + parameters: |
| 70 | + imageNameAndTag: $(IMAGE_NAME_AND_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
| 71 | + dockerfilePath: $(DOCKERFILE_PATH_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
| 72 | + buildContextPath: $(Build.SourcesDirectory) |
| 73 | + buildPlatform: $(buildPlatform) |
| 74 | + buildArch: ${{ parameters.buildArch }} |
| 75 | + buildOs: ${{ parameters.buildOs }} |
| 76 | + targetVersion: $(IMAGE_PLATFORM_TAG_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
| 77 | + targetPlatform: $(targetPlatform) |
| 78 | + targetOs: ${{ parameters.targetOs }} |
| 79 | + addBuildArgs: $(EXTRA_BUILD_ARGS_${{ imageName }}_${{ parameters.targetOs }}_${{ parameters.targetArch }}) |
0 commit comments