Posts Tagged ‘deployment’

Automating the Deployment and Scheduled Execution of an R script on a VPS using Laravel Forge

I love data, its in my blood, I love analysing, cleaning it and preparing it for others to use, still have to get to the last mile to displaying and visualizing it but that is a story for another day

2024 for me is the year of “automation”, for everything that I do. I have been polishing up my R skills over the holidays, as a way for moving into Python based data wrangling, however the challenges that I have faced is to do with getting my R scripts to run regularly – this has to be on a server connected to the internet since my laptop is not always on

I tried ShinyApps in the past, but this needed me to learn more things which I did not have bandwidth for.

So when Contabo my host wiped my dev VPS during the holidays, I had to re-build my sites, one of which was a documentation site built using PHP and markdown, which I wrote about Deploying a Tighten Jigsaw static site to a VPS using Laravel Forge I was deploying generated HTML to the VPS, then it hit me can’t I do the same with an R script

Setup and Configuration

  1. Install R on your server, here are steps to install R v4.x (I was able to get 4.3.2) https://medium.com/@hpgomide/how-to-update-your-r-3-x-to-the-r-4-x-in-your-linux-ubuntu-46e2209409c3
  2. Create a static site via Laravel Forge from the screenshot below
    • The domain does not really matter, use any custom sub-domain, even if it does not exist since we shall not be accessing this site anyway
    • Select Static HTML/Next.js/Nuxt.js
    • Select “website Isolation” where you specify a user name for the site, I tend to do this alot allowing me to do custom commands without using the global forge user
    • Create a new static site with Laravel Forge
  3. Install your site code repository, GitHub/Gitlab are natively supported, and uncheck the “Install Composer dependencies”, we do not need this for R
    • Install Repository
  4. The magic happens in the Deployments tab which is enabled once you have connected the code repository
    • Firstly “Enable Quick Deploy” so that whenever you push code to the selected branch in Step #2 above the code is deployed
    • Customize your R script to be executed, in my case it was a simple as in the image below. I would also recommend keeping it as simple as you can to reduce deployment headaches
    • R execution script
  5. You can also test a deployment by clicking the “Deploy Now” button at the top of the page which will re-run the last deployment

Laravel Forge is $12 per month for a single VPS, then costs $19 per month for unlimited servers

Deploying a Tighten Jigsaw static site to a VPS using Laravel Forge

I have ran into an interesting challenge for a documentation site that I am working on. The code repository is private on GitHub until it is ready to be made public, however needs to be be deployed publicly

Initially I started working with Jekyll deployment proved to be a challenge through GitHub pages and Netlify both of which required upgrades which the project could not justify

Thus I looked in the direction of Jigsaw by Tighten which I have wanted to try out in a long time. My reasoning being that since it was Laravel based, I would be able to deploy it leveraging my existing Laravel Forge subscription to a managed server, and voila all would be well.

I first struggled with getting Jigsaw to get configured to display the site – so I went back to the drawing board and came up with the following flow based

  1. Build a production static version of the site
  2. Deploy it to the gh-pages branch as per the instructions in https://jigsaw.tighten.com/docs/deploying-your-site/
  3. To automate this process I created a custom deploy action below
    deploy": "npm run prod; deploy_time=$(date \"+%A %d-%B, %Y %H:%M:%S\") && git add build_production && git commit -m \"Build for deploy on $deploy_time\" && git subtree push --prefix build_production origin gh-pages which combines all the commands to push to gh-pages
  4. Create an HTML site on my VPS using Laravel Forge
  5. Link the gh-pages branch as the app to the site
  6. Enable quick deploy so that any changes to the gh-pages branch automatically deploys the new site
  7. Do not forget to setup SSL on the site (using the method of your choice)

So once I make changes to my site, I run npm run deploy to push it into production …