Skip to content

Commit

Permalink
Merge pull request #23 from swissbuechi/add-ghcr.io-support
Browse files Browse the repository at this point in the history
Added support for ghcr.io public images
  • Loading branch information
sbe-arg authored Oct 31, 2023
2 parents 37137ef + f78ee60 commit ad3890d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- `docker.io/somecompany/theimage:x.x.x` (ie, docker.io/grafana/grafana:10.0.1)
- `mcr.microsoft.com/part/theimage:x.x.x` (ie, mcr.microsoft.com/azure-cli:2.50.0)
- `gcr.io/project/image:x.x.x` (ie, gcr.io/cadvisor/cadvisor:v0.47.1)
- `ghcr.io/username/image:x.x.x` (ie, ghcr.io/swissbuechi/one-time-secret:1.0.10)

## what for:

Expand All @@ -65,6 +66,7 @@ jobs:
- dockerhub
- microsoft mcr
- google gcr
- github packages ghcr (public images)
- other? open an issue or open pr

## what does it look like
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.1
v0.2.0
21 changes: 21 additions & 0 deletions bin/pincher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ do
[ -n "$latest_version_in_registry" ] && versions_magic
done

# github ghcr
versions_ghcr=$(yq '.services[].image' ./*compose*.y* | grep ghcr.io | sort | uniq)
for version in $versions_ghcr
do
latest_version_in_registry=""

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

# 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

# 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

0 comments on commit ad3890d

Please sign in to comment.