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: add script to automatically publish readme to docker hub #6118

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

inosmeet
Copy link
Contributor

Which problem is this PR solving?

Fixes: #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

@inosmeet inosmeet requested a review from a team as a code owner October 24, 2024 16:01
@dosubot dosubot bot added the docker Pull requests that update Docker code label Oct 24, 2024
Signed-off-by: Meet Soni <[email protected]>
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.45%. Comparing base (f9474f9) to head (274d927).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6118      +/-   ##
==========================================
- Coverage   96.48%   96.45%   -0.03%     
==========================================
  Files         352      352              
  Lines       19973    20007      +34     
==========================================
+ Hits        19270    19297      +27     
- Misses        520      526       +6     
- Partials      183      184       +1     
Flag Coverage Δ
badger_v1 8.42% <ø> (ø)
badger_v2 1.70% <ø> (ø)
cassandra-4.x-v1 14.57% <ø> (ø)
cassandra-4.x-v2 1.64% <ø> (ø)
cassandra-5.x-v1 14.57% <ø> (ø)
cassandra-5.x-v2 1.64% <ø> (ø)
elasticsearch-6.x-v1 18.73% <ø> (+0.01%) ⬆️
elasticsearch-7.x-v1 18.81% <ø> (+0.01%) ⬆️
elasticsearch-8.x-v1 18.98% <ø> (ø)
elasticsearch-8.x-v2 1.69% <ø> (-0.02%) ⬇️
grpc_v1 8.78% <ø> (ø)
grpc_v2 6.72% <ø> (ø)
kafka-v1 8.99% <ø> (ø)
kafka-v2 1.70% <ø> (ø)
memory_v2 1.70% <ø> (ø)
opensearch-1.x-v1 18.86% <ø> (+0.01%) ⬆️
opensearch-2.x-v1 18.85% <ø> (-0.02%) ⬇️
opensearch-2.x-v2 1.69% <ø> (-0.02%) ⬇️
tailsampling-processor 0.48% <ø> (ø)
unittests 95.37% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Meet Soni <[email protected]>
@inosmeet
Copy link
Contributor Author

Screenshot from 2024-10-24 21-20-58

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for having separate script!

I would prefer this to be called after the Docker image upload was successful. You can set a flag here and call the script after docker buildx build below

readme_path="$2"
abs_readme_path=$(realpath "$readme_path")

DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-}
DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:?'missing Docker Hub token'}


DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-}
dockerhub_repository="jaegertracing/$repo"
dockerhub_url="https://hub.docker.com/v2/repositories/$dockerhub_repository/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: what is the story with the other registries? E.g. we also push to quay.io - does it support similar API for updating the readme?

# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0
set -euxf -o pipefail
repo="$1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add check for number of arguments and log error / usage if args missing


body=$(jq -n \
--arg full_desc "$readme_content" \
'{full_description: $full_desc}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!


set +x

body=$(jq -n \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body=$(jq -n \
# encode readme as properly escaped JSON
body=$(jq -n \

-H "Authorization: JWT $DOCKERHUB_TOKEN" \
-d "$body")

dockerhub_status_code="$dockerhub_response"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you trying to achieve with this assignment?

--arg full_desc "$readme_content" \
'{full_description: $full_desc}')

dockerhub_response=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH "$dockerhub_url" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-o /dev/null

Will it not swallow the output / response, especially in case of an error?

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you include in the description a test that hits this point, to show how the logs look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Pull requests that update Docker code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Publish description and readme to Docker Hub
2 participants