Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatically publish readme to docker hub #6118

Merged
merged 10 commits into from
Oct 26, 2024
1 change: 1 addition & 0 deletions scripts/build-upload-a-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ else
if [[ "$overwrite" == 'N' ]]; then
check_overwrite "${IMAGE_TAGS[@]}"
fi
bash scripts/upload-docker-readme.sh "${component_name}" "${dir_arg}"/README.md
inosmeet marked this conversation as resolved.
Show resolved Hide resolved
else
echo 'skipping docker images upload, because not on tagged release or main branch'
PUSHTAG="type=image,push=false"
Expand Down
40 changes: 40 additions & 0 deletions scripts/upload-docker-readme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0
set -euxf -o pipefail
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
repo="$1"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
readme_path="$2"
abs_readme_path=$(realpath "$readme_path")

DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-}
inosmeet marked this conversation as resolved.
Show resolved Hide resolved
dockerhub_repository="jaegertracing/$repo"
dockerhub_url="https://hub.docker.com/v2/repositories/$dockerhub_repository/"
inosmeet marked this conversation as resolved.
Show resolved Hide resolved

if [ ! -f "$abs_readme_path" ]; then
echo "Warning: the dedicated README file for Docker image $repo was not found at path $abs_readme_path"
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
echo "It is recommended to have a dedicated README file for each Docker image"
exit 0
fi

readme_content=$(<"$abs_readme_path")

set +x

body=$(jq -n \
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
--arg full_desc "$readme_content" \
'{full_description: $full_desc}')
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

dockerhub_response=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH "$dockerhub_url" \
inosmeet marked this conversation as resolved.
Show resolved Hide resolved
-H "Content-Type: application/json" \
-H "Authorization: JWT $DOCKERHUB_TOKEN" \
-d "$body")

dockerhub_status_code="$dockerhub_response"
inosmeet marked this conversation as resolved.
Show resolved Hide resolved

if [ "$dockerhub_status_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 $dockerhub_status_code"
echo "Full response: $dockerhub_response"
inosmeet marked this conversation as resolved.
Show resolved Hide resolved
fi
Loading