Skip to content

Commit c11596f

Browse files
authored
[serverless] Upload serverless assets to Azure so we can release for a layer (#6561)
## Summary of changes Compiles the serverless assets to an artifact, uploads them, and uses those when building the layer for a release ## Reason for change The serverless layer has been unable to build for a while for releases. The SSI artifacts (which similarly build in gitlab) pull the assets from the GitHub release page, but we're hesitant to add the serverless assets there, because of the risk of confusion for customers. As a workaround, we upload the assets to a public blob store that can be pulled from later. Various other workflows already use this store, so this is just adding an additional asset, and sidesteps the issue. ## Implementation details - Remove the "aggregation" logic out of GitLab (which chooses _which_ artifacts are required) - Add a new stage to AzDo that does the aggregation logic for the required artifacts. - Upload the artifact as a zip file to Azure - In gitlab, pull either directly from azdo (for build branches) or from Azure (for tag branches) ## Test coverage - [Tested the aggregation and upload here](https://dev.azure.com/datadoghq/dd-trace-dotnet/_build/results?buildId=171807&view=results) - [Tested the pulling from gitlab here](https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-dotnet/-/pipelines/53167864) (using a temporary hack to force calling the tag-related code) ## Other details Supersedes - #6543
1 parent 8fdb243 commit c11596f

File tree

2 files changed

+94
-36
lines changed

2 files changed

+94
-36
lines changed

.azure-pipelines/ultimate-pipeline.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4257,9 +4257,49 @@ stages:
42574257
displayName: Publish ssi artifacts
42584258
artifact: ssi-artifacts
42594259

4260+
- stage: store_serverless_artifacts
4261+
condition: and(succeeded(), eq(variables['isBenchmarksOnlyBuild'], 'False'), eq(variables.isMainRepository, true))
4262+
dependsOn: [build_linux_tracer_r2r, build_arm64_tracer_r2r, build_linux_universal, build_arm64_universal]
4263+
jobs:
4264+
- job: combine
4265+
timeoutInMinutes: 60 #default value
4266+
pool:
4267+
vmImage: ubuntu-latest
4268+
steps:
4269+
- checkout: none
4270+
# Download the files to the expected locations
4271+
- task: DownloadPipelineArtifact@2
4272+
displayName: Download serverless tracer home x64
4273+
inputs:
4274+
artifact: linux-tracer-home-linux-x64-r2r
4275+
path: $(Build.ArtifactStagingDirectory)/x64
4276+
4277+
- task: DownloadPipelineArtifact@2
4278+
displayName: Download serverless universal home x64
4279+
inputs:
4280+
artifact: linux-universal-home-linux-x64
4281+
path: $(Build.ArtifactStagingDirectory)/x64
4282+
4283+
- task: DownloadPipelineArtifact@2
4284+
displayName: Download serverless tracer home arm64
4285+
inputs:
4286+
artifact: linux-tracer-home-linux-arm64-r2r
4287+
path: $(Build.ArtifactStagingDirectory)/arm64
4288+
4289+
- task: DownloadPipelineArtifact@2
4290+
displayName: Download serverless universal home arm64
4291+
inputs:
4292+
artifact: linux-universal-home-linux-arm64
4293+
path: $(Build.ArtifactStagingDirectory)/arm64
4294+
4295+
# publish all tar files as single artifact
4296+
- publish: "$(Build.ArtifactStagingDirectory)"
4297+
displayName: Publish serverless artifacts
4298+
artifact: serverless-artifacts
4299+
42604300
- stage: upload_to_azure
42614301
condition: and(succeeded(), eq(variables['isBenchmarksOnlyBuild'], 'False'), eq(variables.isMainRepository, true))
4262-
dependsOn: [package_windows, package_linux, package_arm64, dotnet_tool, merge_commit_id]
4302+
dependsOn: [package_windows, package_linux, package_arm64, dotnet_tool, merge_commit_id, store_serverless_artifacts]
42634303
variables:
42644304
targetShaId: $[ stageDependencies.merge_commit_id.fetch.outputs['set_sha.sha']]
42654305
targetBranch: $[ stageDependencies.merge_commit_id.fetch.outputs['set_sha.branch']]
@@ -4485,6 +4525,19 @@ stages:
44854525
artifact: windows-msi-x64
44864526
path: $(Build.ArtifactStagingDirectory)
44874527

4528+
# Download the artifacts required by the serverless layer and create the zip file
4529+
# This exapands the directory - but we want a zip file, so re-zip it!
4530+
- task: DownloadPipelineArtifact@2
4531+
displayName: Download serverless artifacts
4532+
inputs:
4533+
artifact: serverless-artifacts
4534+
path: $(Agent.TempDirectory)/serverless-artifacts
4535+
4536+
- bash: |
4537+
cd $(Agent.TempDirectory)/serverless-artifacts
4538+
zip -r $(Build.ArtifactStagingDirectory)/serverless-artifacts.zip .
4539+
displayName: Zip serverless artifacts and store in staging directory
4540+
44884541
- bash: |
44894542
# Write tracer version number to version.txt
44904543
echo "$(tracer_version)" > $(Build.ArtifactStagingDirectory)/version.txt

.gitlab/download-serverless-artifacts.sh

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ set -eo pipefail
1010
target_dir=artifacts
1111
mkdir -p $target_dir
1212

13+
if [ -n "$CI_COMMIT_TAG" ] && [ -n "$CI_COMMIT_SHA" ]; then
14+
echo "Downloading artifacts from Azure"
15+
curl --location --fail \
16+
--output $target_dir/serverless-artifacts.zip \
17+
"https://apmdotnetci.blob.core.windows.net/apm-dotnet-ci-artifacts-master/${CI_COMMIT_SHA}/serverless-artifacts.zip"
18+
19+
# Extract top level artifact
20+
unzip $target_dir/serverless-artifacts.zip -d $target_dir/
21+
rm -f $target_dir/serverless-artifacts.zip
22+
23+
ls -l $target_dir
24+
exit 0
25+
fi
26+
1327
branchName="refs/heads/$CI_COMMIT_BRANCH"
28+
artifactName="serverless-artifacts"
1429

1530
echo "Looking for azure devops PR builds for branch '$branchName' for commit '$CI_COMMIT_SHA' to start"
1631

@@ -32,41 +47,31 @@ fi
3247

3348
echo "Found build with id '$buildId' for commit '$CI_COMMIT_SHA' on branch '$branchName'"
3449

35-
architectures=("x64" "arm64")
36-
for architecture in "${architectures[@]}"; do
37-
echo "Looking for artifacts for architecture '$architecture'"
38-
39-
artifacts=("linux-tracer-home-linux-$architecture-r2r" "linux-universal-home-linux-$architecture")
40-
41-
# Now try to download the artifacts from the build
42-
for artifactName in "${artifacts[@]}"; do
43-
artifactsUrl="https://dev.azure.com/datadoghq/dd-trace-dotnet/_apis/build/builds/$buildId/artifacts?api-version=7.1&artifactName=$artifactName"
44-
45-
# Keep trying to get the artifact for 30 minutes
46-
downloadUrl=""
47-
TIMEOUT=1800
48-
STARTED=0
49-
until (( STARTED == TIMEOUT )) || [ ! -z "${downloadUrl}" ] ; do
50-
echo "Checking for '$artifactName' at '$artifactsUrl'..."
51-
# If the artifact doesn't exist, .resource.downloadUrl will be null, so we filter that out
52-
downloadUrl=$(curl -s $artifactsUrl | jq -r '.resource.downloadUrl | select( . != null )')
53-
sleep 100
54-
(( STARTED += 100 ))
55-
done
56-
(( STARTED < TIMEOUT ))
57-
58-
if [ -z "${downloadUrl}" ]; then
59-
echo "No downloadUrl found after 30 minutes for commit '$CI_COMMIT_SHA' on branch '$branchName'"
60-
exit 1
61-
fi
62-
63-
echo "Downloading '$artifactName' from '$downloadUrl'..."
64-
curl -o $target_dir/artifacts.zip "$downloadUrl"
65-
unzip $target_dir/artifacts.zip -d $target_dir/$architecture
66-
mv $target_dir/$architecture/$artifactName/* $target_dir/$architecture
67-
rm -rf $target_dir/artifacts.zip
68-
rmdir $target_dir/$architecture/$artifactName
69-
done
50+
# Now try to download the artifacts from the build
51+
artifactsUrl="https://dev.azure.com/datadoghq/dd-trace-dotnet/_apis/build/builds/$buildId/artifacts?api-version=7.1&artifactName=$artifactName"
52+
53+
# Keep trying to get the artifact for 40 minutes
54+
TIMEOUT=2400
55+
STARTED=0
56+
until (( STARTED == TIMEOUT )) || [ ! -z "${downloadUrl}" ] ; do
57+
echo "Checking for artifacts at '$artifactsUrl'..."
58+
# If the artifact doesn't exist, .resource.downloadUrl will be null, so we filter that out
59+
downloadUrl=$(curl -s $artifactsUrl | jq -r '.resource.downloadUrl | select( . != null )')
60+
sleep 100
61+
(( STARTED += 100 ))
7062
done
63+
(( STARTED < TIMEOUT ))
64+
65+
if [ -z "${downloadUrl}" ]; then
66+
echo "No downloadUrl found after 30 minutes for commit '$CI_COMMIT_SHA' on branch '$branchName'"
67+
exit 1
68+
fi
69+
70+
echo "Downloading artifacts from '$downloadUrl'..."
71+
curl -o $target_dir/artifacts.zip "$downloadUrl"
72+
unzip $target_dir/artifacts.zip -d $target_dir
73+
mv $target_dir/$artifactName/* $target_dir
74+
rm -rf $target_dir/artifacts.zip
75+
rmdir $target_dir/$artifactName
7176

7277
ls -l $target_dir

0 commit comments

Comments
 (0)