Skip to content

Commit 491101b

Browse files
baldm0mmakminehart
andauthored
Automation: Verify release artifacts on grafana.com (grafana#89197)
* baldm0mma/verify_release/ create verify_release_for_download function * baldm0mma/verify_release/ add name, image, env * baldm0mma/verify_release/ add initial commands * baldm0mma/verify_release/ add deps? * baldm0mma/verify_release/ update location * baldm0mma/verify_release/ add anno to lib-star * bald0mma/verify_release/ update func name to verify_grafanacom_step * baldm0mma/verify_release/ add verify shell script * baldm0mma/verify_release/ add script content, first attempt * baldm0mma/verify_release/ add node image to verify_grafanacom_step * baldm0mma/verify_release/ add gcom secret note * baldm0mma/verify_release/ add sudo to apt-get * baldm0mma/verify_release/ add anno * baldm0mma/verify_release/ add anno to secrets * baldm0mma/verify_release/ update commands to reflect node env image * baldm0mma/verify_release/ update annos * baldm0mma/verify_release/ update tag variable * baldm0mma/verify release/ add whitespace * baldm0mma/verify_releases/ update with no bash loops * baldm0mma/verify_release/ update exit logic * baldm0mma/verify_release/ remove annos * baldm0mma/verify_releasse/ resign and build yml * baldm0mma/verify_release/ remove annos * baldm0mma/verify_release/ update signature * baldm0mma/verify_release/ download curl * baldm0mma/verify_release/ remove temp key folder removal * baldm0mma/verify_release/ account for artifact download time * baldm0mma/verify_release/ add anno * baldm0mma/verify_release/ update location * baldm0mma/verify_release/ update script * baldm0mma/verify_release/ make drone * baldm0mma/verify_release/ update script for oss or ent * baldm0mma/verify_release/ add promotion option * baldm0mma/verify_release/ make drone * Update scripts/drone/events/release.star Co-authored-by: Kevin Minehart <[email protected]> * Update scripts/drone/steps/lib.star Co-authored-by: Kevin Minehart <[email protected]> * Update scripts/drone/steps/lib.star Co-authored-by: Kevin Minehart <[email protected]> * baldm0mma/verify_release/ update drone * Update scripts/drone/events/release.star Co-authored-by: Kevin Minehart <[email protected]> * baldm0mma/verify_release/ update drone * Update scripts/drone/steps/lib.star Co-authored-by: Kevin Minehart <[email protected]> * Apply suggestions from code review Co-authored-by: Kevin Minehart <[email protected]> * baldm0mma/update drone * baldm0mma/verify_release/ update path * baldm0mma/verify_release/ make drone * baldm0mma/update drone * Apply suggestions from code review Co-authored-by: Kevin Minehart <[email protected]> * baldm0mma/verify_release/ update for loop to account for failure * baldm0mma/verify_release/ make drone * baldm0mma/verify_release/ make format-drone * baldm0mma/verify_release/ rem unused var --------- Co-authored-by: Kevin Minehart <[email protected]>
1 parent b075926 commit 491101b

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

.drone.yml

+45-1
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,40 @@ volumes:
29212921
path: /var/run/docker.sock
29222922
name: docker
29232923
---
2924+
clone:
2925+
retries: 3
2926+
depends_on: []
2927+
image_pull_secrets:
2928+
- gcr
2929+
- gar
2930+
kind: pipeline
2931+
name: verify-grafanacom-artifacts
2932+
node:
2933+
type: no-parallel
2934+
platform:
2935+
arch: amd64
2936+
os: linux
2937+
services: []
2938+
steps:
2939+
- commands:
2940+
- apk add curl bash
2941+
- "\n for i in {1..5}; do\n if ./scripts/drone/verify-grafanacom.sh;
2942+
then\n exit 0\n elif [ $i -eq 5 ]; then\n exit
2943+
1\n else\n sleep 60\n fi\n done\n
2944+
\ "
2945+
depends_on: []
2946+
image: node:20.9.0-alpine
2947+
name: verify-grafanacom
2948+
trigger:
2949+
event:
2950+
- promote
2951+
target: verify-grafanacom-artifacts
2952+
type: docker
2953+
volumes:
2954+
- host:
2955+
path: /var/run/docker.sock
2956+
name: docker
2957+
---
29242958
clone:
29252959
retries: 3
29262960
depends_on:
@@ -3001,6 +3035,16 @@ steps:
30013035
from_secret: grafana_api_key
30023036
image: grafana/grafana-ci-deploy:1.3.3
30033037
name: publish-grafanacom
3038+
- commands:
3039+
- apk add curl bash
3040+
- "\n for i in {1..5}; do\n if ./scripts/drone/verify-grafanacom.sh;
3041+
then\n exit 0\n elif [ $i -eq 5 ]; then\n exit
3042+
1\n else\n sleep 60\n fi\n done\n
3043+
\ "
3044+
depends_on:
3045+
- publish-grafanacom
3046+
image: node:20.9.0-alpine
3047+
name: verify-grafanacom
30043048
trigger:
30053049
event:
30063050
- promote
@@ -4952,6 +4996,6 @@ kind: secret
49524996
name: gcr_credentials
49534997
---
49544998
kind: signature
4955-
hmac: ba86e9c1fb16bb20bff8d56f158ea31f32c3e44f6d517a04ae774fc28f9101e7
4999+
hmac: 06f574902baa67d8885abb48e48987f675d7637e30d4b783b3bb84e51b46cdaf
49565000

49575001
...

scripts/drone/events/release.star

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ load(
2121
"remote_alertmanager_integration_tests_steps",
2222
"verify_gen_cue_step",
2323
"verify_gen_jsonnet_step",
24+
"verify_grafanacom_step",
2425
"wire_install_step",
2526
"yarn_install_step",
2627
)
@@ -203,6 +204,7 @@ def publish_packages_pipeline():
203204
publish_linux_packages_step(package_manager = "deb"),
204205
publish_linux_packages_step(package_manager = "rpm"),
205206
publish_grafanacom_step(ver_mode = "release"),
207+
verify_grafanacom_step(),
206208
]
207209

208210
deps = [
@@ -211,6 +213,16 @@ def publish_packages_pipeline():
211213
]
212214

213215
return [
216+
pipeline(
217+
name = "verify-grafanacom-artifacts",
218+
trigger = {
219+
"event": ["promote"],
220+
"target": "verify-grafanacom-artifacts",
221+
},
222+
steps = [
223+
verify_grafanacom_step(depends_on = []),
224+
],
225+
),
214226
pipeline(
215227
name = "publish-packages",
216228
trigger = trigger,

scripts/drone/steps/lib.star

+28
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,34 @@ def publish_grafanacom_step(ver_mode):
11521152
],
11531153
}
11541154

1155+
def verify_grafanacom_step(depends_on = ["publish-grafanacom"]):
1156+
return {
1157+
"name": "verify-grafanacom",
1158+
"image": images["node"],
1159+
"commands": [
1160+
# Download and install `curl` and `bash` - both of which aren't available inside of the `node:{version}-alpine` docker image.
1161+
"apk add curl bash",
1162+
1163+
# There may be a slight lag between when artifacts are uploaded to Google Storage,
1164+
# and when they become available on the website. This `for` loop sould account for that discrepancy.
1165+
# We attempt the verification up to 5 times. If successful, exit the loop with a success (0) status.
1166+
# If any attempt fails, but it's not the final attempt, wait 60 seconds before the next attempt.
1167+
# If the 5th (final) attempt fails, exit with error (1) status.
1168+
"""
1169+
for i in {1..5}; do
1170+
if ./scripts/drone/verify-grafanacom.sh; then
1171+
exit 0
1172+
elif [ $i -eq 5 ]; then
1173+
exit 1
1174+
else
1175+
sleep 60
1176+
fi
1177+
done
1178+
""",
1179+
],
1180+
"depends_on": depends_on,
1181+
}
1182+
11551183
def publish_linux_packages_step(package_manager = "deb"):
11561184
return {
11571185
"name": "publish-linux-packages-{}".format(package_manager),

scripts/drone/verify-grafanacom.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
version=${1:-$TAG}
4+
5+
# Construct the URL based on the provided version and edition
6+
if [ "$EDITION" = "enterprise" ]; then
7+
url="https://grafana.com/api/downloads/grafana-enterprise/versions/$version"
8+
else
9+
url="https://grafana.com/api/downloads/grafana/versions/$version"
10+
fi
11+
12+
# Make a request to the GCOM API to retrieve the artifacts for the specified version. Exit if the request fails.
13+
if ! artifacts=$(curl "$url"); then
14+
echo "Failed to retrieve artifact URLs from Grafana.com API. Please check the API key, authentication, edition, and version."
15+
exit 1
16+
fi
17+
18+
# Use Node.js to parse the JSON response and extract the download URLs
19+
url_string=$(node -e "
20+
const artifacts = JSON.parse(JSON.stringify($artifacts));
21+
const downloadUrls = artifacts.packages.map((package) => package.links.find((link) => link.rel === 'download').href);
22+
console.log(downloadUrls.join(' '));
23+
")
24+
25+
# Convert the url_string to a Bash array
26+
read -r -a urls <<< "$url_string"
27+
28+
# If empty, no artifact URLs were found for the specified version. Exit with an error.
29+
if [ ${#urls[@]} -eq 0 ]; then
30+
echo "No artifact URLs found for version $version. Please check the provided version."
31+
exit 1
32+
fi
33+
34+
# Iterate over the URLs and check the status code of each. If any URL does not return a 200 status code, add it to the failed_urls string.
35+
failed_urls=""
36+
for url in "${urls[@]}"; do
37+
status_code=$(curl -L -s -o /dev/null -w "%{http_code}" "$url")
38+
if [ "$status_code" -ne 200 ]; then
39+
failed_urls+="$url\n"
40+
fi
41+
done
42+
43+
# If any URLs failed, print them and exit with an error.
44+
if [ -n "$failed_urls" ]; then
45+
echo "The following URLs did not return a 200 status code:"
46+
echo "$failed_urls"
47+
exit 1
48+
else
49+
echo "All URLs returned a 200 status code. Download links are valid for version $version."
50+
exit 0
51+
fi

0 commit comments

Comments
 (0)