ColdFusion (Railo) on Microsoft Azure Websites with IntelliJ IDEA — Part 2
September 28, 2014
Posted by on
In Part 1 of this series, I showed how to setup your project on Railo so that you could publish your CFML to Microsoft Azure Websites. You should have your project in a state that you want published on the web.
For this part, you will need to have an Azure account. You can sign up for one at http://azure.microsoft.com. Remember, BizSpark and certain MSDN members get free credits on Microsoft Azure.
- Login to the Microsoft Azure “Management Portal”
- At the time of writing, there are two versions of the portal — the Classic and New. I’m going to show the Classic portal as it seems to be changing the least at the moment — but I’m sure the New portal will eventually replace it.
- Create a new “Custom” Website
- After you’ve logged into the Management Portal, click on the “+ New” button on the bottom of the site.
- Chose “Compute” -> “Website” -> “Custom Create”
- Chose a URL for the site, Web Hosting Plan, and if you want a database. Don’t chose the “Publish from Source Control” at this point — we will set this up later.
- It will launch the new site. This will take a few minutes. Once you see “running” on the dashboard, click on it to modify the settings of the site.
- Click on Configure to configure the site.
- Enable Java by setting a version. This will disable PHP, Python and .NET processing.
- Make sure to select Tomcat as your container.
- Your choice on 64 or 32 bit. Railo doesn’t care which is running.
- Web Sockets will allow for outgoing connections from Railo to outside servers (such as HTTP calls). If you don’t do this, keep it off.
- Always On will keep the site “warm” if it is not in active use. If this is off, Azure will unload it from memory if there is not traffic to the site within a half-hour.
- Scroll down to Default Documents. Add index.cfm. You are free to remove the other options if you wish.
- Hit “Save” It will take about 5 minutes for Websites to update your site to use Java.
- Upload your site to Azure (Using FTP)
- Click back to the Dashboard of your site. Scroll down about half way through the page and find your FTP credentials.
- Using your favorite FTP client, login to this FTP site.
- Change to the /site/wwwroot/webapps/ROOT/ folder on the remote side. This is where your files will be served out of.
- Delete the files that exist in the ROOT folder. Upload ALL the files that exist in the output of your exploded WAR directory (in my case, E:\Projects\SampleWebsite\out\artifacts\SampleWebsite_war_exploded\).
- In some cases, you may need to restart the website. You can do this via the management portal and clicking on “STOP” on the bottom of the page. You can then click “START” to restart it.
- The first load after you upload the files can take 30 seconds. Don’t be alarmed about this — subsequent loads should be much faster after Railo is loaded into memory.
- Keep uploading subsequent changes to your code and play around with settings in Azure. For example, if you want a “custom domain”, you can change the site to a Standard plan instead of the free one. You can also configure IntelliJ to automatically upload changes via FTP when you deploy a site.
- Upload your site to Azure (Using GIT)
- Deploying via GIT is a pretty cool concept, but it does take a few additional steps to get working. First, we will need to create a new artifact in IntelliJ. This is so we can keep our GIT repository separate from our working one (if we are using GIT for source control).
- Right-Click on the SampleWebsite Module in the Project view. Chose Open Module Settings (or you can press F4)
- Click on the Artifacts tab.
- Add a new Artifact “Web Application: Exploded” -> Empty
- Give the new artifact an obvious name, like Azure Push.
- Make a note of the output directory name. This will be the root of your new GIT repository
- Under Output Layout, click the create directory button to add a new directory named “webapps”
- Add another directory below that named “ROOT” (caps matter)
- Under Available Artifacts on the right-column, drag “SampleWebsite war:exploded” to be under ROOT
- Click Apply, then OK to get out of the Artifact setup.
- Go back to the Azure Management Portal. Open your site, and go to the dashboard.
- FTP into the site using the site using the instructions above. You don’t need to upload the files, but you DO need to remove all the files in ROOT in order to get a clean site started.
- Go back to the site dashboard.
- Click “Setup Deployment From Source Control”
- Click on “From Local GIT Repository”
- Load your GIT client (like git bash), and go to the output directory of the artifact we just created.
- Follow the commands on the Azure site on how to commit your initial files to your local GIT repository. Don’t clone the existing site.
- After you’ve committed your first file, and connected it to Azure GIT, do a git add * , and commit those files to your site.
- Your Azure site may need to be restarted after your first commit. I’ve seen it both ways. If it still shows a generic Azure is running Java page, try restarting the site.
- In order to refresh the site’s contents, follow the following steps :
- In IntelliJ, Go to the Rebuild Menu -> Rebuild Artifacts -> Azure Push -> Build. This will refresh your site’s artifact. DO NOT CHOSE REBUILD OR CLEAN — these will remove the GIT database files and you will have to re-connect it to GIT.
- In GIT, add *, then commit. This should update the site with the latest.
And that is it. A few notes, however :
- You can’t deploy .WAR files onto Azure websites. It doesn’t work for some odd reason — and when it does (it happens sometimes), it breaks your site because of partial loads.
- It seems that connections to Amazon S3 are blocked. You can’t use the s3:// commands.
- If you use Microsoft’s Azure SQL Server, you can’t use any ORM (hibernate). Azure SQL Server requires some changes to the SQL Statements to allow for clustered indexes. You can use their “free” MySQL instance. Manual SQL statements via Stored Procs and CFQUERY work fine.
- If you do things like update Railo or upload files locally on your machine, make sure that you update your local project or those files may not make it into your deployed project on Azure.
Hope this tutorial gets you in the right path! I’ve been deploying a few sites using this method with great success. (I’m using GIT to deploy my sites — it’s already in my toolchain and seems to work well).