Skip to content

Commit

Permalink
🔧 Add lifecycle to GCS bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
nkmr-jp committed May 15, 2022
1 parent fa278bf commit c4e8edc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#See: https://cloud.google.com/functions/docs/2nd-gen/getting-started#pubsub
# See:
# https://cloud.google.com/functions/docs/2nd-gen/getting-started#pubsub
# https://cloud.google.com/storage/docs/lifecycle-configurations#delete-objects-json

REGION=asia-northeast1
PROJECT_ID=$(shell gcloud config get-value project)
Expand Down Expand Up @@ -26,10 +28,12 @@ init:
@echo "---- create bucket and set versioning. ----"
-gsutil mb -c regional -l $(REGION) gs://$(BUCKET_NAME)
-gsutil versioning set on gs://$(BUCKET_NAME)
-gsutil lifecycle set ./lifecycle.json gs://$(BUCKET_NAME)
@echo
@echo "---- create bucket and set versioning, for test. ----"
-gsutil mb -c regional -l $(REGION) gs://$(BUCKET_NAME)-test
-gsutil versioning set on gs://$(BUCKET_NAME)-test
-gsutil lifecycle set ./lifecycle.json gs://$(BUCKET_NAME)-test
@echo
@echo "---- check resources in google cloud console. ----"
make open
Expand Down
26 changes: 26 additions & 0 deletions lifecycle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"lifecycle": {
"rule": [
{
"action": {
"type": "SetStorageClass",
"storageClass": "NEARLINE"
},
"condition": {
"age": 1,
"matchesStorageClass": ["REGIONAL", "STANDARD"]
}
},
{
"action": {
"type": "SetStorageClass",
"storageClass": "COLDLINE"
},
"condition": {
"age": 2,
"matchesStorageClass": ["NEARLINE"]
}
}
]
}
}

0 comments on commit c4e8edc

Please sign in to comment.