Список образов Docker в реджестри GitLab.
Этот метод напрямую обращается к реджестри GitLab.
Создайте персональный токен доступа с областью read_registry.
Создайте shell скрипт, который будет использоваться для доступа к реестру GitLab.
Для этого потребуются утилиты командной строки curl и jq.
#!/usr/bin/env bash
# Display GitLab registry containers
#
# Create Personal Access Token with read_registry scope
#
# Define shell variables:
# export GITLAB_USERNAME=milosz
# export GITLAB_TOKEN="glpat-qhP3QBpSMXLUysvserXY"
# export GITLAB_ADDRESS="https://gitlab.example.org"
# export GITLAB_REGISTRY_ADDRESS="https://registry.example.org"
# Check required shell variables
if [ -n "$GITLAB_USERNAME" ] && [ -n "$GITLAB_TOKEN" ] && [ -n "$GITLAB_ADDRESS" ]; then
# Check GitLab and its registry addresses
curl --output /dev/null --silent --head --fail "$GITLAB_ADDRESS" || { echo "GitLab is not responding"; exit 1; }
curl --output /dev/null --silent --head --fail "$GITLAB_REGISTRY_ADDRESS" || { echo "Registry is not responding"; exit 1; }
# Get JWT token that grants access to registry catalog
token="$(curl --silent --request GET --user "${GITLAB_USERNAME}:${GITLAB_TOKEN}" \
"${GITLAB_ADDRESS}/jwt/auth?service=container_registry&scope=registry:catalog:*" | \
jq --raw-output .token)"
if [ -n "$token" ] && [ "$token" != "null" ]; then
# Get repositories
repositories="$(curl --silent --header "Authorization: Bearer $token" \
"${GITLAB_REGISTRY_ADDRESS}/v2/_catalog" | \
jq --raw-output ".repositories[]")"
for repository in $repositories; do
echo "Repository: $repository"
# Get JWT token that grants pull access to the specific repository
token="$(curl --silent --request GET --user "${GITLAB_USERNAME}:${GITLAB_TOKEN}" \
"${GITLAB_ADDRESS}/jwt/auth?service=container_registry&scope=repository:{$repository}:pull" | \
jq --raw-output .token)"
if [ -n "$token" ] && [ "$token" != "null" ]; then
# Get tags
tags="$(curl --silent --header "Authorization: Bearer $token" \
"https://registry.awesomebeastie.eu/v2/${repository}/tags/list" | \
jq --raw-output .tags[])"
echo "Tagged:"
for tag in $tags; do
echo " - $tag"
done
echo
else
echo "Unable to retrieve the JWT token. Please verify your credentials and try again."
fi
done
else
echo "Unable to retrieve the JWT token. Please verify your credentials and try again."
fi
fi
Экспортируйте необходимые переменные оболочки.
export GITLAB_USERNAME=milosz export GITLAB_TOKEN="glpat-qhP3QBpSMXLUysvserXY" export GITLAB_ADDRESS="https://gitlab.example.org" export GITLAB_REGISTRY_ADDRESS="https://registry.example.org"
Выполните его.
$ inspect_registry.sh
Repository: containers/ansible Tagged: - 9.3.0 Repository: containers/hugo Tagged: - 0.122.0-r0 - latest Repository: containers/rust Tagged: - 1.76.0-alpine Repository: sandbox/alpine-cache-nexus Tagged: - utilities Repository: sandbox/alpine-cache Tagged: - basic - utilities
API GitLab предлагает дополнительные подробности, которые мы рассмотрим позже.
см. также:
🦊 GitLab настройка 2FA для всех пользователей
![]()
