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/:.*$//')
|
||||
echo "Resolved host target: ${PORTAINER_HOST}"
|
||||
|
||||
PORTAINER_IP=""
|
||||
ACTIVE_PORTAINER_BASE_URL="${PORTAINER_BASE_URL}"
|
||||
|
||||
if command -v getent >/dev/null 2>&1; then
|
||||
echo "Host lookup (getent):"
|
||||
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
|
||||
|
||||
STACKS_BODY=$(mktemp)
|
||||
@@ -78,11 +86,26 @@ jobs:
|
||||
--noproxy "*" \
|
||||
-o "${STACKS_BODY}" \
|
||||
-w "%{http_code}" \
|
||||
"${PORTAINER_BASE_URL}/api/stacks" \
|
||||
"${ACTIVE_PORTAINER_BASE_URL}/api/stacks" \
|
||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||
2>"${STACKS_ERR}")
|
||||
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 http code: ${STACKS_HTTP_CODE}"
|
||||
echo "GET /api/stacks stderr:"
|
||||
@@ -116,7 +139,7 @@ jobs:
|
||||
--noproxy "*" \
|
||||
-o "${APPLY_BODY}" \
|
||||
-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 "Content-Type: application/json" \
|
||||
-d "${PAYLOAD}" \
|
||||
@@ -134,7 +157,7 @@ jobs:
|
||||
--noproxy "*" \
|
||||
-o "${APPLY_BODY}" \
|
||||
-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 "Content-Type: application/json" \
|
||||
-d "${PAYLOAD}" \
|
||||
|
||||
Reference in New Issue
Block a user