{GCP Cloud Storage}HTTP を使用した静的ウェブサイトのホスティング

 

https://cloud.google.com/storage/docs/hosting-static-website-http?hl=ja
https://zenn.dev/kiyomaryu/articles/1b7abe032f2f0e
https://cloud.google.com/storage/docs/access-public-data?hl=ja
https://cloud.google.com/storage/docs/access-control/making-data-public?hl=ja#permissions-cli

 

-- 1. 前作業

gcloud init
gcloud auth list

gcloud --version

gcloud projects create project01-9999999 \
--name="project01"

gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet

gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111

gcloud services enable compute.googleapis.com --project project01-9999999

gcloud components update


-- 2. バケットの作成

gsutil mb -c standard -l asia-northeast1 gs://bucket123
gsutil ls


-- 3. サイトのファイルのアップロード


vim index.html

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>My Website Home Page</title>
</head>
<body>
  <h1>Welcome to my website</h1>
  <p>Now hosted on GCP S3!</p>
</body>
</html>

 

gsutil cp index.html gs://bucket123

gsutil ls -r gs://bucket123

 

-- 4. ファイルの共有

gsutil iam ch allUsers:objectViewer gs://bucket123


-- 5. 動作確認


curl http://storage.googleapis.com/bucket123/index.html

 

-- 6. クリーンアップ

gsutil rm -r gs://bucket123
gsutil ls

 


gcloud projects list

gcloud projects delete project01-9999999 \
--quiet