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

Extend action functionality #44

Merged
merged 9 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.0
v1.1.0
52 changes: 42 additions & 10 deletions bin/pincher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ skip_check() {
done
}

detect_compose_files() {
compose_files=$(find -name '*compose*.yml' -o -name '*compose*.yaml' -type f)
}

versions_magic() {
skip=false
Expand All @@ -51,7 +54,7 @@ versions_magic() {
git checkout -B "compose/$image"
git pull origin "compose/$image"
# sed compose files on branch
for file in $(find -name '*compose*.yml' -o -name '*compose*.yaml' -type f)
for file in $compose_files
do
if [[ -f "$file" ]]
then
Expand Down Expand Up @@ -86,8 +89,11 @@ versions_magic() {
fi
}

# find all compose files
detect_compose_files

# dockerhub
versions_dockerio=$(yq '.services[].image' ./*compose*.y* | grep docker.io | sort | uniq)
versions_dockerio=$(yq -r '.services[]?.image' $compose_files | grep docker.io | sort | uniq)
for version in $versions_dockerio
do
versions_in_registry=''
Expand All @@ -100,7 +106,7 @@ do
# this registry has some images under library/ those do not match the compose structures
# images such as telegraf, nginx, prometheus, etc
if [[ "$image" != *'/'* ]]
then
then
image_orig="$image"
image="library/$image"
fi
Expand All @@ -125,7 +131,7 @@ do
done

# microsoft mcr
versions_mcr=$(yq '.services[].image' ./*compose*.y* | grep mcr.microsoft.com | sort | uniq)
versions_mcr=$(yq -r '.services[]?.image' $compose_files | grep mcr.microsoft.com | sort | uniq)
for version in $versions_mcr
do
latest_version_in_registry=""
Expand All @@ -134,7 +140,7 @@ do
image=${BASH_REMATCH[1]}
v_rematched=${BASH_REMATCH[2]}
echo "image: $image, v: $v_rematched"

ignore=false
ignore_check # check if image is in ignore_patterns and break
if $ignore
Expand All @@ -149,7 +155,7 @@ do
done

# google gcr
versions_gcr=$(yq '.services[].image' ./*compose*.y* | grep gcr.io | sort | uniq)
versions_gcr=$(yq -r '.services[]?.image' $compose_files | grep gcr.io | sort | uniq)
for version in $versions_gcr
do
latest_version_in_registry=""
Expand All @@ -158,7 +164,7 @@ do
image=${BASH_REMATCH[1]}
v_rematched=${BASH_REMATCH[2]}
echo "image: $image, v: $v_rematched"

ignore=false
ignore_check # check if image is in ignore_patterns and break
if $ignore
Expand All @@ -173,7 +179,7 @@ do
done

# github ghcr
versions_ghcr=$(yq '.services[].image' ./*compose*.y* | grep ghcr.io | sort | uniq)
versions_ghcr=$(yq -r '.services[]?.image' $compose_files | grep ghcr.io | sort | uniq)
for version in $versions_ghcr
do
latest_version_in_registry=""
Expand All @@ -182,7 +188,7 @@ do
image=${BASH_REMATCH[1]}
v_rematched=${BASH_REMATCH[2]}
echo "image: $image, v: $v_rematched"

ignore=false
ignore_check # check if image is in ignore_patterns and break
if $ignore
Expand All @@ -192,14 +198,40 @@ do

# TODO: Private repos require authentication with a PAT or github token
# ghcr_token=$(echo $GITHUB_TOKEN | base64)

ghcr_token=$(curl -s https://ghcr.io/token\?scope\="repository:$image:pull" | jq -r .token)
latest_version_in_registry="$(curl -H "Authorization: Bearer ${ghcr_token}" -s https://ghcr.io/v2/$image/tags/list | jq -r '.tags[]' | sort -V -t. -k1,1 -k2,2 -k3,3 | grep -oP '^v?[0-9]+\.[0-9]+\.[0-9]+$' | tail -n 1)"

# the magic
[ -n "$latest_version_in_registry" ] && versions_magic
done

# quay.io
versions_quay=$(yq -r '.services[]?.image' $compose_files | grep quay.io | sort | uniq)
for version in $versions_quay
do
latest_version_in_registry=""

[[ $version =~ quay.io\/(.*)\:(.*) ]]
image=${BASH_REMATCH[1]}
v_rematched=${BASH_REMATCH[2]}
echo "image: $image, v: $v_rematched"

ignore=false
ignore_check # check if image is in ignore_patterns and break
if $ignore
then
break
fi

# Set page limit to 100 to get more tags to avoids issues
# with images that have many manifests without proper tags like prometheus
latest_version_in_registry="$(curl -s https://quay.io/api/v1/repository/$image/tag/\?limit\=100\&page\=1 | jq -r '.tags[].name' | sort -V -t. -k1,1 -k2,2 -k3,3 | grep -oP '^v?[0-9]+\.[0-9]+\.[0-9]+$' | tail -n 1)"

# the magic
[ -n "$latest_version_in_registry" ] && versions_magic
done

# considerations "how to edit/contribute"
# add each new registry in a separated block loop as per the existing ones
# authentication happens via env_vars in the action block if required
Expand Down
5 changes: 4 additions & 1 deletion compose-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ services:
image: gcr.io/cadvisor/cadvisor:v0.47.1

mcr:
image: mcr.microsoft.com/azure-storage/azurite:3.23.0
image: mcr.microsoft.com/azure-storage/azurite:3.23.0

quay:
image: quay.io/prometheus/node-exporter:v1.6.0
Loading