Ajoute le déploiement en prod locale
Makefile (setup, deploy avec sauvegarde de la base, status, logs, dev), vhost Apache en reverse proxy sur tempus.loc et service systemd utilisateur, binaire installé dans /var/www/tempus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
467293a6bc
commit
a3902c9662
4 files changed
+92
-1
No files matched your search
@@ -0,0 +1,53 @@
|
||||
DEPLOY_DIR ?= /var/www/tempus
|
||||
SERVICE ?= tempus
|
||||
HOST ?= tempus.loc
|
||||
ADDR ?= 127.0.0.1:3110
|
||||
UNIT := $(HOME)/.config/systemd/user/$(SERVICE).service
|
||||
SUBST := sed -e 's|@HOST@|$(HOST)|g' -e 's|@ADDR@|$(ADDR)|g' -e 's|@DEPLOY_DIR@|$(DEPLOY_DIR)|g'
|
||||
|
||||
.PHONY: build setup deploy backup status logs dev
|
||||
|
||||
## Compile le binaire (templates, CSS/JS et migrations sont embarqués).
|
||||
build:
|
||||
cargo build --release
|
||||
|
||||
## Une seule fois : dossier, vhost Apache et /etc/hosts (sudo), service systemd utilisateur.
|
||||
setup:
|
||||
sudo install -d -o $(USER) -g www-data -m 755 $(DEPLOY_DIR)
|
||||
$(SUBST) deploy/vh_tempus.conf | sudo tee /etc/apache2/sites-available/vh_tempus.conf >/dev/null
|
||||
sudo a2ensite -q vh_tempus
|
||||
sudo systemctl reload apache2
|
||||
grep -qw '$(HOST)' /etc/hosts || printf '127.0.0.1\t$(HOST)\n' | sudo tee -a /etc/hosts >/dev/null
|
||||
install -d $(dir $(UNIT))
|
||||
$(SUBST) deploy/tempus.service > $(UNIT)
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable $(SERVICE)
|
||||
|
||||
## Sauvegarde la base, installe le nouveau binaire et redémarre le service.
|
||||
deploy: build
|
||||
systemctl --user stop $(SERVICE)
|
||||
$(MAKE) --no-print-directory backup
|
||||
install -m 755 target/release/tempus $(DEPLOY_DIR)/tempus
|
||||
systemctl --user start $(SERVICE)
|
||||
@for i in $$(seq 1 50); do \
|
||||
curl -sf -o /dev/null http://$(ADDR)/health && echo "Déployé : http://$(HOST)" && exit 0; \
|
||||
sleep 0.1; \
|
||||
done; echo "Le service ne répond pas : make logs" >&2; exit 1
|
||||
|
||||
## Copie la base (service arrêté) dans $(DEPLOY_DIR)/backups, garde les 10 dernières.
|
||||
backup:
|
||||
@if [ -f $(DEPLOY_DIR)/tempus.db ]; then \
|
||||
d=$(DEPLOY_DIR)/backups/$$(date +%Y%m%d-%H%M%S); mkdir -p $$d; \
|
||||
cp $(DEPLOY_DIR)/tempus.db* $$d/ && echo "Sauvegarde : $$d"; \
|
||||
ls -1dt $(DEPLOY_DIR)/backups/*/ | tail -n +11 | xargs -r rm -r; \
|
||||
fi
|
||||
|
||||
status:
|
||||
systemctl --user status $(SERVICE) --no-pager
|
||||
|
||||
logs:
|
||||
journalctl --user -u $(SERVICE) -f
|
||||
|
||||
## Dev : recompile, redémarre et recharge le navigateur à chaque modif.
|
||||
dev:
|
||||
watchexec -r -e rs,html,css,js,sql -- cargo run --features livereload
|
||||
@@ -51,13 +51,28 @@ curl -XPOST localhost:7878/api/clients -H 'content-type: application/json' -d '{
|
||||
curl -XPOST localhost:7878/api/timer/start -H 'content-type: application/json' -d '{"project_id":1}'
|
||||
```
|
||||
|
||||
## Production locale
|
||||
|
||||
Binaire dans `/var/www/tempus`, service systemd utilisateur, vhost Apache
|
||||
(reverse proxy) sur http://tempus.loc → `127.0.0.1:3110`.
|
||||
|
||||
```sh
|
||||
make setup # une fois (sudo) : dossier, vhost, /etc/hosts, service
|
||||
make deploy # compile, sauvegarde la base, installe, redémarre
|
||||
make status # / make logs
|
||||
```
|
||||
|
||||
La base de prod est `/var/www/tempus/tempus.db` ; chaque `make deploy` la copie
|
||||
dans `/var/www/tempus/backups/` (10 dernières conservées). Variables
|
||||
surchargeables : `DEPLOY_DIR`, `HOST`, `ADDR`, `SERVICE`.
|
||||
|
||||
## Développement
|
||||
|
||||
Rechargement automatique (recompile, redémarre et rafraîchit le navigateur) :
|
||||
|
||||
```sh
|
||||
cargo install watchexec-cli # une fois
|
||||
watchexec -r -e rs,html,css,js,sql -- cargo run --features livereload
|
||||
make dev
|
||||
```
|
||||
|
||||
La feature `livereload` injecte un script dans les pages (pas dans les fragments
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=Tempus (suivi du temps)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=@DEPLOY_DIR@
|
||||
Environment=TEMPUS_DB=@DEPLOY_DIR@/tempus.db
|
||||
Environment=TEMPUS_ADDR=@ADDR@
|
||||
ExecStart=@DEPLOY_DIR@/tempus
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
@@ -0,0 +1,8 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName @HOST@
|
||||
ProxyPreserveHost On
|
||||
ProxyPass / http://@ADDR@/
|
||||
ProxyPassReverse / http://@ADDR@/
|
||||
ErrorLog /var/log/apache2/error.@HOST@.log
|
||||
CustomLog /var/log/apache2/access.@HOST@.log combined
|
||||
</VirtualHost>
|
||||
Reference in new issue
Block a user