Ameliore le deploiement Proxmox derriere un reverse proxy
This commit is contained in:
11
README.md
11
README.md
@@ -104,7 +104,9 @@ Le deploiement dans le LXC Proxmox utilise maintenant Docker dans le conteneur p
|
|||||||
|
|
||||||
Le script prepare une URL publique pour Keycloak via `PUBLIC_BASE_URL`, installe Docker dans le LXC, puis lance `docker compose up -d --build`.
|
Le script prepare une URL publique pour Keycloak via `PUBLIC_BASE_URL`, installe Docker dans le LXC, puis lance `docker compose up -d --build`.
|
||||||
|
|
||||||
Pour un usage confortable, il est recommande de prevoir un LXC avec au moins 2 vCPU, 4 Go de RAM et 10 Go de disque.
|
Si le site est expose derriere un reverse proxy, `PUBLIC_BASE_URL` doit etre l'URL publique finale servie par ce proxy.
|
||||||
|
|
||||||
|
Pour un usage confortable, il est recommande de prevoir un LXC avec au moins 2 vCPU, 4 Go de RAM et 16 Go de disque.
|
||||||
|
|
||||||
### Installer un nouveau LXC
|
### Installer un nouveau LXC
|
||||||
|
|
||||||
@@ -112,7 +114,8 @@ Pour un usage confortable, il est recommande de prevoir un LXC avec au moins 2 v
|
|||||||
./scripts/install-proxmox-lxc.sh \
|
./scripts/install-proxmox-lxc.sh \
|
||||||
--proxmox-host 10.0.0.2 \
|
--proxmox-host 10.0.0.2 \
|
||||||
--proxmox-user root@pam \
|
--proxmox-user root@pam \
|
||||||
--proxmox-password 'secret'
|
--proxmox-password 'secret' \
|
||||||
|
--public-base-url https://jeu.exemple.fr
|
||||||
```
|
```
|
||||||
|
|
||||||
Version "curl | bash" :
|
Version "curl | bash" :
|
||||||
@@ -128,7 +131,9 @@ bash -c "$(curl -fsSL https://git.jeannerot.fr/christophe/chesscubing/raw/branch
|
|||||||
--proxmox-host 10.0.0.2 \
|
--proxmox-host 10.0.0.2 \
|
||||||
--proxmox-user root@pam \
|
--proxmox-user root@pam \
|
||||||
--proxmox-password 'secret' \
|
--proxmox-password 'secret' \
|
||||||
--ctid 120
|
--ctid 120 \
|
||||||
|
--public-base-url https://jeu.exemple.fr \
|
||||||
|
--disk-gb 16
|
||||||
```
|
```
|
||||||
|
|
||||||
Version "curl | bash" :
|
Version "curl | bash" :
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Options principales:
|
|||||||
--cores Nombre de vCPU du LXC (defaut: 2)
|
--cores Nombre de vCPU du LXC (defaut: 2)
|
||||||
--memory Memoire RAM en Mo (defaut: 4096)
|
--memory Memoire RAM en Mo (defaut: 4096)
|
||||||
--swap Swap en Mo (defaut: 1024)
|
--swap Swap en Mo (defaut: 1024)
|
||||||
--disk-gb Taille disque du LXC en Go (defaut: 12)
|
--disk-gb Taille disque du LXC en Go (defaut: 16)
|
||||||
--template-storage Stockage Proxmox pour les templates
|
--template-storage Stockage Proxmox pour les templates
|
||||||
--rootfs-storage Stockage Proxmox pour le disque LXC
|
--rootfs-storage Stockage Proxmox pour le disque LXC
|
||||||
--repo-url Depot Git a deployer
|
--repo-url Depot Git a deployer
|
||||||
@@ -75,7 +75,7 @@ LXC_BRIDGE="vmbr0"
|
|||||||
LXC_CORES="2"
|
LXC_CORES="2"
|
||||||
LXC_MEMORY="4096"
|
LXC_MEMORY="4096"
|
||||||
LXC_SWAP="1024"
|
LXC_SWAP="1024"
|
||||||
LXC_DISK_GB="12"
|
LXC_DISK_GB="16"
|
||||||
TEMPLATE_STORAGE=""
|
TEMPLATE_STORAGE=""
|
||||||
ROOTFS_STORAGE=""
|
ROOTFS_STORAGE=""
|
||||||
REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git"
|
REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git"
|
||||||
@@ -631,11 +631,38 @@ disable_legacy_nginx() {
|
|||||||
systemctl disable --now nginx >/dev/null 2>&1 || true
|
systemctl disable --now nginx >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepare_disk_space() {
|
||||||
|
cd \"\$deploy_dir\"
|
||||||
|
docker compose down || true
|
||||||
|
docker system prune -af || true
|
||||||
|
apt-get clean || true
|
||||||
|
rm -rf /var/lib/apt/lists/* || true
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_free_space_mb() {
|
||||||
|
local required_mb=\"\$1\"
|
||||||
|
local available_mb
|
||||||
|
|
||||||
|
available_mb=\"\$(df -Pm / | awk 'NR == 2 { print \$4 }')\"
|
||||||
|
if [[ -z \"\$available_mb\" ]]; then
|
||||||
|
echo \"Impossible de mesurer l'espace disque libre dans le LXC.\" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( available_mb < required_mb )); then
|
||||||
|
echo \"Espace disque insuffisant dans le LXC: \${available_mb} Mo libres, \${required_mb} Mo recommandes avant la reconstruction Docker.\" >&2
|
||||||
|
echo \"Agrandis le disque du LXC puis relance la mise a jour.\" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
deploy_stack() {
|
deploy_stack() {
|
||||||
cp \"\$env_file\" \"\$deploy_dir/.env\"
|
cp \"\$env_file\" \"\$deploy_dir/.env\"
|
||||||
|
|
||||||
|
prepare_disk_space
|
||||||
|
ensure_free_space_mb 6144
|
||||||
|
|
||||||
cd \"\$deploy_dir\"
|
cd \"\$deploy_dir\"
|
||||||
docker compose down || true
|
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
docker compose ps
|
docker compose ps
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ Options principales:
|
|||||||
--local Execute directement sur l'hote Proxmox local
|
--local Execute directement sur l'hote Proxmox local
|
||||||
--ctid CTID du LXC a mettre a jour
|
--ctid CTID du LXC a mettre a jour
|
||||||
--hostname Nom du LXC si le CTID n'est pas fourni (defaut: chesscubing-web)
|
--hostname Nom du LXC si le CTID n'est pas fourni (defaut: chesscubing-web)
|
||||||
|
--disk-gb Taille disque cible du LXC en Go si un agrandissement est necessaire
|
||||||
--repo-url Depot Git principal a deployer
|
--repo-url Depot Git principal a deployer
|
||||||
--branch Branche Git a deployer (defaut: main)
|
--branch Branche Git a deployer (defaut: main)
|
||||||
--ethan-repo-url Depot Git de l'application Ethan
|
--ethan-repo-url Depot Git de l'application Ethan
|
||||||
@@ -54,6 +55,7 @@ LOCAL_MODE="0"
|
|||||||
|
|
||||||
CTID=""
|
CTID=""
|
||||||
LXC_HOSTNAME="chesscubing-web"
|
LXC_HOSTNAME="chesscubing-web"
|
||||||
|
TARGET_DISK_GB=""
|
||||||
REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git"
|
REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git"
|
||||||
REPO_BRANCH="main"
|
REPO_BRANCH="main"
|
||||||
ETHAN_REPO_URL="https://git.jeannerot.fr/Mineloulou/Chesscubing.git"
|
ETHAN_REPO_URL="https://git.jeannerot.fr/Mineloulou/Chesscubing.git"
|
||||||
@@ -95,6 +97,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
LXC_HOSTNAME="${2:-}"
|
LXC_HOSTNAME="${2:-}"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--disk-gb)
|
||||||
|
TARGET_DISK_GB="${2:-}"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--repo-url)
|
--repo-url)
|
||||||
REPO_URL="${2:-}"
|
REPO_URL="${2:-}"
|
||||||
shift 2
|
shift 2
|
||||||
@@ -174,12 +180,60 @@ public_base_url="$9"
|
|||||||
web_port="${10}"
|
web_port="${10}"
|
||||||
keycloak_admin_user="${11}"
|
keycloak_admin_user="${11}"
|
||||||
keycloak_admin_password="${12}"
|
keycloak_admin_password="${12}"
|
||||||
|
target_disk_gb="${13}"
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
printf 'Erreur: %s\n' "$*" >&2
|
printf 'Erreur: %s\n' "$*" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_to_mb() {
|
||||||
|
local raw="${1^^}"
|
||||||
|
|
||||||
|
case "$raw" in
|
||||||
|
*T) echo $(( ${raw%T} * 1024 * 1024 )) ;;
|
||||||
|
*G) echo $(( ${raw%G} * 1024 )) ;;
|
||||||
|
*M) echo $(( ${raw%M} )) ;;
|
||||||
|
*K) echo $(( ${raw%K} / 1024 )) ;;
|
||||||
|
*) echo "$raw" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
get_current_rootfs_mb() {
|
||||||
|
local size
|
||||||
|
|
||||||
|
size="$(pct config "$ctid" | awk -F'[:,=]' '/^rootfs:/ { for (i = 1; i <= NF; i++) { if ($i == "size") { print $(i + 1); exit } } }')"
|
||||||
|
[[ -n "$size" ]] || return 1
|
||||||
|
|
||||||
|
size_to_mb "$size"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_rootfs_capacity() {
|
||||||
|
local requested_gb="$1"
|
||||||
|
local current_mb
|
||||||
|
local requested_mb
|
||||||
|
local delta_mb
|
||||||
|
local delta_gb
|
||||||
|
local current_gb
|
||||||
|
|
||||||
|
[[ -n "$requested_gb" ]] || return 0
|
||||||
|
[[ "$requested_gb" =~ ^[0-9]+$ ]] || die "La valeur de --disk-gb doit etre un entier en Go."
|
||||||
|
|
||||||
|
current_mb="$(get_current_rootfs_mb)" || die "Impossible de lire la taille actuelle du disque rootfs du LXC."
|
||||||
|
requested_mb=$(( requested_gb * 1024 ))
|
||||||
|
|
||||||
|
if (( current_mb >= requested_mb )); then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
delta_mb=$(( requested_mb - current_mb ))
|
||||||
|
delta_gb=$(( (delta_mb + 1023) / 1024 ))
|
||||||
|
current_gb=$(( (current_mb + 1023) / 1024 ))
|
||||||
|
|
||||||
|
printf 'Agrandissement du disque rootfs du LXC: %sG -> %sG (+%sG).\n' "$current_gb" "$requested_gb" "$delta_gb"
|
||||||
|
pct resize "$ctid" rootfs "+${delta_gb}G" >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
find_ctid_by_hostname() {
|
find_ctid_by_hostname() {
|
||||||
local wanted="$1"
|
local wanted="$1"
|
||||||
local candidate=""
|
local candidate=""
|
||||||
@@ -214,6 +268,8 @@ if [[ -n "$detected_hostname" ]]; then
|
|||||||
lxc_hostname="$detected_hostname"
|
lxc_hostname="$detected_hostname"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ensure_rootfs_capacity "$target_disk_gb"
|
||||||
|
|
||||||
if pct status "$ctid" | grep -q "running"; then
|
if pct status "$ctid" | grep -q "running"; then
|
||||||
pct stop "$ctid"
|
pct stop "$ctid"
|
||||||
fi
|
fi
|
||||||
@@ -482,11 +538,38 @@ disable_legacy_nginx() {
|
|||||||
systemctl disable --now nginx >/dev/null 2>&1 || true
|
systemctl disable --now nginx >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepare_disk_space() {
|
||||||
|
cd \"\$deploy_dir\"
|
||||||
|
docker compose down || true
|
||||||
|
docker system prune -af || true
|
||||||
|
apt-get clean || true
|
||||||
|
rm -rf /var/lib/apt/lists/* || true
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_free_space_mb() {
|
||||||
|
local required_mb=\"\$1\"
|
||||||
|
local available_mb
|
||||||
|
|
||||||
|
available_mb=\"\$(df -Pm / | awk 'NR == 2 { print \$4 }')\"
|
||||||
|
if [[ -z \"\$available_mb\" ]]; then
|
||||||
|
echo \"Impossible de mesurer l'espace disque libre dans le LXC.\" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( available_mb < required_mb )); then
|
||||||
|
echo \"Espace disque insuffisant dans le LXC: \${available_mb} Mo libres, \${required_mb} Mo recommandes avant la reconstruction Docker.\" >&2
|
||||||
|
echo \"Relance le script avec --disk-gb 16 ou une valeur plus elevee si besoin.\" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
deploy_stack() {
|
deploy_stack() {
|
||||||
cp \"\$env_file\" \"\$deploy_dir/.env\"
|
cp \"\$env_file\" \"\$deploy_dir/.env\"
|
||||||
|
|
||||||
|
prepare_disk_space
|
||||||
|
ensure_free_space_mb 6144
|
||||||
|
|
||||||
cd \"\$deploy_dir\"
|
cd \"\$deploy_dir\"
|
||||||
docker compose down || true
|
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
docker compose ps
|
docker compose ps
|
||||||
}
|
}
|
||||||
@@ -531,7 +614,8 @@ if [[ "$LOCAL_MODE" == "1" ]]; then
|
|||||||
"$PUBLIC_BASE_URL" \
|
"$PUBLIC_BASE_URL" \
|
||||||
"$WEB_PORT" \
|
"$WEB_PORT" \
|
||||||
"$KEYCLOAK_ADMIN_USER" \
|
"$KEYCLOAK_ADMIN_USER" \
|
||||||
"$KEYCLOAK_ADMIN_PASSWORD"
|
"$KEYCLOAK_ADMIN_PASSWORD" \
|
||||||
|
"$TARGET_DISK_GB"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -567,4 +651,5 @@ sshpass -p "$PROXMOX_PASSWORD" \
|
|||||||
"$PUBLIC_BASE_URL" \
|
"$PUBLIC_BASE_URL" \
|
||||||
"$WEB_PORT" \
|
"$WEB_PORT" \
|
||||||
"$KEYCLOAK_ADMIN_USER" \
|
"$KEYCLOAK_ADMIN_USER" \
|
||||||
"$KEYCLOAK_ADMIN_PASSWORD" < "$payload_script"
|
"$KEYCLOAK_ADMIN_PASSWORD" \
|
||||||
|
"$TARGET_DISK_GB" < "$payload_script"
|
||||||
|
|||||||
Reference in New Issue
Block a user