Skip to content
Snippets Groups Projects
Commit 1f0260f7 authored by Vipul's avatar Vipul
Browse files

feat: cleanup implementation

parent 36f58c22
No related branches found
No related tags found
No related merge requests found
......@@ -121,6 +121,7 @@ ensure_dependencies
# Variables
PROJECT_PATH="/home/admin/shepherd-enterprise"
GIT_BRANCH="patch-fix-storage-cleanup"
ENV_SHEPHERD_PATH="$PROJECT_PATH/.env.shepherd"
ENV_CLIENT_PATH="$PROJECT_PATH/.env.client"
......@@ -135,6 +136,8 @@ CADDYFILE_PATH="$PROJECT_PATH/Caddyfile"
GRAFANADATA_PATH="$PROJECT_PATH/grafanadata"
LOKIDATA_PATH="$PROJECT_PATH/lokidata"
GIT_PATH="$PROJECT_PATH/.git"
SCRIPT_PATH="$PROJECT_PATH/setup-debian.sh"
SCRIPT_LOG_PATH="$PROJECT_PATH/cron-logs/setup-debian-cron.log"
CRON_JOB="0 0 * * * $SCRIPT_PATH >> $SCRIPT_LOG_PATH 2>&1"
......@@ -157,6 +160,35 @@ VIMACOG_HARD_GEN_EXISTS=$(crontab -l | grep -F "$VIMACOG_HARD_GEN_PATH" | grep -
VIMACOG_HARD_GEN_LOG_DIR="$PROJECT_PATH/vimacog/hard-gen-logs/"
VIMACOG_HARD_GEN_BACKUP_DIR="$PROJECT_PATH/vimacog/hard-gen-backup/"
# Note: Cleanup temporary storgae
cleanup_git() {
echo "Initiating git cleanup..."
sudo du -hc $GIT_PATH
sudo git fetch -fpPv origin $GIT_BRANCH
echo "Git cleanup complete."
sudo du -hc $GIT_PATH
}
cleanup_loki() {
echo "Initiating loki logs cleanup..."
sudo du -hc $LOKIDATA_PATH
sudo rm -rf $LOKIDATA_PATH/*
echo "Loki logs cleanup complete."
sudo du -hc $LOKIDATA_PATH
}
cleanup_docker() {
echo "Initiating docker cleanup..."
sudo docker system df
sudo docker system prune -af --volumes
echo "Docker cleanup complete."
sudo docker system df
}
cleanup_git
cleanup_loki
cleanup_docker
# Check for Git updates & pull if updates are available
# Returns whether to hard run or soft run
# Note: Runs always
......@@ -164,12 +196,12 @@ setup_git() {
echo "Checking for git updates..."
cd "$PROJECT_PATH" || exit
# git config pull.rebase true
sudo git fetch origin main
sudo git fetch -fpPv origin $GIT_BRANCH
if [ "$(git rev-parse HEAD)" != "$(git rev-parse FETCH_HEAD)" ]; then
# Ignore all local changes(comitted & non-comitted)
sudo git reset --hard origin/main
# TODO: Change this to main branch
sudo git pull origin main --force
sudo git reset --hard origin/$GIT_BRANCH
# TODO: Change this to $GIT_BRANCH branch
sudo git pull -fpv origin $GIT_BRANCH
echo "Repository updated. Applying updates..."
# Ensure the scripts are executable after a potential update
sudo chmod +x "$SCRIPT_PATH"
......@@ -337,7 +369,7 @@ setup_docker() {
if [ "$force_update" = true ]; then
echo "Force updating images..."
sudo docker compose down
sudo docker system prune -af
sudo docker system prune -af --volumes
sudo docker compose pull
sudo docker compose --env-file ./.env up -d
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment