58 lines
1.5 KiB
Bash
58 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
REGISTRY=${REGISTRY:-git.4nkweb.com}
|
|
NAMESPACE=${NAMESPACE:-4nk}
|
|
DOCKER_TAG=${DOCKER_TAG:-dev-test}
|
|
|
|
echo "[docker] registry=${REGISTRY} namespace=${NAMESPACE} tag=${DOCKER_TAG}"
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "[docker][erreur] docker introuvable" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f .gitmodules ]; then
|
|
echo "[docker][erreur] .gitmodules introuvable dans $(pwd)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Parcourt les submodules déclarés
|
|
mapfile -t submodules < <(git config -f .gitmodules --name-only --get-regexp 'submodule\..*\.path' | sed -E 's/\.path$//')
|
|
|
|
for name in "${submodules[@]}"; do
|
|
path=$(git config -f .gitmodules --get "${name}.path" || true)
|
|
url=$(git config -f .gitmodules --get "${name}.url" || true)
|
|
branch=$(git config -f .gitmodules --get "${name}.branch" || echo "master")
|
|
|
|
if [ -z "${path}" ] || [ -z "${url}" ]; then
|
|
echo "[docker][warn] entrée incomplète pour ${name}, ignoré" >&2
|
|
continue
|
|
fi
|
|
|
|
image_name=$(basename "${path}")
|
|
full_ref="${REGISTRY}/${NAMESPACE}/${image_name}:${DOCKER_TAG}"
|
|
|
|
if [ ! -d "${path}" ]; then
|
|
echo "[docker][warn] sous-dossier ${path} manquant, on saute" >&2
|
|
continue
|
|
fi
|
|
|
|
if [ ! -f "${path}/Dockerfile" ]; then
|
|
echo "[docker] aucun Dockerfile dans ${path}, ignoré"
|
|
continue
|
|
fi
|
|
|
|
echo "[docker] build ${full_ref} depuis ${path} (branche ${branch})"
|
|
docker buildx build \
|
|
--pull \
|
|
--tag "${full_ref}" \
|
|
"${path}"
|
|
|
|
echo "[docker] push ${full_ref}"
|
|
docker push "${full_ref}"
|
|
done
|
|
|
|
echo "[docker] terminé"
|