Demo using Google Cloud Storage to host a static site!
Presented at Greer Programmers Group at Aug 10, 2020 in conjunction with these slides.
For more, see the Hosting a static website tutorial.
- Sign up for Google Cloud Platform if you haven't already.
- Install the
gcloud
CLI. This should also installgsutil
.
Log into the CLI and create a new project, linking it to your billing account:
gcloud auth login
and select the Google account you linked to GCP.gcloud projects create PROJECT_ID
to create a new project with a givenPROJECT_ID
gcloud config set project PROJECT_ID
gcloud beta billing accounts list
to find your billing account IDgcloud beta billing projects link PROJECT_ID --billing-account BILLING_ACCOUNT_ID
Create an app-specific, rights-restricted service account:
gcloud iam service-accounts create SA_NAME
gcloud iam service-accounts list
to retrieve the email of the service account just created.gcloud iam service-accounts keys create key.json --iam-account=SA_EMAIL
to create aJSON
keyfile you can authenticate with in the next step.gcloud auth activate-service-account SA_EMAIL --key-file=key.json
to act as the service account in the following CLI commands.gcloud projects add-iam-policy-binding PROJECT_ID --member=serviceAccount:SA_EMAIL --role=roles/storage.admin
to add a role to the service account and add it to the projectgsutil mb -b on gs://BUCKET_NAME
to create a new GCS bucket withBUCKET_NAME
gsutil cp ./index.html gs://BUCKET_NAME
gsutil iam ch allUsers:objectViewer gs://BUCKET_NAME
- Your file is available at https://storage.googleapis.com/BUCKET_NAME/index.html 🚀. This one is available here.
cat key.json | base64
and set it as aGCP_SA_KEY
secret.- Set
PROJECT_ID
to a secret calledGCP_PROJECT_ID
. - Upon every push to
index.html
on themain
branch, theupload.yml
GitHub Actions workflow will uploadindex.html
togs://BUCKET_NAME
.