Last active
July 17, 2022 21:16
-
-
Save AlexAtkinson/950ed84e7fc37c193fde9b2143104830 to your computer and use it in GitHub Desktop.
Docker: Get total pulls from dockerhub
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
#!/usr/bin/env bash | |
# get-total-pulls.sh | |
# ------------------------------------------------------------------------------ | |
# | |
# DESCRIPTION: | |
# Gets the total pulls for a dockerhub repo. | |
# This script iterates the image-list file and outputs a report. | |
# | |
# INPUT FILE: | |
# The input file is a list of docker images - one per line. | |
# Example: | |
# debian:latest | |
# ubuntu:latest | |
# centos:latest | |
# fedora:latest | |
# archlinux:latest | |
# opensuse/leap:latest | |
# rockylinux:latest | |
# almalinux:latest | |
# ------------------------------------------------------------------------------ | |
function get-total-pulls() { | |
curl -s https://hub.docker.com/v2/repositories/$image | \ | |
jq -r '(paths(scalars) | select(.[-1] == "pull_count")) as $p | [ ( [ $p[] | tostring ] | join(".") ) , ( getpath($p) | tojson ) ] | join(": ")' | \ | |
awk '{s+=$2} END {print s}' | \ | |
xargs printf "%'d" | |
} | |
width=30 | |
echo "TOTAL PULLS:" | |
echo "------------" | |
for image in $(cat image-list | awk -F: '{print $1}'); do | |
pulls=$(get-total-pulls) | |
printf "%s" "$image" | |
printf "%*s" "$((${COLUMNS}-$((${COLUMNS}-$(wc -c<<<${image}${pulls})+${width}))))" # | tr ' ' - | |
printf "%s\n" "${pulls}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment