From a624d091a04b17a084b9948eff4d89afea0095ef Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Thu, 28 Aug 2025 09:55:40 +0200 Subject: [PATCH] =?UTF-8?q?feat(ci):=20image=20unifi=C3=A9e=20runner+agent?= =?UTF-8?q?s=20(Dockerfile.ci,=20entrypoint,=20compose,=20helper)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursorignore | 1 + .gitignore | 1 + TEMPLATE_VERSION | 1 + docker-compose.ci.yml | 19 +++++++++++ docker/Dockerfile.ci | 26 +++++++++++++++ docker/entrypoint.ci.sh | 51 +++++++++++++++++++++++++++++ scripts/checks/version_alignment.sh | 1 + scripts/dev/run_project_ci.sh | 14 ++++++++ scripts/release/guard.sh | 1 + scripts/security/audit.sh | 1 + 10 files changed, 116 insertions(+) create mode 100644 docker-compose.ci.yml create mode 100644 docker/Dockerfile.ci create mode 100644 docker/entrypoint.ci.sh create mode 100644 scripts/dev/run_project_ci.sh diff --git a/.cursorignore b/.cursorignore index 700ef8e..82b854b 100644 --- a/.cursorignore +++ b/.cursorignore @@ -21,3 +21,4 @@ tests/reports/ !/.cursor !/AGENTS.md + diff --git a/.gitignore b/.gitignore index 5f17270..b891241 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ git-installer.exe # Ne pas ignorer .cursor ni AGENTS.md + diff --git a/TEMPLATE_VERSION b/TEMPLATE_VERSION index 408e425..1c772ff 100644 --- a/TEMPLATE_VERSION +++ b/TEMPLATE_VERSION @@ -1,2 +1,3 @@ v2025.08.3 + diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 0000000..abf897e --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,19 @@ +services: + project-ci: + build: + context: . + dockerfile: docker/Dockerfile.ci + image: 4nk-template-ci:latest + environment: + - RUNNER_MODE=${RUNNER_MODE:-agents} + - TARGET_DIR=/work + - OUTPUT_DIR=/work/tests/reports/agents + - BASE_URL + - REGISTRATION_TOKEN + volumes: + - ./:/work + - ${HOME}/.4nk_template/.env:/root/.4nk_template/.env:ro + tty: true + labels: + - "com.4nk.template=ci" + diff --git a/docker/Dockerfile.ci b/docker/Dockerfile.ci new file mode 100644 index 0000000..3842571 --- /dev/null +++ b/docker/Dockerfile.ci @@ -0,0 +1,26 @@ +FROM gitea/act_runner:nightly + +USER root + +RUN apk update || true && \ + (apk add --no-cache bash curl jq git coreutils dos2unix || \ + (apt-get update && apt-get install -y bash curl jq git coreutils dos2unix)) && \ + mkdir -p /app /work /root/.4nk_template && chmod 700 /root/.4nk_template + +WORKDIR /app + +# Copier les scripts agents +COPY scripts /work/scripts + +# Normaliser les fins de ligne et permissions +RUN find /work/scripts -type f -name "*.sh" -print0 | xargs -0 -r dos2unix -f && \ + find /work/scripts -type f -name "*.sh" -exec chmod +x {} + + +# Entrypoint unifié: lance le runner si variables présentes, sinon agents +COPY docker/entrypoint.ci.sh /entrypoint.sh +RUN dos2unix -f /entrypoint.sh && chmod +x /entrypoint.sh + +WORKDIR /work + +ENTRYPOINT ["/entrypoint.sh"] + diff --git a/docker/entrypoint.ci.sh b/docker/entrypoint.ci.sh new file mode 100644 index 0000000..43d6687 --- /dev/null +++ b/docker/entrypoint.ci.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Charge l'env utilisateur si monté +if [[ -f "/root/.4nk_template/.env" ]]; then + set -a + . "/root/.4nk_template/.env" + set +a +fi + +MODE="${RUNNER_MODE:-agents}" +TARGET_DIR="${TARGET_DIR:-/work}" +OUTPUT_DIR="${OUTPUT_DIR:-/work/tests/reports/agents}" + +normalize_scripts() { + if command -v dos2unix >/dev/null 2>&1; then + find /work/scripts -type f -name "*.sh" -print0 | xargs -0 -r dos2unix -f || true + fi + find /work/scripts -type f -name "*.sh" -exec chmod +x {} + || true +} + +start_runner() { + # Démarre le runner gitea/act_runner (processus au premier plan) + # Requiert : GITEA_INSTANCE_URL (BASE_URL), REGISTRATION_TOKEN ou config existante + if [[ -n "${BASE_URL:-}" && -n "${REGISTRATION_TOKEN:-}" ]]; then + act_runner register --no-interactive \ + --instance "$BASE_URL" \ + --token "$REGISTRATION_TOKEN" \ + --labels "self-hosted,linux" || true + fi + exec act_runner daemon +} + +run_agents() { + normalize_scripts + mkdir -p "$OUTPUT_DIR" + cd "$TARGET_DIR" + /work/scripts/agents/run.sh "$TARGET_DIR" "$OUTPUT_DIR" all || true + echo "Rapports disponibles dans $OUTPUT_DIR" >&2 +} + +case "$MODE" in + runner) start_runner ;; + agents) run_agents ;; + both) + start_runner & + run_agents + wait -n || true + ;; + *) run_agents ;; +esac diff --git a/scripts/checks/version_alignment.sh b/scripts/checks/version_alignment.sh index e399e72..a7907cc 100644 --- a/scripts/checks/version_alignment.sh +++ b/scripts/checks/version_alignment.sh @@ -19,3 +19,4 @@ fi echo "Version alignment OK" + diff --git a/scripts/dev/run_project_ci.sh b/scripts/dev/run_project_ci.sh new file mode 100644 index 0000000..d92d96b --- /dev/null +++ b/scripts/dev/run_project_ci.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Build et lance le conteneur unifié (runner+agents) sur ce projet +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +cd "$ROOT_DIR" + +# Build image +docker compose -f docker-compose.ci.yml build + +# Exécuter agents par défaut +RUNNER_MODE="${RUNNER_MODE:-agents}" BASE_URL="${BASE_URL:-}" REGISTRATION_TOKEN="${REGISTRATION_TOKEN:-}" \ + docker compose -f docker-compose.ci.yml up --remove-orphans --abort-on-container-exit diff --git a/scripts/release/guard.sh b/scripts/release/guard.sh index cb5410b..fc59b08 100644 --- a/scripts/release/guard.sh +++ b/scripts/release/guard.sh @@ -64,3 +64,4 @@ esac echo "[release-guard] OK" + diff --git a/scripts/security/audit.sh b/scripts/security/audit.sh index 4dc1d4c..c705469 100644 --- a/scripts/security/audit.sh +++ b/scripts/security/audit.sh @@ -34,3 +34,4 @@ fi echo "[security-audit] terminé rc=$rc" exit $rc +