Skip to content

Instantly share code, notes, and snippets.

@tym-xqo
Last active July 27, 2018 17:09
Show Gist options
  • Save tym-xqo/d6c6f31ef202f3fc67b9f0b54b50fc90 to your computer and use it in GitHub Desktop.
Save tym-xqo/d6c6f31ef202f3fc67b9f0b54b50fc90 to your computer and use it in GitHub Desktop.
Gcloud static site deployer

Usage

  • Download gcloud-static-deploy.sh
  • chmod +x gcloud-static-deploy.sh; mv gcloud-static-deploy.sh /usr/local/bin/gcloud-static-deploy
  • cd to directory with your static site, then invoke the script with gcloud-static-deploy

NB: Assumes you have httpie installed, in addition GCloud SDK installed and authorized

#!/bin/sh
ZONE=meta-jacknife-fun
DOMAIN=meta-jackknife.fun
SUBDOMAIN=$(http -b https://unknown-cheese.now.sh)
echo "Deploying to $SUBDOMAIN.$DOMAIN ..."
gcloud dns --project=lexical-cider-93918 \
record-sets transaction start \
--zone=$ZONE
gcloud dns --project=lexical-cider-93918 \
record-sets transaction add c.storage.googleapis.com. \
--name=$SUBDOMAIN.$DOMAIN \
--ttl=300 \
--type=CNAME \
--zone=$ZONE
gcloud dns --project=lexical-cider-93918 \
record-sets transaction execute \
--zone=$ZONE
gsutil mb -p giant-youth-06 \
-c regional -l us-central1 \
gs://$SUBDOMAIN.$DOMAIN
gsutil web set -m index.html gs://$SUBDOMAIN.$DOMAIN
gsutil iam ch allUsers:objectViewer gs://$SUBDOMAIN.$DOMAIN
gsutil cp ./* gs://$SUBDOMAIN.$DOMAIN/
echo "Deployed to http://$SUBDOMAIN.$DOMAIN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment