Disclaimer: This really isn't a tutorial, more of just some things I did and my thoughts.
So here I am going to go through my learning and usage of the Google Cloud Platform, or GCP for short. This article roughly summarizes what I did to create a docker based web server with a database on GCP.
So awhile back I built a fantasy football draft board website for fun. I built it with PHP using the Symfony framework and Aurelia. Hosting was done on 1&1 and over all I was not satisfied. Performance was meh, php and websockets are not great and I had very little control over the server. The next year I went ahead and rewrote the whole thing. This time I used node and Adonis and Vue on the front with hosting on AWS. Performance skyrocketed with almost all API calls returning under 100ms the sweet spot and I had web sockets for live notifications. AWS worked well but ended up being quite expensive (relative) after the trial for a website sitting there with no traffic. So now I am trying out GCP to see how I like it.
The first step was of course setting up an account with GCP. This was as easy as can be since it just links to your Google account.
Next was launching a VM. For my use I will just be using docker to run the website since docker makes it easy to manage dev/test/prod server configuration and local dev. Looking through the product list it was obvious to me that compute engine is what I needed.
Once you get your account you can go into the GCP console and from there getting to the compute engine is easy. Creating a vm is simple, you pick where you want it and how beefy to make it. For me I am just playing around, so a micro instance was sufficient. Now since I plan to only run things on the server from docker I went ahead and chose the "container optimized OS" more on that later.
Since I am using docker and containers I wanted a private secure place to store my images. Fortunately GCP makes it easy to create your own registry and push/pull from it. Simply follow the docs.
Getting to the correct networking product took a little more effort but I eventually found that the VPC was what I needed. Using the VPC in hind sight is quite easy, but I had a lot of issues due to the VM image I selected. What I wanted was to block all connections that were not from me. Creating a firewall rule with my ip as a filter works great.
I still do not know exactly what was wrong but selecting that container optimized os (chromium os) caused me all sorts of issues. Basically I ssh-ed into the server, ran docker pull on my image, and then docker run --network host and no matter what I could not get access to the website. I thought maybe something was up with docker so I even loaded a Go binary bare bones "hello world" website. Running the binary resulted in "permission denied". I then gave said executable 777 permissions as a sanity check (intending to revert), but still "permission denied." Sudo run, but still permission denied. At that point I abandoned the VM and created a new one with a minimal ubuntu and installed docker. Everything worked fine from there. ¯_(ツ)_/¯
GCP has several varieties of databases and database services. After some research their cloud SQL product is what I needed. It allows you to make a MySQL or Postgres database. The process to create it was simple and similar to creating a compute engine VM. One thing I liked was that it can load and run a SQL file stored on the platform. Following the docs/tooltips/help links I uploaded a small script to create my tables and foo data. Worked like a charm.
Linking the web VM to the MySQL instance was quite easy with a quick edit I was able to limit access to who could get to the server.
So lets see how GCP compares to AWS.
- Clearer docs
- Easier setup overall
- AWS was a little easier to debug problems
- AWS performance seems a little higher in response time (tentative)
Ultimately the setup between both of them is pretty similar and due to that GCP could seem easier because I already have used a similar product.
I like GCP so far. Everything was pretty easy to use and setup, with the exception of that strange VM image which still confuses me. The docs were informative and were genuinely helpful. I will have to use it more in order to give a better assessment over all but so far it has my thumbs up.