-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from robertej09/dev-gha
Addressing Issue #109
- Loading branch information
Showing
4 changed files
with
187 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
The "desiredImages" file is a plain-text file where each line contains an | ||
Extended Regular Expression (ERE) for a tag of the official tomcat image on | ||
DockerHub, followed by a space (" ") and either a 1 or a 0, denoting whether or | ||
not that pariticular tag is additionally tracked as the "latest" tag. For | ||
example: | ||
|
||
^10\.[0-9]{1,}\.[0-9]{1,}-jdk17-openjdk$ 0 | ||
|
||
Is the tag for tomcat version 10.x.y using the jdk version 17 version of | ||
openjdk. The 0 at the end of the line indicates this won't be pushed to either | ||
GitHub or Docker as "latest." | ||
|
||
Note the "^" and "$" at the beginning and end of the ERE, respecitively. These | ||
are necessary to ensure specificity of the tag. Namely, while you may be wanting | ||
to specify the tag "10.0.12-jdk17-openjdk" with the ERE | ||
10\.[0-9]{1,}\.[0-9]{1,}-jdk17-openjdk, this would also match the following | ||
tags: | ||
|
||
10.0.12-jdk17-openjdk-slim-buster | ||
10.0.12-jdk17-openjdk-slim-bullseye | ||
10.0.12-jdk17-openjdk-slim | ||
10.0.12-jdk17-openjdk-buster | ||
10.0.12-jdk17-openjdk-bullseye |
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,3 @@ | ||
^8\.[0-9]{1,}\.[0-9]{1,}-jdk11-openjdk$ 1 | ||
^10\.[0-9]{1,}\.[0-9]{1,}-jdk17-openjdk$ 0 | ||
^10\.[0-9]{1,}\.[0-9]{1,}-jdk17-temurin-focal$ 0 |
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 |
---|---|---|
@@ -1,30 +1,99 @@ | ||
#!/bin/bash | ||
|
||
# Shamelessly taken from StackOverflow. No need to reinvent the wheel right? | ||
# https://stackoverflow.com/questions/28320134/how-can-i-list-all-tags-for-a-docker-image-on-a-remote-registry | ||
USAGE=" | ||
dockertags -- list all tags for a Docker image in the DockerHub registry \n | ||
\n | ||
INPUTS: \n | ||
./dockertags -u|--user <user> \ \n | ||
-p|--password <password> \ \n | ||
-n|--namespace <namespace> \ \n | ||
-i|--image <image> \ \n | ||
[ -h|--help ] \n | ||
\n | ||
--user: username used for authentication to dockerhub registry \n | ||
--password: password or personal access token \n | ||
--namespace: organization name (e.g. "unidata"); "library" for public repos \n | ||
--image: the name of the image \n | ||
--help: print this help message and exit \n | ||
\n | ||
OUTPUTS: \n | ||
The tags of the desired image, each on a new line. For example: \n | ||
\n | ||
$ ./dockertags --user $USERNAME \ \n | ||
--password $PASSWORD \ \n | ||
--namespace library \ \n | ||
--image $IMAGE \n | ||
\n | ||
tag1 \n | ||
tag2 \n | ||
tag3 \n | ||
" | ||
|
||
if [ $# -lt 1 ] | ||
then | ||
cat << HELP | ||
while [[ $# > 0 ]] | ||
do | ||
key="$1" | ||
case $key in | ||
-u|--user) | ||
USERNAME="$2" | ||
shift # past argument | ||
;; | ||
-p|--password) | ||
PASSWORD="$2" | ||
shift # past argument | ||
;; | ||
-n|--namespace) | ||
NAMESPACE="$2" | ||
shift # past argument | ||
;; | ||
-i|--image) | ||
IMAGE="$2" | ||
shift # past argument | ||
;; | ||
-h|--help) | ||
echo -e $USAGE | ||
exit | ||
;; | ||
esac | ||
shift # past argument or value | ||
done | ||
|
||
dockertags -- list all tags for a Docker image on a remote registry. | ||
# Check if all values were set | ||
[[ -z "$USERNAME" ]] && { echo -e "Must supply a username...Exiting" $USAGE; exit 1; } | ||
[[ -z "$PASSWORD" ]] && { echo -e "Must supply a password...Exiting" $USAGE; exit 1; } | ||
[[ -z "$NAMESPACE" ]] && { echo -e "Must supply a namespace...Exiting" $USAGE; exit 1; } | ||
[[ -z "$IMAGE" ]] && { echo -e "Must supply an image...Exiting" $USAGE; exit 1; } | ||
|
||
EXAMPLE: | ||
- list all tags for ubuntu: | ||
dockertags ubuntu | ||
# Grab a token for authentiting when querying the registry | ||
token=$(curl -Ls -X POST https://hub.docker.com/v2/users/login \ | ||
-H 'Content-Type: application/json' \ | ||
-d "{\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\"}" | jq -r .token) | ||
|
||
- list all php tags containing apache: | ||
dockertags php apache | ||
# Query the registry for the first 100 entries (the maximum page size) | ||
RESPONSE=$(curl -Ls -G \ | ||
--data-urlencode "page_size=100" \ | ||
--data-urlencode "page=1" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
https://hub.docker.com/v2/namespaces/${NAMESPACE}/repositories/${IMAGE}/tags) | ||
|
||
HELP | ||
fi | ||
# Parse using jq | ||
TAGS=$(echo $RESPONSE | jq '.results[].name') | ||
|
||
image="$1" | ||
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'` | ||
# If more than 100 tags exist in the repository, we must loop through all pages | ||
# using the "next" field of the JSON response | ||
let PAGE=1 | ||
NEXTURL=$(echo $RESPONSE | jq '.next') | ||
|
||
if [ -n "$2" ] | ||
then | ||
tags=` echo "${tags}" | grep "$2" ` | ||
fi | ||
while [[ "${NEXTURL}" != "null" ]]; | ||
do | ||
let PAGE+=1 | ||
RESPONSE=$(curl -Ls -G \ | ||
--data-urlencode "page_size=100" \ | ||
--data-urlencode "page=$PAGE" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
https://hub.docker.com/v2/namespaces/${NAMESPACE}/repositories/${IMAGE}/tags) | ||
TAGS+=" $(echo $RESPONSE | jq '.results[].name')" | ||
NEXTURL=$(echo $RESPONSE | jq '.next') | ||
done | ||
|
||
echo "${tags}" | ||
# Print each tag on its own line and remove quotes (") from around each tag | ||
printf '%s\n' $TAGS | sed -e 's/"//g' |
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