Synchronise aussi le projet d'Ethan dans les scripts Proxmox

This commit is contained in:
2026-04-12 17:24:14 +02:00
parent a3d3bd18a9
commit 89f0858bce
5 changed files with 212 additions and 69 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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