Files
docker-login-skydust/action.yml
2024-12-09 08:01:35 +01:00

53 lines
1.8 KiB
YAML

name: Docker login
description: A custom docker login
author: Skydust
# Define your inputs here.
inputs:
user:
description: The username
required: true
pass:
description: The password or API key
required: true
default: ${{ gitea.server_url }}/${{ gitea.repository_owner }}/
registry:
description: The registry to log onto, defaults to the server
required: false
default: ${{ gitea.server_url }}
runs:
using: composite
steps:
- name: Docker login
shell: sh
run: |
source /load-tools.sh
export PREFIXLESS_REGISTRY=$(echo -n "${{ inputs.registry }}" | sed 's/^https\?:\/\///')
write "$(bold_blue)Checking credentials validity for ${PREFIXLESS_REGISTRY}..."
export BASE64_AUTH=$(echo -n "${{ inputs.user }}:${{ inputs.pass }}" | base64 -w 0)
response=$(curl -s -w "\n%{http_code}" \
-H "Authorization: Basic $BASE64_AUTH" \
-H "User-Agent: Docker-Client/20.10.12 (linux)" \
"https://${PREFIXLESS_REGISTRY}/v2/")
http_code=$(echo "$response" | tail -n 1)
response_body=$(echo "$response" | head -n -1)
if [ "$http_code" -eq 200 ]; then
write "$(bold_green)Authentication successful"
else
write "$(bold_red)Authentication failed with HTTP code: $http_code"
write "$(red)Response body:"
write "$(red)$response_body"
if [ "$http_code" -eq 401 ]; then
write "$(yellow)The identifiers are probably wrong"
fi
exit 1
fi
echo "Exporting config"
echo DOCKER_CONFIG_BASE64=$(echo "{\"auths\": {\"${PREFIXLESS_REGISTRY}\": {\"auth\": \"${BASE64_AUTH}\"}}}" | base64 -w 0) >> $GITEA_ENV