Synchronise aussi le projet d'Ethan dans les scripts Proxmox
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user