Automating Xojo Web 2 Deployments on macOS or Linux
Following up on my article to set up a server:
I want to show you an approach to automate the deployment.
Now that you have your great new server, you probably started to deploy your first Xojo Web Apps. You are compiling your application, and then you are uploading the files with the SFTP browser of your choice.
But perhaps you ran already into a few challenges, for instance, that you have, of course, to shut down your Linux service, running your App, before you are doing the upload. Finally, you have to ensure to start this service again after the upload has finished.
That's a lot of work, at least compared to the ease of Xojo Cloud and the Xojo IDE, where you only need to click this shiny little button "Deploy":
Compared to Xojo Cloud, our solution is a real pain in the neck.
Workaround to automate the upload process of Xojo Web 2
But there is hope! With the following approach you can mimic the Xojo Cloud behavior. All you need to do, is "Building" your project under Linux and the upload will be done automatically:
Preparing your Xojo Web 2 project
First you need to add a "build step". Call it "deployToServer". It is important to place this step after(!) your build step (you can use dragging to adjust the position).
The deployToServer build step needs to contain some code looking somehow like this:
Var result as string // Execute the deployment script in a shell result = DoShellCommand("localPathToYourApp/deploy.sh") // when finished, show the URL of my Xoho Web App 2 showUrl("https://xojodocs.com")
The path has, of course, to correspond with the local location of your Xojo Web App.
With this we are using Xojo Script in a post-build script to execute an own script and displaying our updated app in the browser afterwards.
Creating a shell script for deployment
Now create a file called deploy.sh (or whatever name you specified in the step above) and populate it with this following code. Of course, here again, you have to make the necessary changes, according to your server credentials:
#!/bin/sh echo "STOP MyXojoService before uploading" ssh youruser@yourdomain 'sudo systemctl stop yourXojo.service' rsync -avz --delete localPathToYourAppBuildFolder/ youruser@yourdomain: remotePathOfYourApp/ echo "START MyXojoService" ssh youruser@yourdomain 'sudo systemctl start yourXojo.service' exit 0
This looks easy but can get a bit confusing when using the absolute paths. That's why I'm posting you here one of my working examples:
echo "STOP xojoDOCs" ssh email@example.com 'sudo systemctl stop xojoDOCs.service' rsync -avz --delete /Users/jmu/xojo/xojoDOCs/Builds\ -\ xojoDOCs/Linux\ 64\ bit/xojoDOCs/ firstname.lastname@example.org:/var/www/html/xojoDOCs/ echo "START xojoDOCs" ssh email@example.com 'sudo systemctl start xojoDOCs.service' exit 0
If you now hit "Build" for Linux, the Xojo IDE will compile your project and then copy all your files on your server and afterward open the URL of your Xojo Web App 2.
Now the deployment of a Xojo Web 2 Application should be as easy for you as compiling a console or Desktop Application!
Perhaps you can build a similar approach for Windows as well based on this concept, but this is out of scope of this tutorial.
Sign in or become a jeannot-muller.com member to join the conversation.
Just enter your email below to get a log in link.