From 89f0858bcefcb955e911202e9801c312fd6ffa33 Mon Sep 17 00:00:00 2001 From: Christophe Date: Sun, 12 Apr 2026 17:24:14 +0200 Subject: [PATCH] Synchronise aussi le projet d'Ethan dans les scripts Proxmox --- README.md | 6 +- install-chesscubing-proxmox.sh | 6 ++ scripts/install-proxmox-lxc.sh | 134 ++++++++++++++++++++++++--------- scripts/update-proxmox-lxc.sh | 129 +++++++++++++++++++++++-------- update-chesscubing-proxmox.sh | 6 ++ 5 files changed, 212 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index ce5d0bf..af0ccc7 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Prérequis sur la machine qui lance les scripts : - en mode distant : `ssh` et `sshpass` - en mode local sur l'hôte Proxmox : aucun paquet supplémentaire n'est installé sur Proxmox -Le déploiement dans le LXC n'utilise pas Docker. Le script installe `nginx`, `git` et `rsync` dans le conteneur, clone le dépôt puis publie uniquement les fichiers web. +Le déploiement dans le LXC n'utilise pas Docker. Le script installe `nginx`, `git` et `rsync` dans le conteneur, clone le dépôt principal, synchronise aussi le projet d'Ethan, puis publie uniquement les fichiers web. ### Installer un nouveau LXC @@ -68,6 +68,7 @@ Valeurs par défaut utiles : - IP du LXC en `dhcp` - branche Git `main` - dépôt `https://git.jeannerot.fr/christophe/chesscubing.git` +- dépôt Ethan `https://git.jeannerot.fr/Mineloulou/Chesscubing.git` Options utiles si besoin : @@ -76,6 +77,7 @@ Options utiles si besoin : - `--template-storage local` - `--rootfs-storage local-lvm` - `--branch main` +- `--ethan-branch main` À la fin, le script affiche : @@ -112,7 +114,7 @@ On peut aussi cibler le conteneur par nom si on n'a pas le `CTID` : --hostname chesscubing-web ``` -Le script de mise à jour exécute un `git pull --ff-only` dans le conteneur puis republie les fichiers statiques via `nginx`. +Le script de mise à jour exécute un `git pull --ff-only` pour le dépôt principal et le dépôt d'Ethan dans le conteneur, puis republie les fichiers statiques via `nginx`, y compris la route `/ethan/`. ## Fichiers clés diff --git a/install-chesscubing-proxmox.sh b/install-chesscubing-proxmox.sh index fe1d434..3077c4d 100755 --- a/install-chesscubing-proxmox.sh +++ b/install-chesscubing-proxmox.sh @@ -33,6 +33,8 @@ Variables d'environnement reconnues : CHESSCUBING_ROOTFS_STORAGE CHESSCUBING_LXC_PASSWORD CHESSCUBING_GIT_BRANCH + CHESSCUBING_ETHAN_REPO_URL + CHESSCUBING_ETHAN_GIT_BRANCH EOF } @@ -107,6 +109,8 @@ LXC_DISK_GB="${CHESSCUBING_LXC_DISK_GB:-6}" TEMPLATE_STORAGE="${CHESSCUBING_TEMPLATE_STORAGE:-}" ROOTFS_STORAGE="${CHESSCUBING_ROOTFS_STORAGE:-}" LXC_PASSWORD="${CHESSCUBING_LXC_PASSWORD:-}" +ETHAN_REPO_URL="${CHESSCUBING_ETHAN_REPO_URL:-https://git.jeannerot.fr/Mineloulou/Chesscubing.git}" +ETHAN_REPO_BRANCH="${CHESSCUBING_ETHAN_GIT_BRANCH:-main}" if [[ -z "$LOCAL_MODE" && -z "$PROXMOX_HOST" ]]; then if have_cmd pct && have_cmd pveam; then @@ -159,6 +163,8 @@ cmd=( --swap "$LXC_SWAP" --disk-gb "$LXC_DISK_GB" --branch "$REPO_BRANCH" + --ethan-repo-url "$ETHAN_REPO_URL" + --ethan-branch "$ETHAN_REPO_BRANCH" ) if [[ "$LOCAL_MODE" == "1" ]]; then diff --git a/scripts/install-proxmox-lxc.sh b/scripts/install-proxmox-lxc.sh index 48e7192..746f75f 100755 --- a/scripts/install-proxmox-lxc.sh +++ b/scripts/install-proxmox-lxc.sh @@ -32,6 +32,8 @@ Options principales: --rootfs-storage Stockage Proxmox pour le disque LXC --repo-url Depot Git a deployer --branch Branche Git a deployer (defaut: main) + --ethan-repo-url Depot Git de l'application Ethan + --ethan-branch Branche Git de l'application Ethan (defaut: main) --lxc-password Mot de passe root du LXC. Genere si absent -h, --help Affiche cette aide @@ -71,6 +73,8 @@ TEMPLATE_STORAGE="" ROOTFS_STORAGE="" REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git" REPO_BRANCH="main" +ETHAN_REPO_URL="https://git.jeannerot.fr/Mineloulou/Chesscubing.git" +ETHAN_REPO_BRANCH="main" LXC_PASSWORD="" while [[ $# -gt 0 ]]; do @@ -147,6 +151,14 @@ while [[ $# -gt 0 ]]; do REPO_BRANCH="${2:-}" shift 2 ;; + --ethan-repo-url) + ETHAN_REPO_URL="${2:-}" + shift 2 + ;; + --ethan-branch) + ETHAN_REPO_BRANCH="${2:-}" + shift 2 + ;; --lxc-password) LXC_PASSWORD="${2:-}" shift 2 @@ -192,7 +204,9 @@ template_storage="$1" rootfs_storage="$2" repo_url="$3" repo_branch="$4" -lxc_password="$5" +ethan_repo_url="$5" +ethan_repo_branch="$6" +lxc_password="$7" die() { printf 'Erreur: %s\n' "$*" >&2 @@ -328,14 +342,17 @@ pct exec "$ctid" -- true >/dev/null 2>&1 || die "Le LXC n'est pas joignable apre printf 'Installation de nginx, git et rsync dans le conteneur...\n' ct_exec "apt-get update && apt-get install -y ca-certificates git nginx rsync" -ct_exec "install -d -m 0755 /opt/chesscubing/repo /var/www/chesscubing/current" +ct_exec "install -d -m 0755 /opt/chesscubing/repo /opt/chesscubing/ethan-repo /var/www/chesscubing/current" printf 'Clonage du depot %s...\n' "$repo_url" ct_exec "if [ ! -d /opt/chesscubing/repo/.git ]; then \ rm -rf /opt/chesscubing/repo/* /opt/chesscubing/repo/.[!.]* /opt/chesscubing/repo/..?* 2>/dev/null || true; \ git clone --branch '$repo_branch' --single-branch '$repo_url' /opt/chesscubing/repo; \ else \ - cd /opt/chesscubing/repo && git checkout '$repo_branch' && git pull --ff-only origin '$repo_branch'; \ + cd /opt/chesscubing/repo && \ + git fetch origin '$repo_branch' && \ + if git show-ref --verify --quiet 'refs/heads/$repo_branch'; then git checkout '$repo_branch'; else git checkout -b '$repo_branch' --track 'origin/$repo_branch'; fi && \ + git pull --ff-only origin '$repo_branch'; \ fi" ct_exec "cat > /usr/local/bin/update-chesscubing <<'SCRIPT' @@ -344,46 +361,83 @@ set -Eeuo pipefail trap 'printf \"Erreur: echec de la commande [%s] a la ligne %s.\\n\" \"\$BASH_COMMAND\" \"\$LINENO\" >&2' ERR -repo_dir='/opt/chesscubing/repo' +main_repo_dir='/opt/chesscubing/repo' +ethan_repo_dir='/opt/chesscubing/ethan-repo' web_root='/var/www/chesscubing/current' -branch=\"\${1:-${repo_branch}}\" +main_branch=\"\${1:-${repo_branch}}\" +ethan_repo_url='${ethan_repo_url}' +ethan_branch='${ethan_repo_branch}' -cd \"\$repo_dir\" +sync_git_repo() { + local repo_dir=\"\$1\" + local repo_url=\"\$2\" + local branch=\"\$3\" + local label=\"\$4\" -if ! git diff --quiet || ! git diff --cached --quiet; then - echo 'Le depot de production contient des modifications locales. Mise a jour annulee.' >&2 - exit 1 -fi + if [[ -d \"\$repo_dir/.git\" ]]; then + cd \"\$repo_dir\" -current_branch=\"\$(git rev-parse --abbrev-ref HEAD)\" -if [[ \"\$current_branch\" != \"\$branch\" ]]; then - git checkout \"\$branch\" -fi + if ! git diff --quiet || ! git diff --cached --quiet; then + echo \"Le depot \${label} contient des modifications locales. Mise a jour annulee.\" >&2 + exit 1 + fi -git fetch origin \"\$branch\" -git pull --ff-only origin \"\$branch\" -asset_version=\"\$(git rev-parse --short HEAD)\" + git fetch origin \"\$branch\" + if git show-ref --verify --quiet \"refs/heads/\$branch\"; then + git checkout \"\$branch\" + else + git checkout -b \"\$branch\" --track \"origin/\$branch\" + fi + git pull --ff-only origin \"\$branch\" + return 0 + fi + + [[ -n \"\$repo_url\" ]] || { + echo \"Le depot \${label} est absent et aucune URL n'a ete fournie.\" >&2 + exit 1 + } + + rm -rf \"\$repo_dir\" + git clone --branch \"\$branch\" --single-branch \"\$repo_url\" \"\$repo_dir\" +} + +publish_static_tree() { + local source_dir=\"\$1\" + local destination_dir=\"\$2\" + + install -d -m 0755 \"\$destination_dir\" + + rsync -a --delete \ + --include='*/' \ + --include='*.html' \ + --include='*.css' \ + --include='*.js' \ + --include='*.mjs' \ + --include='*.png' \ + --include='*.jpg' \ + --include='*.jpeg' \ + --include='*.svg' \ + --include='*.webp' \ + --include='*.ico' \ + --include='*.pdf' \ + --include='*.webmanifest' \ + --exclude='*' \ + \"\$source_dir/\" \"\$destination_dir/\" +} + +sync_git_repo \"\$main_repo_dir\" '${repo_url}' \"\$main_branch\" 'principal' +sync_git_repo \"\$ethan_repo_dir\" \"\$ethan_repo_url\" \"\$ethan_branch\" 'Ethan' + +asset_version=\"\$(git -C \"\$main_repo_dir\" rev-parse --short HEAD)-\$(git -C \"\$ethan_repo_dir\" rev-parse --short HEAD)\" install -d -m 0755 \"\$web_root\" -rsync -a --delete \ - --include='*/' \ - --include='*.html' \ - --include='*.css' \ - --include='*.js' \ - --include='*.png' \ - --include='*.jpg' \ - --include='*.jpeg' \ - --include='*.svg' \ - --include='*.webp' \ - --include='*.ico' \ - --include='*.pdf' \ - --exclude='*' \ - \"\$repo_dir/\" \"\$web_root/\" +publish_static_tree \"\$main_repo_dir\" \"\$web_root\" +publish_static_tree \"\$ethan_repo_dir\" \"\$web_root/ethan\" while IFS= read -r -d '' html_file; do - LC_ALL=C LANG=C ASSET_VERSION=\"\$asset_version\" perl -0pi -e 's{((?:href|src)=\")(?!https?://|data:|//)([^\"?]+?\.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf))(?:\?[^\"]*)?(\")}{\$1 . \$2 . \"?v=\" . \$ENV{ASSET_VERSION} . \$3}ge' \"\$html_file\" -done < <(find \"\$web_root\" -maxdepth 1 -type f -name '*.html' -print0) + LC_ALL=C LANG=C ASSET_VERSION=\"\$asset_version\" perl -0pi -e 's{((?:href|src)=\")(?!https?://|data:|//)([^\"?]+?\.(?:css|js|mjs|png|jpg|jpeg|svg|webp|ico|pdf|webmanifest))(?:\?[^\"]*)?(\")}{\$1 . \$2 . \"?v=\" . \$ENV{ASSET_VERSION} . \$3}ge' \"\$html_file\" +done < <(find \"\$web_root\" -type f -name '*.html' -print0) chown -R www-data:www-data \"\$web_root\" @@ -401,11 +455,19 @@ server { root /var/www/chesscubing/current; index index.html; + location = /ethan { + return 301 \$scheme://\$http_host/ethan/; + } + + location /ethan/ { + try_files \$uri \$uri/ /ethan/index.html; + } + location / { try_files \$uri \$uri/ /index.html; } - location ~* \.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf)$ { + location ~* \.(?:css|js|mjs|png|jpg|jpeg|svg|webp|ico|pdf|webmanifest)$ { expires -1; add_header Cache-Control 'no-cache, no-store, must-revalidate'; } @@ -449,6 +511,8 @@ if [[ "$LOCAL_MODE" == "1" ]]; then "$ROOTFS_STORAGE" \ "$REPO_URL" \ "$REPO_BRANCH" \ + "$ETHAN_REPO_URL" \ + "$ETHAN_REPO_BRANCH" \ "$LXC_PASSWORD" exit 0 fi @@ -487,4 +551,6 @@ sshpass -p "$PROXMOX_PASSWORD" \ "$ROOTFS_STORAGE" \ "$REPO_URL" \ "$REPO_BRANCH" \ + "$ETHAN_REPO_URL" \ + "$ETHAN_REPO_BRANCH" \ "$LXC_PASSWORD" < "$payload_script" diff --git a/scripts/update-proxmox-lxc.sh b/scripts/update-proxmox-lxc.sh index 91c6a4f..561a9ad 100755 --- a/scripts/update-proxmox-lxc.sh +++ b/scripts/update-proxmox-lxc.sh @@ -23,6 +23,8 @@ Options principales: --ctid CTID du LXC a mettre a jour --hostname Nom du LXC si le CTID n'est pas fourni (defaut: chesscubing-web) --branch Branche Git a deployer (defaut: main) + --ethan-repo-url Depot Git de l'application Ethan + --ethan-branch Branche Git de l'application Ethan (defaut: main) -h, --help Affiche cette aide EOF } @@ -45,6 +47,8 @@ LOCAL_MODE="0" CTID="" LXC_HOSTNAME="chesscubing-web" REPO_BRANCH="main" +ETHAN_REPO_URL="https://git.jeannerot.fr/Mineloulou/Chesscubing.git" +ETHAN_REPO_BRANCH="main" while [[ $# -gt 0 ]]; do case "$1" in @@ -80,6 +84,14 @@ while [[ $# -gt 0 ]]; do REPO_BRANCH="${2:-}" shift 2 ;; + --ethan-repo-url) + ETHAN_REPO_URL="${2:-}" + shift 2 + ;; + --ethan-branch) + ETHAN_REPO_BRANCH="${2:-}" + shift 2 + ;; -h | --help) usage exit 0 @@ -110,6 +122,8 @@ trap 'printf "Erreur: echec de la commande [%s] a la ligne %s.\n" "$BASH_COMMAND ctid="$1" lxc_hostname="$2" repo_branch="$3" +ethan_repo_url="$4" +ethan_repo_branch="$5" die() { printf 'Erreur: %s\n' "$*" >&2 @@ -165,46 +179,83 @@ set -Eeuo pipefail trap 'printf \"Erreur: echec de la commande [%s] a la ligne %s.\\n\" \"\$BASH_COMMAND\" \"\$LINENO\" >&2' ERR -repo_dir='/opt/chesscubing/repo' +main_repo_dir='/opt/chesscubing/repo' +ethan_repo_dir='/opt/chesscubing/ethan-repo' web_root='/var/www/chesscubing/current' -branch=\"\${1:-${repo_branch}}\" +main_branch=\"\${1:-${repo_branch}}\" +ethan_repo_url='${ethan_repo_url}' +ethan_branch='${ethan_repo_branch}' -cd \"\$repo_dir\" +sync_git_repo() { + local repo_dir=\"\$1\" + local repo_url=\"\$2\" + local branch=\"\$3\" + local label=\"\$4\" -if ! git diff --quiet || ! git diff --cached --quiet; then - echo 'Le depot de production contient des modifications locales. Mise a jour annulee.' >&2 - exit 1 -fi + if [[ -d \"\$repo_dir/.git\" ]]; then + cd \"\$repo_dir\" -current_branch=\"\$(git rev-parse --abbrev-ref HEAD)\" -if [[ \"\$current_branch\" != \"\$branch\" ]]; then - git checkout \"\$branch\" -fi + if ! git diff --quiet || ! git diff --cached --quiet; then + echo \"Le depot \${label} contient des modifications locales. Mise a jour annulee.\" >&2 + exit 1 + fi -git fetch origin \"\$branch\" -git pull --ff-only origin \"\$branch\" -asset_version=\"\$(git rev-parse --short HEAD)\" + git fetch origin \"\$branch\" + if git show-ref --verify --quiet \"refs/heads/\$branch\"; then + git checkout \"\$branch\" + else + git checkout -b \"\$branch\" --track \"origin/\$branch\" + fi + git pull --ff-only origin \"\$branch\" + return 0 + fi + + [[ -n \"\$repo_url\" ]] || { + echo \"Le depot \${label} est absent et aucune URL n'a ete fournie.\" >&2 + exit 1 + } + + rm -rf \"\$repo_dir\" + git clone --branch \"\$branch\" --single-branch \"\$repo_url\" \"\$repo_dir\" +} + +publish_static_tree() { + local source_dir=\"\$1\" + local destination_dir=\"\$2\" + + install -d -m 0755 \"\$destination_dir\" + + rsync -a --delete \ + --include='*/' \ + --include='*.html' \ + --include='*.css' \ + --include='*.js' \ + --include='*.mjs' \ + --include='*.png' \ + --include='*.jpg' \ + --include='*.jpeg' \ + --include='*.svg' \ + --include='*.webp' \ + --include='*.ico' \ + --include='*.pdf' \ + --include='*.webmanifest' \ + --exclude='*' \ + \"\$source_dir/\" \"\$destination_dir/\" +} + +sync_git_repo \"\$main_repo_dir\" '' \"\$main_branch\" 'principal' +sync_git_repo \"\$ethan_repo_dir\" \"\$ethan_repo_url\" \"\$ethan_branch\" 'Ethan' + +asset_version=\"\$(git -C \"\$main_repo_dir\" rev-parse --short HEAD)-\$(git -C \"\$ethan_repo_dir\" rev-parse --short HEAD)\" install -d -m 0755 \"\$web_root\" -rsync -a --delete \ - --include='*/' \ - --include='*.html' \ - --include='*.css' \ - --include='*.js' \ - --include='*.png' \ - --include='*.jpg' \ - --include='*.jpeg' \ - --include='*.svg' \ - --include='*.webp' \ - --include='*.ico' \ - --include='*.pdf' \ - --exclude='*' \ - \"\$repo_dir/\" \"\$web_root/\" +publish_static_tree \"\$main_repo_dir\" \"\$web_root\" +publish_static_tree \"\$ethan_repo_dir\" \"\$web_root/ethan\" while IFS= read -r -d '' html_file; do - LC_ALL=C LANG=C ASSET_VERSION=\"\$asset_version\" perl -0pi -e 's{((?:href|src)=\")(?!https?://|data:|//)([^\"?]+?\.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf))(?:\?[^\"]*)?(\")}{\$1 . \$2 . \"?v=\" . \$ENV{ASSET_VERSION} . \$3}ge' \"\$html_file\" -done < <(find \"\$web_root\" -maxdepth 1 -type f -name '*.html' -print0) + LC_ALL=C LANG=C ASSET_VERSION=\"\$asset_version\" perl -0pi -e 's{((?:href|src)=\")(?!https?://|data:|//)([^\"?]+?\.(?:css|js|mjs|png|jpg|jpeg|svg|webp|ico|pdf|webmanifest))(?:\?[^\"]*)?(\")}{\$1 . \$2 . \"?v=\" . \$ENV{ASSET_VERSION} . \$3}ge' \"\$html_file\" +done < <(find \"\$web_root\" -type f -name '*.html' -print0) chown -R www-data:www-data \"\$web_root\" @@ -222,11 +273,19 @@ server { root /var/www/chesscubing/current; index index.html; + location = /ethan { + return 301 \$scheme://\$http_host/ethan/; + } + + location /ethan/ { + try_files \$uri \$uri/ /ethan/index.html; + } + location / { try_files \$uri \$uri/ /index.html; } - location ~* \.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf)$ { + location ~* \.(?:css|js|mjs|png|jpg|jpeg|svg|webp|ico|pdf|webmanifest)$ { expires -1; add_header Cache-Control 'no-cache, no-store, must-revalidate'; } @@ -253,7 +312,9 @@ if [[ "$LOCAL_MODE" == "1" ]]; then bash "$payload_script" \ "$CTID" \ "$LXC_HOSTNAME" \ - "$REPO_BRANCH" + "$REPO_BRANCH" \ + "$ETHAN_REPO_URL" \ + "$ETHAN_REPO_BRANCH" exit 0 fi @@ -280,4 +341,6 @@ sshpass -p "$PROXMOX_PASSWORD" \ bash -s -- \ "$CTID" \ "$LXC_HOSTNAME" \ - "$REPO_BRANCH" < "$payload_script" + "$REPO_BRANCH" \ + "$ETHAN_REPO_URL" \ + "$ETHAN_REPO_BRANCH" < "$payload_script" diff --git a/update-chesscubing-proxmox.sh b/update-chesscubing-proxmox.sh index 10edc86..de10c59 100755 --- a/update-chesscubing-proxmox.sh +++ b/update-chesscubing-proxmox.sh @@ -23,6 +23,8 @@ Variables d'environnement reconnues : CHESSCUBING_CTID CHESSCUBING_LXC_HOSTNAME CHESSCUBING_GIT_BRANCH + CHESSCUBING_ETHAN_REPO_URL + CHESSCUBING_ETHAN_GIT_BRANCH EOF } @@ -87,6 +89,8 @@ PROXMOX_PASSWORD="${CHESSCUBING_PROXMOX_PASSWORD:-}" SSH_PORT="${CHESSCUBING_SSH_PORT:-22}" CTID="${CHESSCUBING_CTID:-}" LXC_HOSTNAME="${CHESSCUBING_LXC_HOSTNAME:-chesscubing-web}" +ETHAN_REPO_URL="${CHESSCUBING_ETHAN_REPO_URL:-https://git.jeannerot.fr/Mineloulou/Chesscubing.git}" +ETHAN_REPO_BRANCH="${CHESSCUBING_ETHAN_GIT_BRANCH:-main}" if [[ -z "$LOCAL_MODE" && -z "$PROXMOX_HOST" ]]; then if have_cmd pct && have_cmd pveam; then @@ -124,6 +128,8 @@ chmod +x "$TMP_DIR/update-proxmox-lxc.sh" cmd=( "$TMP_DIR/update-proxmox-lxc.sh" --branch "$REPO_BRANCH" + --ethan-repo-url "$ETHAN_REPO_URL" + --ethan-branch "$ETHAN_REPO_BRANCH" ) if [[ "$LOCAL_MODE" == "1" ]]; then