Fix CICD issue.
All checks were successful
build / test (push) Successful in 1m18s
build / images (collector) (push) Successful in 22s
build / images (web) (push) Successful in 16s

This commit is contained in:
ploush 2026-10-31 23:57:59 +01:00
parent 35823a3972
commit 7a1c1528e7
2 changed files with 118 additions and 11 deletions

View file

@ -9,7 +9,11 @@
# - le secret REGISTRY_TOKEN : jeton d'accès avec la portée write:package ; # - le secret REGISTRY_TOKEN : jeton d'accès avec la portée write:package ;
# - facultatif : la variable REGISTRY_USER (sinon l'auteur du push) ; # - facultatif : la variable REGISTRY_USER (sinon l'auteur du push) ;
# - facultatif : la variable IMAGE_PLATFORM (ex. linux/amd64) si l'architecture # - facultatif : la variable IMAGE_PLATFORM (ex. linux/amd64) si l'architecture
# du serveur diffère de celle du runner. # du serveur diffère de celle du runner ;
# - facultatif : la variable FORGEJO_INTERNAL_URL (ex. http://forgejo:3000) si
# les jobs doivent joindre Forgejo (code et registre) par une adresse interne
# plutôt que par son URL publique (ROOT_URL). Le serveur de production tire
# toujours les images par l'URL publique : c'est le même registre.
name: build name: build
@ -37,19 +41,17 @@ jobs:
--health-timeout 5s --health-timeout 5s
--health-retries 10 --health-retries 10
env: env:
PGHOST: postgres
PGUSER: postgres PGUSER: postgres
PGPASSWORD: ci-superuser PGPASSWORD: ci-superuser
TEST_OWNER_URL: postgresql://shortstats_owner:remplacer-mdp-owner@postgres:5432/shortstats
TEST_COLLECTOR_URL: postgresql://shortstats_collector:remplacer-mdp-collector@postgres:5432/shortstats
TEST_WEB_URL: postgresql://shortstats_web:remplacer-mdp-web@postgres:5432/shortstats
steps: steps:
- name: Récupérer le code - name: Récupérer le code
env: env:
TOKEN: ${{ github.token }} TOKEN: ${{ github.token }}
INTERNAL_URL: ${{ vars.FORGEJO_INTERNAL_URL }}
run: | run: |
base="${INTERNAL_URL:-$GITHUB_SERVER_URL}"
git init -q . git init -q .
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" git remote add origin "${base%/}/${GITHUB_REPOSITORY}.git"
auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w0) auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)
git -c "http.extraHeader=Authorization: Basic ${auth}" fetch -q --depth 1 origin "${GITHUB_SHA}" git -c "http.extraHeader=Authorization: Basic ${auth}" fetch -q --depth 1 origin "${GITHUB_SHA}"
git checkout -q FETCH_HEAD git checkout -q FETCH_HEAD
@ -59,13 +61,32 @@ jobs:
apt-get update -qq && apt-get install -y -qq --no-install-recommends postgresql-client >/dev/null apt-get update -qq && apt-get install -y -qq --no-install-recommends postgresql-client >/dev/null
pip install -q --constraint constraints.txt ".[collector,web,dev]" pip install -q --constraint constraints.txt ".[collector,web,dev]"
- name: Trouver le service PostgreSQL
run: |
# Réseau dédié au job : le service se nomme « postgres ».
# Runner en `container.network: host` (fréquent en docker-in-docker) :
# le nom n'est pas résolu, le service écoute sur 127.0.0.1.
# On essaie les deux pendant 60 s et on garde celui qui répond.
for _ in $(seq 1 30); do
for h in postgres 127.0.0.1; do
if pg_isready -q -h "$h" -p 5432 2>/dev/null; then
echo "PGHOST=${h}" >> "$GITHUB_ENV"; echo "PostgreSQL trouvé sur : ${h}"; exit 0
fi
done
sleep 2
done
echo "PostgreSQL injoignable par « postgres » et par 127.0.0.1" >&2; exit 1
- name: Créer la base avec le script SQL minimal - name: Créer la base avec le script SQL minimal
run: | run: |
for _ in $(seq 1 30); do pg_isready -q && break; sleep 2; done
psql -v ON_ERROR_STOP=1 -f sql/bootstrap.sql psql -v ON_ERROR_STOP=1 -f sql/bootstrap.sql
- name: Tests - name: Tests
run: pytest -q run: |
export TEST_OWNER_URL="postgresql://shortstats_owner:remplacer-mdp-owner@${PGHOST}:5432/shortstats"
export TEST_COLLECTOR_URL="postgresql://shortstats_collector:remplacer-mdp-collector@${PGHOST}:5432/shortstats"
export TEST_WEB_URL="postgresql://shortstats_web:remplacer-mdp-web@${PGHOST}:5432/shortstats"
pytest -q
images: images:
needs: test needs: test
@ -83,17 +104,25 @@ jobs:
- name: Récupérer le code - name: Récupérer le code
env: env:
TOKEN: ${{ github.token }} TOKEN: ${{ github.token }}
INTERNAL_URL: ${{ vars.FORGEJO_INTERNAL_URL }}
run: | run: |
base="${INTERNAL_URL:-$GITHUB_SERVER_URL}"
git init -q . git init -q .
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" git remote add origin "${base%/}/${GITHUB_REPOSITORY}.git"
auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w 0) auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w 0)
git -c "http.extraHeader=Authorization: Basic ${auth}" fetch -q --depth 1 origin "${GITHUB_SHA}" git -c "http.extraHeader=Authorization: Basic ${auth}" fetch -q --depth 1 origin "${GITHUB_SHA}"
git checkout -q FETCH_HEAD git checkout -q FETCH_HEAD
- name: Calculer le nom et les étiquettes de l'image - name: Calculer le nom et les étiquettes de l'image
id: meta id: meta
env:
INTERNAL_URL: ${{ vars.FORGEJO_INTERNAL_URL }}
run: | run: |
registry=$(echo "${GITHUB_SERVER_URL}" | sed -E 's#^https?://##; s#/.*$##') host_of() { echo "$1" | sed -E 's#^https?://##; s#/.*$##'; }
# Registre utilisé par le runner pour pousser, et registre public que le
# serveur utilisera pour tirer (identiques sauf si FORGEJO_INTERNAL_URL est défini).
registry=$(host_of "${INTERNAL_URL:-$GITHUB_SERVER_URL}")
public_registry=$(host_of "${GITHUB_SERVER_URL}")
owner=$(echo "${GITHUB_REPOSITORY%%/*}" | tr '[:upper:]' '[:lower:]') owner=$(echo "${GITHUB_REPOSITORY%%/*}" | tr '[:upper:]' '[:lower:]')
image="${registry}/${owner}/shortstats-${{ matrix.target }}" image="${registry}/${owner}/shortstats-${{ matrix.target }}"
short_sha=$(echo "${GITHUB_SHA}" | cut -c1-12) short_sha=$(echo "${GITHUB_SHA}" | cut -c1-12)
@ -108,6 +137,7 @@ jobs:
case "${GITHUB_REF}" in refs/tags/v*) version="${GITHUB_REF_NAME#v}" ;; esac case "${GITHUB_REF}" in refs/tags/v*) version="${GITHUB_REF_NAME#v}" ;; esac
{ {
echo "registry=${registry}" echo "registry=${registry}"
echo "public_registry=${public_registry}"
echo "owner=${owner}" echo "owner=${owner}"
echo "image=${image}" echo "image=${image}"
echo "tags=${tags}" echo "tags=${tags}"
@ -148,7 +178,7 @@ jobs:
echo "Architecture : $(docker image inspect --format '{{.Os}}/{{.Architecture}}' "${first_tag}")" echo "Architecture : $(docker image inspect --format '{{.Os}}/{{.Architecture}}' "${first_tag}")"
echo "Empreinte : $(docker image inspect --format '{{index .RepoDigests 0}}' "${first_tag}")" echo "Empreinte : $(docker image inspect --format '{{index .RepoDigests 0}}' "${first_tag}")"
echo "Dans le .env du dossier de déploiement :" echo "Dans le .env du dossier de déploiement :"
echo " IMAGE_PREFIX=${{ steps.meta.outputs.registry }}/${{ steps.meta.outputs.owner }}" echo " IMAGE_PREFIX=${{ steps.meta.outputs.public_registry }}/${{ steps.meta.outputs.owner }}"
echo " IMAGE_TAG=${{ steps.meta.outputs.version }}" echo " IMAGE_TAG=${{ steps.meta.outputs.version }}"
- name: Déconnexion - name: Déconnexion

View file

@ -0,0 +1,77 @@
# Vérification du runner, à lancer à la main (Actions > runner-check > Lancer le workflow)
# après avoir ajouté le label `docker` : contrôle tout ce dont a besoin build.yaml,
# sans rien construire ni publier.
name: runner-check
on:
workflow_dispatch:
jobs:
docker-cli:
# Le job `images` de build.yaml exécute docker build / docker push.
runs-on: docker
container:
image: docker:29-cli
steps:
- name: Accès au démon Docker depuis le job
run: |
echo "DOCKER_HOST=${DOCKER_HOST:-<non défini>}"
docker version
docker buildx version
docker info --format 'Démon : {{.ServerVersion}}, architecture {{.Architecture}}'
- name: Connexion au registre (même calcul que build.yaml)
env:
INTERNAL_URL: ${{ vars.FORGEJO_INTERNAL_URL }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
REGISTRY_USER: ${{ vars.REGISTRY_USER || github.actor }}
run: |
registry=$(echo "${INTERNAL_URL:-$GITHUB_SERVER_URL}" | sed -E 's#^https?://##; s#/.*$##')
public=$(echo "${GITHUB_SERVER_URL}" | sed -E 's#^https?://##; s#/.*$##')
echo "URL publique (ROOT_URL) : ${GITHUB_SERVER_URL}"
echo "Registre pour pousser : ${registry}"
echo "Registre pour le serveur: ${public}"
if [ -z "${REGISTRY_TOKEN}" ]; then
echo "Secret REGISTRY_TOKEN absent : connexion non testée." && exit 1
fi
printf '%s' "$REGISTRY_TOKEN" | docker login "$registry" -u "$REGISTRY_USER" --password-stdin
docker logout "$registry"
service:
# Le job `test` de build.yaml utilise un service PostgreSQL et récupère le code par git.
runs-on: docker
container:
image: python:3.13-trixie
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_PASSWORD: verif
steps:
- name: Joindre le service PostgreSQL
env:
PGUSER: postgres
PGPASSWORD: verif
run: |
apt-get update -qq && apt-get install -y -qq --no-install-recommends postgresql-client >/dev/null
host=""
for _ in $(seq 1 30); do
for h in postgres 127.0.0.1; do
if pg_isready -q -h "$h" -p 5432 2>/dev/null; then host="$h"; break 2; fi
done
sleep 2
done
[ -n "$host" ] || { echo "PostgreSQL injoignable par « postgres » et par 127.0.0.1" >&2; exit 1; }
echo "PostgreSQL trouvé sur : ${host}"
psql -h "$host" -tAc 'select version()'
- name: Récupérer le code (même méthode que build.yaml)
env:
TOKEN: ${{ github.token }}
INTERNAL_URL: ${{ vars.FORGEJO_INTERNAL_URL }}
run: |
base="${INTERNAL_URL:-$GITHUB_SERVER_URL}"
echo "Dépôt : ${base%/}/${GITHUB_REPOSITORY}.git"
auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)
git -c "http.extraHeader=Authorization: Basic ${auth}" ls-remote "${base%/}/${GITHUB_REPOSITORY}.git" HEAD