From 7932f0f8fc45529eebcf37ef7d30529a7cfabc98 Mon Sep 17 00:00:00 2001 From: Skydust Date: Mon, 25 Nov 2024 14:09:45 +0100 Subject: [PATCH] Remove the usage of docker --- .gitignore | 1 + action.yml | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/action.yml b/action.yml index 2092306..9a689fd 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,30 @@ runs: - name: Docker login shell: sh run: | - export PREFIXLESS_REGISTRY=$(echo "${{ inputs.registry }}" | sed 's/^https\?:\/\///') - echo "${{ inputs.pass }}" | docker login "$PREFIXLESS_REGISTRY" -u ${{ inputs.user }} --password-stdin - echo "DOCKER_CONFIG_BASE64=$(base64 -w 0 < "$HOME/.docker/config.json")" >> $GITEA_ENV + 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