fix: try multiple registry usernames in docker workflow
Some checks failed
docker-images / build-and-push (admin, admin, termi-astro-admin, admin/Dockerfile) (push) Failing after 8s
docker-images / build-and-push (backend, backend, termi-astro-backend, backend/Dockerfile) (push) Failing after 4s
docker-images / build-and-push (frontend, frontend, termi-astro-frontend, frontend/Dockerfile) (push) Failing after 5s
Some checks failed
docker-images / build-and-push (admin, admin, termi-astro-admin, admin/Dockerfile) (push) Failing after 8s
docker-images / build-and-push (backend, backend, termi-astro-backend, backend/Dockerfile) (push) Failing after 4s
docker-images / build-and-push (frontend, frontend, termi-astro-frontend, frontend/Dockerfile) (push) Failing after 5s
This commit is contained in:
@@ -116,6 +116,7 @@ jobs:
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
BUILTIN_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITHUB_ACTOR_NAME: ${{ github.actor }}
|
||||
GITHUB_REPOSITORY_OWNER_NAME: ${{ github.repository_owner }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
@@ -123,21 +124,43 @@ jobs:
|
||||
CUSTOM_REGISTRY_TOKEN="${REGISTRY_TOKEN:-}"
|
||||
BUILTIN_REGISTRY_TOKEN="${BUILTIN_GITEA_TOKEN:-}"
|
||||
ACTOR_USER="${GITHUB_ACTOR_NAME:-}"
|
||||
OWNER_USER="${GITHUB_REPOSITORY_OWNER_NAME:-}"
|
||||
|
||||
if [ -n "${CUSTOM_REGISTRY_TOKEN}" ]; then
|
||||
REGISTRY_USER="${CUSTOM_REGISTRY_USER:-${ACTOR_USER}}"
|
||||
REGISTRY_TOKEN="${CUSTOM_REGISTRY_TOKEN}"
|
||||
else
|
||||
REGISTRY_USER="${ACTOR_USER:-${CUSTOM_REGISTRY_USER}}"
|
||||
REGISTRY_TOKEN="${BUILTIN_REGISTRY_TOKEN}"
|
||||
fi
|
||||
|
||||
if [ -z "${REGISTRY_USER}" ] || [ -z "${REGISTRY_TOKEN}" ]; then
|
||||
if [ -z "${REGISTRY_TOKEN}" ]; then
|
||||
echo "Missing registry credentials: set REGISTRY_USERNAME/REGISTRY_TOKEN, or rely on the built-in GITEA_TOKEN with packages:write permission."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY_HOST}" --username "${REGISTRY_USER}" --password-stdin
|
||||
CANDIDATE_USERS=()
|
||||
for candidate in "${CUSTOM_REGISTRY_USER}" "${ACTOR_USER}" "${OWNER_USER}"; do
|
||||
if [ -n "${candidate}" ] && [[ ! " ${CANDIDATE_USERS[*]} " =~ [[:space:]]${candidate}[[:space:]] ]]; then
|
||||
CANDIDATE_USERS+=("${candidate}")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#CANDIDATE_USERS[@]} -eq 0 ]; then
|
||||
echo "Missing registry username: set REGISTRY_USERNAME or ensure github.actor/repository_owner are available."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LOGIN_OK=0
|
||||
for candidate in "${CANDIDATE_USERS[@]}"; do
|
||||
if echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY_HOST}" --username "${candidate}" --password-stdin; then
|
||||
LOGIN_OK=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${LOGIN_OK}" -ne 1 ]; then
|
||||
echo "Registry login failed for all candidate usernames."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Build image
|
||||
shell: bash
|
||||
|
||||
Reference in New Issue
Block a user