Google App Engine is a great way to host your Polymer application using Google infrastructure.
You can sign up for a Google Cloud Platform free account.
There are multiple ways to host web app on GCP, but my favorite one is using GAE.
The scripts below are based on the Using Static Files guide and Polymer Gmail by @ebidel repository.
-
Install the gcloud command line tools
curl https://sdk.cloud.google.com | bashDetailed instructions can be found here
-
Inititalize gcloud
gcloud initIn this step you will be asked to login to your GCP account and set default settings, such as project, zone & region, etc.
-
Create a new GCP project using the Developers Console
-
Add
app.yamlto your project root folderruntime: python27 api_version: 1 threadsafe: yes handlers: - url: /bower_components static_dir: bower_components secure: always - url: /images static_dir: images secure: always - url: /(.*).(html|js|json|css) static_files: \1.\2 upload: (.*)\.(html|js|json|css) secure: always - url: / static_files: index.html upload: index\.html http_headers: Link: '</scripts/app.js>; rel=preload; as=script, </elements/elements.html>; rel=preload; as=document, </styles/main.css>; rel=preload; as=style' # Access-Control-Allow-Origin: "*" secure: always skip_files: - ^(.*/)?app\.yaml
This is the configuration file for the GCP project. It sets a python runtime environment and static file handlers. The configuration utilizes GAE HTTP/2 capabilities in order to minimize load time for HTTP/2 compatible browsers. Please note : this also ensures https, if you wish to use custom domains supporting http only you will need to remove all the 'secure: always’ entries.
-
Add a bash script to build & deploy the application
#!/usr/bin/env bash GAE_PROJECT=psk DEPLOY_VERSION=$1 if [ -z "$DEPLOY_VERSION" ] then TAG=`git describe --abbrev=0` # GAE doesn't allow periods DEPLOY_VERSION=${TAG//.} fi # Build it. echo "Building $DEPLOY_VERSION" gulp cp app.yaml dist/app.yaml echo "Deploying $DEPLOY_VERSION" gcloud preview app deploy dist/app.yaml --project $GAE_PROJECT --promote --version $DEPLOY_VERSION
You have to set
GAE_PROJECTvariable to your GAE project id. A deploy version can be provided as a parameter for the script, if not provided the latest git tag will be used. -
Add execution permission to the script
chmod +x deploy.sh -
Run the deploy script
Without version argument in order to use the latest git tag
./deploy.shOr with a version argument (according to GAE version limitations)
./deploy.sh v100The URL to your live site is listed in the output.
Enjoy!