Hosting static sites on Google App Engine is a sweet thing as GAE provides a free tier of 1GB data storage and traffic for free, which is more than enough for most static sites.
Static sites are made up of HTML, CSS, and Javascript (if necessary). They require no database design or web programming.
Simply put, every visitor sees the same content when they visit a static website.
Using the Cloud Shell code editor (beta), let’s host a static website on GAE.
First, create a new project on Google Cloud
-
Take note of the project id (in my case, it’s hello-coffee-cup)
-
Navigate to your projectās App Engine dashboard and create your project’s App Engine application
-
Select python for the project’s language (this does not matter for static sites)
-
You might have to enable billing
Once done, you should see this:
Next, create your application
I have set up a simple app for this purpose. I named it hello-coffee-app. Download it here.
Take note of the appās structure:
- the www folder contains the static website content, and
- the app.yaml file is the applicationās configuration.
Now, let’s publish the site
-
Back in you project’s console, open the cloud shell (the first icon on the top right)
-
In the cloud shell window, click the second icon on the right side of its navigation to launch the code editor
-
Once in the code editor, drag and drop the hello-coffee-app folder into the left side bar of the code editor, just beneath your google account username
-
In the cloud shell, run the below command to select your project
gcloud config set project <yourprojectid>
(in my case:gcloud config set project hello-coffee-cup
) -
Then run the below command to navigate to the appās directory
cd hello-coffee-app
-
Next, to deploy, run
gcloud app deploy
-
Choose your preferred region and enter
Y
to confirm.
You can now see your website online via your-project-id dot appspot dot com.
You may prefer to run the commands and control things on your local machine. To do this, you will have to download the Cloud SDK. See here for more.