fix: enhance Portainer API interaction with DNS fallback and improved error handling
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 11s
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 11s
This commit is contained in:
@@ -66,9 +66,17 @@ jobs:
|
|||||||
PORTAINER_HOST=$(printf '%s' "${PORTAINER_BASE_URL}" | sed -E 's#^[a-zA-Z]+://##; s#/.*$##; s/:.*$//')
|
PORTAINER_HOST=$(printf '%s' "${PORTAINER_BASE_URL}" | sed -E 's#^[a-zA-Z]+://##; s#/.*$##; s/:.*$//')
|
||||||
echo "Resolved host target: ${PORTAINER_HOST}"
|
echo "Resolved host target: ${PORTAINER_HOST}"
|
||||||
|
|
||||||
|
PORTAINER_IP=""
|
||||||
|
ACTIVE_PORTAINER_BASE_URL="${PORTAINER_BASE_URL}"
|
||||||
|
|
||||||
if command -v getent >/dev/null 2>&1; then
|
if command -v getent >/dev/null 2>&1; then
|
||||||
echo "Host lookup (getent):"
|
echo "Host lookup (getent):"
|
||||||
getent hosts "${PORTAINER_HOST}" || true
|
getent hosts "${PORTAINER_HOST}" || true
|
||||||
|
PORTAINER_IP=$(getent hosts "${PORTAINER_HOST}" | awk 'NR==1{print $1}')
|
||||||
|
if [ -n "${PORTAINER_IP}" ]; then
|
||||||
|
PORTAINER_IP_BASE_URL="${PORTAINER_BASE_URL/${PORTAINER_HOST}/${PORTAINER_IP}}"
|
||||||
|
echo "Portainer IP fallback URL: ${PORTAINER_IP_BASE_URL}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
STACKS_BODY=$(mktemp)
|
STACKS_BODY=$(mktemp)
|
||||||
@@ -78,11 +86,26 @@ jobs:
|
|||||||
--noproxy "*" \
|
--noproxy "*" \
|
||||||
-o "${STACKS_BODY}" \
|
-o "${STACKS_BODY}" \
|
||||||
-w "%{http_code}" \
|
-w "%{http_code}" \
|
||||||
"${PORTAINER_BASE_URL}/api/stacks" \
|
"${ACTIVE_PORTAINER_BASE_URL}/api/stacks" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
2>"${STACKS_ERR}")
|
2>"${STACKS_ERR}")
|
||||||
STACKS_CURL_EXIT=$?
|
STACKS_CURL_EXIT=$?
|
||||||
|
|
||||||
|
if [ "${STACKS_CURL_EXIT}" -eq 6 ] && [ -n "${PORTAINER_IP:-}" ]; then
|
||||||
|
echo "Retrying GET /api/stacks with IP fallback due to DNS failure"
|
||||||
|
STACKS_HTTP_CODE=$(curl -sS \
|
||||||
|
--noproxy "*" \
|
||||||
|
-o "${STACKS_BODY}" \
|
||||||
|
-w "%{http_code}" \
|
||||||
|
"${PORTAINER_IP_BASE_URL}/api/stacks" \
|
||||||
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
|
2>"${STACKS_ERR}")
|
||||||
|
STACKS_CURL_EXIT=$?
|
||||||
|
if [ "${STACKS_CURL_EXIT}" -eq 0 ]; then
|
||||||
|
ACTIVE_PORTAINER_BASE_URL="${PORTAINER_IP_BASE_URL}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "GET /api/stacks curl exit: ${STACKS_CURL_EXIT}"
|
echo "GET /api/stacks curl exit: ${STACKS_CURL_EXIT}"
|
||||||
echo "GET /api/stacks http code: ${STACKS_HTTP_CODE}"
|
echo "GET /api/stacks http code: ${STACKS_HTTP_CODE}"
|
||||||
echo "GET /api/stacks stderr:"
|
echo "GET /api/stacks stderr:"
|
||||||
@@ -116,7 +139,7 @@ jobs:
|
|||||||
--noproxy "*" \
|
--noproxy "*" \
|
||||||
-o "${APPLY_BODY}" \
|
-o "${APPLY_BODY}" \
|
||||||
-w "%{http_code}" \
|
-w "%{http_code}" \
|
||||||
"${PORTAINER_BASE_URL}/api/stacks/${STACK_ID}?endpointId=${PORTAINER_ENDPOINT_ID}" \
|
"${ACTIVE_PORTAINER_BASE_URL}/api/stacks/${STACK_ID}?endpointId=${PORTAINER_ENDPOINT_ID}" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "${PAYLOAD}" \
|
-d "${PAYLOAD}" \
|
||||||
@@ -134,7 +157,7 @@ jobs:
|
|||||||
--noproxy "*" \
|
--noproxy "*" \
|
||||||
-o "${APPLY_BODY}" \
|
-o "${APPLY_BODY}" \
|
||||||
-w "%{http_code}" \
|
-w "%{http_code}" \
|
||||||
"${PORTAINER_BASE_URL}/api/stacks/create/standalone/string?endpointId=${PORTAINER_ENDPOINT_ID}" \
|
"${ACTIVE_PORTAINER_BASE_URL}/api/stacks/create/standalone/string?endpointId=${PORTAINER_ENDPOINT_ID}" \
|
||||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "${PAYLOAD}" \
|
-d "${PAYLOAD}" \
|
||||||
|
|||||||
Reference in New Issue
Block a user