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
gcloudCLI. This should also installgsutil.
Log into the CLI and create a new project, linking it to your billing account:
gcloud auth loginand select the Google account you linked to GCP.gcloud projects create PROJECT_IDto create a new project with a givenPROJECT_IDgcloud config set project PROJECT_IDgcloud beta billing accounts listto 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_NAMEgcloud iam service-accounts listto retrieve the email of the service account just created.gcloud iam service-accounts keys create key.json --iam-account=SA_EMAILto create aJSONkeyfile you can authenticate with in the next step.gcloud auth activate-service-account SA_EMAIL --key-file=key.jsonto 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.adminto add a role to the service account and add it to the projectgsutil mb -b on gs://BUCKET_NAMEto create a new GCS bucket withBUCKET_NAME
gsutil cp ./index.html gs://BUCKET_NAMEgsutil 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 | base64and set it as aGCP_SA_KEYsecret.- Set
PROJECT_IDto a secret calledGCP_PROJECT_ID. - Upon every push to
index.htmlon themainbranch, theupload.ymlGitHub Actions workflow will uploadindex.htmltogs://BUCKET_NAME.