forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatically publish readme to docker hub (jaegertracing#6118)
## Which problem is this PR solving? Fixes: jaegertracing#3842 ## Description of the changes - Added a shell script that publishes README.md files along with docker images to docker hub ## How was this change tested? - Locally as well as on fork ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` --------- Signed-off-by: Meet Soni <[email protected]> Signed-off-by: Yuri Shkuro <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]>
- Loading branch information
1 parent
f5575e2
commit 85d558d
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2024 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -euxf -o pipefail | ||
|
||
usage() { | ||
echo "Usage: $0 <repository_name> <file_path>" | ||
exit 1 | ||
} | ||
|
||
if [ "$#" -ne 2 ]; then | ||
echo "Error: Missing arguments." | ||
usage | ||
fi | ||
|
||
repo="$1" | ||
readme_path="$2" | ||
abs_readme_path=$(realpath "$readme_path") | ||
repository="jaegertracing/$repo" | ||
|
||
DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:?'missing Docker Hub token'} | ||
QUAY_TOKEN=${QUAY_TOKEN:?'missing Quay token'} | ||
|
||
dockerhub_url="https://hub.docker.com/v2/repositories/$repository/" | ||
quay_url="https://quay.io/api/v1/repository/${repository}" | ||
|
||
if [ ! -f "$abs_readme_path" ]; then | ||
echo "❗Warning: no README file found at path $abs_readme_path" | ||
echo "It is recommended to have a dedicated README file for each Docker image" | ||
exit 0 | ||
fi | ||
|
||
readme_content=$(<"$abs_readme_path") | ||
|
||
set +x | ||
|
||
# Handling DockerHUB upload | ||
# encode readme as properly escaped JSON | ||
body=$(jq -n \ | ||
--arg full_desc "$readme_content" \ | ||
'{full_description: $full_desc}') | ||
|
||
dockerhub_response=$(curl -s -w "%{http_code}" -X PATCH "$dockerhub_url" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: JWT $DOCKERHUB_TOKEN" \ | ||
-d "$body") | ||
|
||
http_code="${dockerhub_response: -3}" | ||
response_body="${dockerhub_response:0:${#dockerhub_response}-3}" | ||
|
||
if [ "$http_code" -eq 200 ]; then | ||
echo "Successfully updated Docker Hub README for $repository" | ||
else | ||
echo "🛑 Failed to update Docker Hub README for $repository with status code $http_code" | ||
echo "Full response: $response_body" | ||
fi | ||
|
||
# Handling Quay upload | ||
# encode readme as properly escaped JSON | ||
quay_body=$(jq -n \ | ||
--arg full_desc "$readme_content" \ | ||
'{description: $full_desc}') | ||
|
||
quay_response=$(curl -s -w "%{http_code}" -X PUT "$quay_url" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $QUAY_TOKEN" \ | ||
-d "$quay_body") | ||
|
||
quay_http_code="${quay_response: -3}" | ||
quay_response_body="${quay_response:0:${#quay_response}-3}" | ||
|
||
if [ "$quay_http_code" -eq 200 ]; then | ||
echo "Successfully updated Quay.io README for $repository" | ||
else | ||
echo "Failed to update Quay.io README for $repository with status code $quay_http_code" | ||
echo "Full response: $quay_response_body" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) 2024 The Jaeger Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -euo pipefail | ||
|
||
# Mock variables | ||
dockerhub_repository="jaegertracing/test-docker" | ||
http_code="" | ||
response_body="" | ||
|
||
simulate_update() { | ||
local status=$1 | ||
if [ "$status" -eq 200 ]; then | ||
http_code=200 | ||
response_body="Successfully updated README." | ||
else | ||
http_code="$status" | ||
response_body="Error: Unable to update README." | ||
fi | ||
} | ||
|
||
# Test 1: Successful update | ||
echo "Running test: Successful update" | ||
simulate_update 200 | ||
if [ "$http_code" -eq 200 ]; then | ||
echo "Successfully updated Docker Hub README for $dockerhub_repository" | ||
else | ||
echo "Failed to update Docker Hub README for $dockerhub_repository with status code $http_code" | ||
echo "Full response: $response_body" | ||
fi | ||
|
||
# Test 2: Failed update | ||
echo "Running test: Failed update" | ||
simulate_update 403 | ||
if [ "$http_code" -eq 200 ]; then | ||
echo "Successfully updated Docker Hub README for $dockerhub_repository" | ||
else | ||
echo "Failed to update Docker Hub README for $dockerhub_repository with status code $http_code" | ||
echo "Full response: $response_body" | ||
fi |