Using React Realm with CI

This is not so much a problem as a solution to a particular deployment configuration.
We have a js/react backend server which calls Realm ( our realm functions are part of our infrastructure to integrate Atlas Search (good stuff). Our backend is on ubuntu and managed with a CI ( When we git push Cleavr replaces the old distribution and creates a new one. I noticed that one of our deployment hooks was failing because a folder mongodb_realm is crreated and given root ownership. This makes sense, but also creates a problem. The Cleavr process doesn’t have root privileges so it can’t remove mongodb_realm. I found a solution by creating a zsh script to remove the old releases. Very simple and go around the problem of root ownership by adding the script to /etc/sudoers for the cleavr user.

cleavr ALL=(ALL:ALL) NOPASSWD: /home/ubuntu/clean

the clean script takes care of our med-dev BE server

l=$(ls $SITE  | wc -l)

if [ $l -gt  1 ]; 
  for i in  $(ls -rt  $SITE | tail  -n  $m)
        echo $i
        rm -rf $i
   echo 'DONE'  
 echo 'OK'

Since this took me more than a trivial amount of time I wanted to share the solution.

Hope this helps someone at sometime.