How I migrated to the cloud

2022-04-07 | 610 words

I decided to move all my small websites from the company server to the cloud and get rid of Wordpress at the same time, because I’m a Wordpress hater. I decided to migrate to Azure, because I’m a Microsoft fanboy and with one condition, it has to be completely free, because I’m stingy.

Azure logo

Migration of blogs

This blog, the documentation of the construction of our house at domecek.skoula.cz and the website of our winery vinarstvojuracek.sk were the ones I wanted to migrate.

The obvious choice was the Azure Static Web Apps service, which is designed for static websites and is free. When setting up a website in Azure, you pair your GitHub account, choose a framework or generator, and a workflow file is inserted into the chosen repository, which defines the build process. The build process runs on GitHub (GitHub Actions) automatically when changes are pushed.

I chose Hugo generator. The best thing about it is the installation. Just download hugo.exe and put it in the path, that’s it, everything is in that exe. Please compare this to installing Ruby and then Jekyll. However, the binary is only needed for local testing - Hugo is a very fast generator and builds this entire website (full rebuild) in half a second. However, I didn’t understand the syntax of the templates and, like the entire Go language, it is very unpleasant for me.

Why not use GitHub pages?

They are free only for public repositories and support only Jekyll.

Migration of weather stations and other things

It was more complicated to migrate my two projects, the weather station pi-dashboard and the heating station pi-dashboard-2. Both projects are similar - the basis is a Raspberry, which obtains data (in the first case from Arduinos, in the second case by scraping a local heating dashboard), saves it to MySQL and at the same time uploads it via SSH to the server, where it is displayed on a web page (Vue). Where to store data for free in the cloud? Azure offers a free (with certain limitations) NoSQL database called Cosmos DB. It even has a SQL interface (for selects) and a REST API, but I couldn’t log in to it for the life of me. So, I used the official Python package and added it to my cron scripts. I also upload webcam images there, in Base64 (keeping only one record).

But how do I retrieve the data from the DB? I created web dashboards in Vue and Svelte (again, using Static Web Apps), but as I mentioned, the REST API for Cosmos DB was beyond my abilities.

The answer is App Service. It has some limitations (no custom domain, limited CPU time) and it’s essentially a Python app (specifically Flask, but you can choose PHP, .NET, etc.) that uses the same package I use on the Raspberry Pi to access Cosmos DB, retrieve the data, and return it in JSON format.

Here’s a professional diagram of how it all works:

Diagram of how it works - migration to Azure cloud

Source

The source code is not public this time, but I will show the final migration.

pi-dashboard -> https://ledtech.skoula.cz

pi-dashboard-2 -> haha, the heating in our home is not a public utility

Conclusion

* I pay $1** for two domains in Azure DNS. Because Static Web Apps can use a custom domain, but the registrar must support ALIAS or ANAME records, or CNAME on the apex domain. From what I’ve seen, only Websupport supports this, and they have expensive domains…

** I don’t pay, I have a $200 bonus credit for the first year.