-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced curl with Skopeo for in image functions
- Loading branch information
Showing
3 changed files
with
19 additions
and
92 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 |
---|---|---|
@@ -1,82 +1,17 @@ | ||
#!/bin/bash | ||
# Retrieves image configuration from public images in DockerHub | ||
# Functions from https://gist.github.com/cirocosta/17ea17be7ac11594cb0f290b0a3ac0d1 | ||
# Optimised for our use case | ||
|
||
get_image_label() { | ||
local label=$1 | ||
local image=$2 | ||
local tag=$3 | ||
local token | ||
token=$(_get_token "$image") | ||
local digest | ||
digest=$(_get_digest "$image" "$tag" "$token") | ||
local retval="null" | ||
if [ "$digest" != "null" ]; then | ||
retval=$(_get_image_configuration "$image" "$token" "$digest" "$label") | ||
fi | ||
echo "$retval" | ||
skopeo inspect "docker://$image" | jq -r ".Labels[\"$label\"]" | ||
} | ||
|
||
get_image_layers() { | ||
local image=$1 | ||
local tag=$2 | ||
local token | ||
token=$(_get_token "$image") | ||
_get_layers "$image" "$tag" "$token" | ||
skopeo inspect "docker://$image" | jq -r ".Layers" | ||
} | ||
|
||
get_image_last_layer() { | ||
local image=$1 | ||
local tag=$2 | ||
local token | ||
token=$(_get_token "$image") | ||
local layers | ||
mapfile -t layers < <(_get_layers "$image" "$tag" "$token") | ||
echo "${layers[-1]}" | ||
} | ||
|
||
_get_image_configuration() { | ||
local image=$1 | ||
local token=$2 | ||
local digest=$3 | ||
local label=$4 | ||
curl \ | ||
--silent \ | ||
--location \ | ||
--header "Authorization: Bearer $token" \ | ||
"https://registry-1.docker.io/v2/$image/blobs/$digest" | | ||
jq -r ".config.Labels.\"$label\"" | ||
} | ||
|
||
_get_token() { | ||
local image=$1 | ||
curl \ | ||
--silent \ | ||
"https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" | | ||
jq -r '.token' | ||
} | ||
|
||
_get_digest() { | ||
local image=$1 | ||
local tag=$2 | ||
local token=$3 | ||
curl \ | ||
--silent \ | ||
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ | ||
--header "Authorization: Bearer $token" \ | ||
"https://registry-1.docker.io/v2/$image/manifests/$tag" | | ||
jq -r '.config.digest' | ||
} | ||
|
||
_get_layers() { | ||
local image=$1 | ||
local tag=$2 | ||
local token=$3 | ||
curl \ | ||
--silent \ | ||
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ | ||
--header "Authorization: Bearer $token" \ | ||
"https://registry-1.docker.io/v2/$image/manifests/$tag" | | ||
jq -r '.layers[].digest' | ||
skopeo inspect "docker://$image" | jq -r ".Layers | last" | ||
} |
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
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