Skip to content

Commit b2e1468

Browse files
Update common Docker engineering infrastructure with latest
1 parent 3afe96c commit b2e1468

32 files changed

+486
-170
lines changed

eng/common/Dockerfile.syft

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARG SYFT_IMAGE_NAME
2+
ARG TARGET_IMAGE_NAME
3+
4+
FROM ${SYFT_IMAGE_NAME} AS syft
5+
FROM ${TARGET_IMAGE_NAME} AS scan-image
6+
7+
FROM syft AS run-scan
8+
ARG TARGET_IMAGE_NAME
9+
ENV SYFT_CHECK_FOR_APP_UPDATE=0 \
10+
SYFT_SOURCE_NAME=${TARGET_IMAGE_NAME}
11+
USER root
12+
RUN --mount=from=scan-image,source=/,target=/rootfs \
13+
["/syft", "scan", "/rootfs/", "--select-catalogers", "image", "--output", "spdx-json=/manifest.spdx.json"]
14+
15+
FROM scratch AS output
16+
COPY --from=run-scan /manifest.spdx.json /manifest.spdx.json

eng/common/Pull-Image.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env pwsh
2+
3+
[cmdletbinding()]
4+
param(
5+
[Parameter(Mandatory = $true, Position = 0)]
6+
[string]$Image,
7+
8+
[Parameter(Mandatory = $false)]
9+
[int]$Retries = 2,
10+
11+
[Parameter(Mandatory = $false)]
12+
[int]$WaitFactor = 6
13+
)
14+
15+
Set-StrictMode -Version Latest
16+
$ErrorActionPreference = 'Stop'
17+
18+
& "$PSScriptRoot/Invoke-WithRetry.ps1" "docker pull $Image" -Retries $Retries -WaitFactor $WaitFactor

eng/common/templates/1es.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# When extending this template, pipelines using a repository resource containing versions files for image caching must
2+
# do the following:
3+
#
4+
# - Do not rely on any source code from the versions repo so as to not circumvent SDL and CG guidelines
5+
# - The versions repo resource must be named `VersionsRepo` to avoid SDL scans
6+
# - The versions repo must be checked out to `$(Build.SourcesDirectory)/versions` to avoid CG scans
7+
#
8+
# If the pipeline is not using a separate repository resource, ensure that there is no source code checked out in
9+
# `$(Build.SourcesDirectory)/versions`, as it will not be scanned.
10+
11+
parameters:
12+
- name: stages
13+
type: stageList
14+
default: []
15+
# List of repositories that will be excluded from SDL scanning. This should
16+
# only be used when including other repos without building their source code.
17+
# E.g. for the dotnet/versions repo.
18+
- name: reposToExcludeFromScanning
19+
type: object
20+
default: []
21+
# The pool that will be used for initializing service connections.
22+
- name: pool
23+
type: object
24+
default:
25+
name: $(default1ESInternalPoolName)
26+
image: $(default1ESInternalPoolImage)
27+
os: linux
28+
# The pool that will be used for SDL jobs.
29+
- name: sourceAnalysisPool
30+
type: object
31+
default:
32+
name: $(defaultSourceAnalysisPoolName)
33+
image: $(defaultSourceAnalysisPoolImage)
34+
os: windows
35+
36+
resources:
37+
repositories:
38+
- repository: 1ESPipelineTemplates
39+
type: git
40+
name: 1ESPipelineTemplates/1ESPipelineTemplates
41+
ref: refs/tags/release
42+
43+
extends:
44+
template: /eng/common/templates/task-prefix-decorator.yml@self
45+
parameters:
46+
baseTemplate: v1/1ES.${{ iif(contains(variables['Build.DefinitionName'], '-official'), 'Official', 'Unofficial') }}.PipelineTemplate.yml@1ESPipelineTemplates
47+
templateParameters:
48+
pool: ${{ parameters.pool }}
49+
sdl:
50+
# Required for unofficial pipelines because we rely on the ManifestGeneratorTask that is
51+
# automatically installed by 1ES pipeline templates
52+
sbom:
53+
enabled: true
54+
binskim:
55+
enabled: true
56+
componentgovernance:
57+
ignoreDirectories: $(Build.SourcesDirectory)/versions
58+
showAlertLink: true
59+
policheck:
60+
enabled: true
61+
${{ if ne(length(parameters.reposToExcludeFromScanning), 0) }}:
62+
sourceRepositoriesToScan:
63+
exclude:
64+
- ${{ each repo in parameters.reposToExcludeFromScanning }}:
65+
- repository: ${{ repo }}
66+
sourceAnalysisPool: ${{ parameters.sourceAnalysisPool }}
67+
tsa:
68+
enabled: true
69+
stages:
70+
- ${{ parameters.stages }}

eng/common/templates/jobs/build-images.yml

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ parameters:
66
buildJobTimeout: 60
77
commonInitStepsForMatrixAndBuild: []
88
customInitSteps: []
9+
publishConfig: null
910
noCache: false
1011
internalProjectName: null
1112
publicProjectName: null
@@ -48,13 +49,13 @@ jobs:
4849
# to escape the single quotes that are in the string which would need to be done outside the context of PowerShell. Since
4950
# all we need is for that value to be in a PowerShell variable, we can get that by the fact that AzDO automatically creates
5051
# the environment variable for us.
51-
$imageBuilderBuildArgs = "$env:IMAGEBUILDERBUILDARGS $(imageBuilder.queueArgs) --image-info-output-path $(imageInfoContainerDir)/$(legName)-image-info.json $(commonMatrixAndBuildOptions)"
52+
$imageBuilderBuildArgs = "$env:IMAGEBUILDERBUILDARGS $env:IMAGEBUILDER_QUEUEARGS --image-info-output-path $(imageInfoContainerDir)/$(legName)-image-info.json $(commonMatrixAndBuildOptions)"
5253
if ($env:SYSTEM_TEAMPROJECT -eq "${{ parameters.internalProjectName }}" -and $env:BUILD_REASON -ne "PullRequest") {
53-
$imageBuilderBuildArgs = "$imageBuilderBuildArgs --repo-prefix $(stagingRepoPrefix) --push"
54+
$imageBuilderBuildArgs = "$imageBuilderBuildArgs --repo-prefix ${{ parameters.publishConfig.buildAcr.repoPrefix }} --push"
5455
}
5556
5657
# If the pipeline isn't configured to disable the cache and a build variable hasn't been set to disable the cache
57-
if ("$(pipelineDisabledCache)" -ne "true" -and $env:NOCACHE -ne "true") {
58+
if ("$(pipelineDisabledCache)" -ne "true" -and "${{ parameters.noCache }}" -ne "true") {
5859
$imageBuilderBuildArgs = "$imageBuilderBuildArgs --image-info-source-path $(versionsBasePath)$(imageInfoVersionsPath)"
5960
}
6061
@@ -66,10 +67,12 @@ jobs:
6667
name: BuildImages
6768
displayName: Build Images
6869
serviceConnections:
70+
# "name" here refers to the argument name, not the service connection name.
71+
# It should probably be changed to "argName".
6972
- name: acr
70-
id: $(build.serviceConnection.id)
71-
tenantId: $(build.serviceConnection.tenantId)
72-
clientId: $(build.serviceConnection.clientId)
73+
id: ${{ parameters.publishConfig.buildAcr.serviceConnection.id }}
74+
tenantId: ${{ parameters.publishConfig.buildAcr.serviceConnection.tenantId }}
75+
clientId: ${{ parameters.publishConfig.buildAcr.serviceConnection.clientId }}
7376
- ${{ if eq(parameters.isInternalServicingValidation, true) }}:
7477
- name: storage
7578
id: $(dotnetstaging.serviceConnection.id)
@@ -86,8 +89,8 @@ jobs:
8689
--architecture $(architecture)
8790
--retry
8891
--digests-out-var 'builtImages'
89-
--acr-subscription '$(acr-staging.subscription)'
90-
--acr-resource-group '$(acr-staging.resourceGroup)'
92+
--acr-subscription '${{ parameters.publishConfig.buildAcr.subscription }}'
93+
--acr-resource-group '${{ parameters.publishConfig.buildAcr.resourceGroup }}'
9194
$(manifestVariables)
9295
$(imageBuilderBuildArgs)
9396
- template: /eng/common/templates/steps/publish-artifact.yml@self
@@ -97,63 +100,27 @@ jobs:
97100
displayName: Publish Image Info File Artifact
98101
internalProjectName: ${{ parameters.internalProjectName }}
99102
publicProjectName: ${{ parameters.publicProjectName }}
100-
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest')) }}:
101-
# The following task depends on the SBOM Manifest Generator task installed on the agent.
102-
# This task is auto-injected by 1ES Pipeline Templates so we don't need to install it ourselves.
103+
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
103104
- powershell: |
104105
$images = "$(BuildImages.builtImages)"
105106
if (-not $images) { return 0 }
106-
107-
# There can be leftover versions of the task left on the agent if it's not fresh. So find the latest version.
108-
$taskDir = $(Get-ChildItem -Recurse -Directory -Filter "ManifestGeneratorTask*" -Path '$(Agent.WorkFolder)')[-1].FullName
109-
110-
# There may be multiple version directories within the task directory. Use the latest.
111-
$taskVersionDir = $(Get-ChildItem -Directory $taskDir | Sort-Object)[-1].FullName
112-
113-
$manifestToolDllPath = $(Get-ChildItem -Recurse -File -Filter "Microsoft.ManifestTool.dll" -Path $taskVersionDir).FullName
114-
115-
# Check whether the manifest task installed its own version of .NET.
116-
# To be more robust, we'll handle varying implementations that it's had.
117-
# First check for a dotnet folder in the task location
118-
$dotnetDir = $(Get-ChildItem -Recurse -Directory -Filter "dotnet-*" -Path $taskVersionDir).FullName
119-
if (-not $dotnetDir) {
120-
# If it's not there, check in the agent tools location
121-
$dotnetDir = $(Get-ChildItem -Recurse -Directory -Filter "*dotnet-*" -Path "$(Agent.ToolsDirectory)").FullName
122-
}
123-
124-
# If the manifest task installed its own version of .NET use that; otherwise it's reusing an existing install of .NET
125-
# which is executable by default.
126-
if ($dotnetDir) {
127-
$dotnetPath = "$dotnetDir/dotnet"
128-
}
129-
else {
130-
$dotnetPath = "dotnet"
131-
}
132-
133-
# Call the manifest tool for each image to produce seperate SBOMs
134-
# Manifest tool docs: https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/secure-supply-chain/custom-sbom-generation-workflows
107+
$syftImageName = "${{ parameters.publishConfig.publicMirrorAcr.server }}/$(imageNames.syft)"
108+
& $(engCommonPath)/Pull-Image.ps1 $syftImageName
135109
$images -Split ',' | ForEach-Object {
136110
echo "Generating SBOM for $_";
137-
$formattedImageName = $_.Replace('$(acr-staging.server)/$(stagingRepoPrefix)', "").Replace('/', '_').Replace(':', '_');
111+
$targetImageName = "$_";
112+
$formattedImageName = $targetImageName.Replace('${{ parameters.publishConfig.buildAcr.server }}/${{ parameters.publishConfig.buildAcr.repoPrefix }}', "").Replace('/', '_').Replace(':', '_');
138113
$sbomChildDir = "$(sbomDirectory)/$formattedImageName";
139114
New-Item -Type Directory -Path $sbomChildDir > $null;
140-
& $dotnetPath "$manifestToolDllPath" `
141-
Generate `
142-
-BuildDropPath '$(Build.ArtifactStagingDirectory)' `
143-
-BuildComponentPath '$(Agent.BuildDirectory)' `
144-
-PackageName '.NET' `
145-
-PackageVersion '$(Build.BuildNumber)' `
146-
-ManifestDirPath $sbomChildDir `
147-
-DockerImagesToScan $_ `
148-
-Verbosity Information
115+
docker build --output=$sbomChildDir -f $(engCommonPath)/Dockerfile.syft --build-arg SYFT_IMAGE_NAME=$syftImageName --build-arg TARGET_IMAGE_NAME=$targetImageName -t syft-sbom $(engCommonPath);
149116
}
150117
displayName: Generate SBOMs
151118
condition: and(succeeded(), ne(variables['BuildImages.builtImages'], ''))
152119
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
153120
- template: /eng/common/templates/jobs/${{ format('../steps/test-images-{0}-client.yml', parameters.dockerClientOS) }}@self
154121
parameters:
155122
condition: ne(variables.testScriptPath, '')
156-
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest')) }}:
123+
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
157124
- template: /eng/common/templates/steps/publish-artifact.yml@self
158125
parameters:
159126
path: $(sbomDirectory)

eng/common/templates/jobs/copy-base-images-staging.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ parameters:
55
- name: pool
66
type: object
77
default: {}
8+
- name: publishConfig
9+
type: object
10+
default: null
811
- name: customInitSteps
912
type: stepList
1013
default: []
@@ -22,12 +25,5 @@ jobs:
2225
pool: ${{ parameters.pool }}
2326
customInitSteps: ${{ parameters.customInitSteps }}
2427
additionalOptions: ${{ parameters.additionalOptions }}
25-
acr:
26-
server: $(acr-staging.server)
27-
serviceConnection:
28-
tenantId: $(internal-mirror.serviceConnection.tenantId)
29-
clientId: $(internal-mirror.serviceConnection.clientId)
30-
id: $(internal-mirror.serviceConnection.id)
31-
subscription: $(acr-staging.subscription)
32-
resourceGroup: $(acr-staging.resourceGroup)
33-
repoPrefix: $(mirrorRepoPrefix)
28+
acr: ${{ parameters.publishConfig.internalMirrorAcr }}
29+
repoPrefix: ${{ parameters.publishConfig.internalMirrorAcr.repoPrefix }}

eng/common/templates/jobs/generate-matrix.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ parameters:
66
isTestStage: false
77
internalProjectName: null
88
noCache: false
9+
publishConfig: null
910
customInitSteps: []
1011
commonInitStepsForMatrixAndBuild: []
1112
sourceBuildPipelineRunId: ""
@@ -20,6 +21,7 @@ jobs:
2021
- ${{ parameters.customInitSteps }}
2122
- template: /eng/common/templates/steps/validate-branch.yml@self
2223
parameters:
24+
publishConfig: ${{ parameters.publishConfig }}
2325
internalProjectName: ${{ parameters.internalProjectName }}
2426
- template: /eng/common/templates/steps/set-image-info-path-var.yml
2527
parameters:
@@ -36,7 +38,7 @@ jobs:
3638
if ("${{ parameters.isTestStage}}" -eq "true") {
3739
$additionalGenerateBuildMatrixOptions = "$additionalGenerateBuildMatrixOptions --image-info $(artifactsPath)/image-info.json"
3840
}
39-
elseif ("$(pipelineDisabledCache)" -ne "true" -and $env:NOCACHE -ne "true" -and "$(trimCachedImagesForMatrix)" -eq "true") {
41+
elseif ("$(pipelineDisabledCache)" -ne "true" -and "${{ parameters.noCache }}" -ne "true" -and "$(trimCachedImagesForMatrix)" -eq "true") {
4042
# If the pipeline isn't configured to disable the cache and a build variable hasn't been set to disable the cache
4143
$additionalGenerateBuildMatrixOptions = "$additionalGenerateBuildMatrixOptions --image-info $(versionsBasePath)$(imageInfoVersionsPath) --trim-cached-images"
4244
}

0 commit comments

Comments
 (0)