Add .env and .env.example files; implement development script and Docker connection logic

This commit is contained in:
2025-11-12 22:54:16 +00:00
parent 42535a81b2
commit d0a9583d22
4 changed files with 63 additions and 3 deletions

0
.env Normal file
View File

13
.env.example Normal file
View File

@@ -0,0 +1,13 @@
# Backup Configuration
BACKUP_FOLDER=/data/volumes
BACKUP_CRON=*/5 * * * *
# FTP Configuration
FTP_HOST=ftp.example.com
FTP_PORT=21
FTP_USER=backup_user
FTP_PASSWORD=secret123
FTP_PATH=/backups
# Docker Configuration
DOCKER_HOST=unix:///var/run/docker.sock

38
scripts/dev.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
set -e
# Couleurs pour les messages
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}🐝 Beekeeper Development Script${NC}"
# Vérifier si le fichier .env existe
if [ ! -f .env ]; then
echo -e "${RED}❌ Fichier .env introuvable${NC}"
echo -e "${YELLOW}Créez un fichier .env avec les variables nécessaires${NC}"
exit 1
fi
# Charger les variables d'environnement
echo -e "${GREEN}📋 Chargement des variables d'environnement depuis .env${NC}"
set -a
source .env
set +a
# Vérifier si cargo-watch est installé
if ! command -v cargo-watch &> /dev/null; then
echo -e "${YELLOW}⚠️ cargo-watch n'est pas installé${NC}"
echo -e "${YELLOW}Installation de cargo-watch...${NC}"
cargo install cargo-watch
fi
# Lancer cargo watch avec hot reload
echo -e "${GREEN}🚀 Démarrage du programme avec hot reload${NC}"
echo -e "${YELLOW}Le programme redémarrera automatiquement lors de modifications${NC}"
echo ""
cargo watch -x run

View File

@@ -7,13 +7,22 @@ async fn main() -> anyhow::Result<()> {
let folders = list_folders(backup_root_path).await?; let folders = list_folders(backup_root_path).await?;
let docker_conn = Docker::connect_with_socket_defaults()?; let docker_host = std::env::var("DOCKER_HOST").ok();
let docker_version = docker_conn.version().await?; let docker_conn = connect_docker(docker_host).await?;
println!("Docker version: {:?}", docker_version);
Ok(()) Ok(())
} }
async fn connect_docker(docker_host: Option<String>) -> anyhow::Result<Docker> {
Ok(
match docker_host {
Some(host) => Docker::connect_with_http(&host, 60, bollard::API_DEFAULT_VERSION)?,
None => Docker::connect_with_socket_defaults()?,
}
)
}
async fn list_folders(path: &std::path::Path) -> anyhow::Result<Vec<std::path::PathBuf>> { async fn list_folders(path: &std::path::Path) -> anyhow::Result<Vec<std::path::PathBuf>> {
let mut folders = Vec::new(); let mut folders = Vec::new();
let mut dir_entries = tokio::fs::read_dir(path).await?; let mut dir_entries = tokio::fs::read_dir(path).await?;