Files
docker-login-skydust/action.yml
2024-11-25 19:43:19 +01:00

52 lines
1.7 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: |
export PREFIXLESS_REGISTRY=$(echo -n "${{ inputs.registry }}" | sed 's/^https\?:\/\///')
echo 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
echo "Authentication successful"
else
echo "Authentication failed with HTTP code: $http_code"
echo "Response body:"
echo "$response_body"
if [ "$http_code" -eq 401 ]; then
echo "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