Serverless Wikis On Google Cloud
In a previous article I wrote about how to Run A Wiki on Microsoft Azure. In this article I will go over how to set up the same type of system, but do it on the Google Cloud Platform (GCP).
As a quick overview of why someone might chose to use Google Cloud over other Cloud providers is that google offers a much more granular control over all of your cloud infrastructure. That control allows you use more features and set them up in specific ways to meet your needs. Google Cloud resources are also often less expensive then comparable services from its competitors.
The added control and lower costs are offset by Google Clouds relatively steeper learning curve compared to other cloud providers. When you are building infrastructure in Google Cloud it gives you all of this control with the assumption that you know exactly what you are doing. It also operates with a much stricter security model where you must explicitly grant access rather than restricting access. This can lead to a significate amount of frustration as you try to figure out why your systems are not performing in ways you thought they would.
With that said I have already written out step by step guides with visuals to help walk through process of building up the infrastructure needed to run your own wiki on Google Cloud in a serverless stateless manner.
System Diagram
Lets take a look at what our finished project should look like.
What we will end up with is a Docker Container that runs in Google Cloud Run. Which is a serverless host that will spin up your container on demand and has the ability to add or remove additional containers running your same code depending on how much traffic is coming in. It can even scale all the way down to zero meaning that you are not being charged for your service if nobody is looking at it. This in my mind is the main selling point for using Google Cloud and Cloud Run to host your services.
In order to serve your container we need to store it in an Artifact Registry which you can think of like a dock yard where containers sit until they are needed by Cloud Run or another container host.
Since we cannot store any information in the container otherwise it would disappear when the container is stopped and restarted we can use a SQL database to hold all of the text that will appear on our pages as well as all of the information about how they link together and who our users are.
The databases however cannot hold things like uploaded files and images. To handle that we will need to add some kind of external file storage. Google offers this with a resources called Google Buckets. The only caveat is that you cannot attach them directly. You will need to create something know as a Service Account which allows you to pass data back and forth between your Cloud Run Container and your Google Bucket.
Source Code and Guides
All of the code needed to build the modified containers can be found in my GitHub repository at MediaWiki-GCP-CR
All of the Guides can be found in the Wiki for that GitHub repository, I will also link them individually below. But before we do lets take a look at the setup process from start to finish. These are the steps that we will follow to set up our Infrastructure in Google Cloud as well as all of the necessary steps to install the wiki and get you to your front page.
Guides
- Creating a Cloud SQL Database
- Creating Storage Buckets
- Creating a Service Account
- Creating an Artifact Registry
- Creating a Custom Docker Image
- Uploading the Custom Docker Image
- Creating a Cloud Run Instance
- Setting Up your Wiki
- Securing Cloud SQL
- Modifying and Uploading Wiki Configuration Files
- Updating Cloud Run Variables