Azure Ghost is a powerful tool for automating tasks on Azure. It's a free and open-source project, and its setup and deployment process is relatively straightforward.
To get started, you'll need to install the Azure Ghost CLI, which can be done using pip. You can install it by running the command `pip install azure-ghost`.
The Azure Ghost setup process involves creating a configuration file, which can be done using the `az ghost config` command. This command will guide you through the process of setting up your Azure Ghost instance.
With Azure Ghost up and running, you can start automating tasks on Azure. The deployment process involves creating a deployment package, which can be done using the `az ghost deploy` command. This command will package your Azure resources into a deployment package that can be easily rolled out across your Azure environment.
App Service Configuration
To update Ghost to the latest version on Azure App Service, you'll need to make some code modifications. Felix Rieseberg's repo has a one-click deployment setup, but it's still using Ghost 0.11.9, not the latest version.
You can find all the changes made to update Ghost to the latest version in Felix's ghost repo on GitHub.
Felix tried to use the new CLI tool to set up a blog, but it didn't work reliably on Azure's app service.
The new CLI tool is supposed to make it easier to set up a Ghost blog, but it requires full access to a server, which isn't possible on Azure's app service.
Database and Infrastructure
Creating the Ghost Database is a crucial step in setting up your Azure Ghost blog. Pre-1.0 Ghost used to create a SQLite database automatically, but now the CLI tool handles this task.
The new CLI tool can create the database, but it's not easily accessible in Azure App Service. I had to run the knex-migrator manually on my machine to create the database locally, and then FTP it up to Azure.
To create the database, you'll need to set up a config.development.json and/or a config.production.json file in the root with the database you want. For example, I'm still using SQLite.
Infrastructure as Code is essential for managing your Azure resources. I chose Azure Bicep for our solution, as I'm most proficient in it.
Private endpoints can be enabled in Azure Bicep, but they're not necessary for our case, and we're saving on costs by disabling them.
Creating Our Base Infrastructure
Creating our base Azure infrastructure is a crucial step in setting up our blog. We'll be using the Azure CLI, also known as az cli, to create the basics.
To start, we need to create a database. In the past, Ghost used to create a SQLite database automatically, but now we need to use the CLI tool to create the database. This can be a bit tricky, especially when running on Azure App Service.
We can create a db.js file in the root of our project to help with this process. After running npm install, we can use this file to create the database locally and then FTP it up to Azure. I've done this myself and can attest to its effectiveness.
For our project, we're using SQLite, which is a great choice for simplicity. However, we could also use MySQL-in-app with Azure App Service, but this has its own limitations, such as not being able to access the database remotely.
Now that we have our database set up, we can move on to creating our infrastructure as code. We're using Azure Bicep for this, which is a great choice for those proficient in it.
Creating a Ghost on Container Instance
Creating a Ghost on Container Instance can be a straightforward process. We'll be using Azure Container Instances to host Ghost, which is a popular open-source blogging platform.
To get started, we'll need to create a container instance on Azure. This can be done through the Azure portal or using the Azure CLI.
Azure Container Instances allows us to run a container instance in a matter of minutes, without having to provision a virtual machine. This makes it a great option for development and testing purposes.
We can also use Azure Container Instances to host our Ghost blog, which will allow us to scale our application as needed.
To host Ghost, we will now use Azure Container Instances. This will give us the flexibility to easily deploy and manage our application.
Deployment and Performance
Deploying to Azure is a straightforward process. You can start by logging into your free Azure account and clicking on App Services. From there, click on + Add and choose a Web App, then select the Free Plan.
To get Ghost running properly, you'll need to update the node version to the latest LTS version, which is 8.9.4 as of this writing. This can be done by clicking on your new app service and then on Application Settings, and setting the WEBSITE_NODE_DEFAULT_VERSION to 8.9.4.
Setting up deployment for your site is also a breeze. You can use the Github integration to automatically redeploy the site whenever you push to a particular branch. This will also install any dependencies during deployment, making it easy to keep your site up-to-date.
Deploying
To deploy your app to Azure, start by logging in to your free Azure account and clicking on App Services.
Click on + Add and choose a Web App, then select your app name and choose the Free Plan.
Azure defaults to an old node version, so update it to the latest LTS version by clicking on your new app service and setting the WEBSITE_NODE_DEFAULT_VERSION to 8.9.4.
You can also set up deployment for your site using the Github integration, which will automatically redeploy the site anytime you push to a particular branch.
Setting up deployment options involves choosing your source, and for this, I chose Github and filled in all my settings.
Having multiple branches for easier maintenance is helpful, so I set up a few branches, including the ghost branch for unchanged Ghost releases and the azure branch for necessary changes to get it running on Azure.
Static Site Performance
Serving your site like a static site can greatly benefit performance, especially if it doesn't get updated often. This is because it can be served almost always from cache.
You can set the cache headers right in Ghost to get this benefit with Azure CDN, which will act as a caching reverse proxy honoring the cache headers from your site. To do this, edit the config.production.json file in the root.
By default, Ghost will set the cache time to zero, so you'll want to bump that number to whatever you're most comfortable with. For example, setting it to 72,000 seconds, or 20 hours, can be a good starting point.
Azure CDN can take up to 6 hours to propagate changes through their network, so be patient and don't fret if your new endpoint returns 404s during that time.
Sources
- https://www.wattpad.com/902201294-all%27s-fair-in-love-and-war-atla-reader-insert-the
- https://blog.novanet.no/ghost-on-azure-with-docker/
- https://www.chadly.net/blog/ghost-on-azure
- https://hybridbrothers.com/hosting-a-blog-with-azure-container-apps/
- https://xaviergeerinck.com/2022/08/09/running-ghost-on-azure-cli/
Featured Images: pexels.com