From b22bcb606f3a7517233a110e12ef9094fbccc727 Mon Sep 17 00:00:00 2001 From: soneda-yuya Date: Fri, 24 Jan 2025 19:04:40 +0900 Subject: [PATCH] chore(server): fack gcs server for local development --- docker-compose.yml | 7 +++++++ server/.env.example | 6 +++--- server/Makefile | 10 +++++++++- server/README.md | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f764f2a101..6677aeaa14 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,3 +20,10 @@ services: - 27017:27017 volumes: - ./mongo:/data/db + gcs: + image: fsouza/fake-gcs-server + ports: + - 4443:4443 + volumes: + - ${PWD}/tmp/gcs:/storage + command: -scheme http diff --git a/server/.env.example b/server/.env.example index 587e750303..1ca8ae9154 100644 --- a/server/.env.example +++ b/server/.env.example @@ -9,9 +9,9 @@ REEARTH_ASSETBASEURL=https://localhost:8080/assets REEARTH_DEV=false # GCP -GOOGLE_CLOUD_PROJECT= -GCS_BUCKETNAME= -GCS_PUBLICATIONCACHECONTROL= +REEARTH_GOOGLE_CLOUD_PROJECT= +REEARTH_GCS_BUCKETNAME= +REEARTH_GCS_PUBLICATIONCACHECONTROL= # Local Auth serv REEARTH_AUTH0_DOMAIN=https://example.auth0.com diff --git a/server/Makefile b/server/Makefile index 75b897f0b7..c9dd2b4b82 100644 --- a/server/Makefile +++ b/server/Makefile @@ -19,6 +19,8 @@ help: @echo " dev Run the application with hot reloading" @echo " run-app Run the application" @echo " run-db Run the MongoDB database using Docker Compose" + @echo " up-gcs Run the fake-gcs-server using Docker Compose" + @echo " down-gcs Stop the fake-gcs-server using Docker Compose" @echo " gql Generate GraphQL code include dataloader" @echo " mockuser Create a mock user by executing a curl request" @echo " schematyper Generate schema using schematyper" @@ -60,6 +62,12 @@ gql: go generate ./internal/adapter/gql/gqldataloader go generate ./internal/adapter/gql +up-gcs: + docker compose -f ../docker-compose.yml up -d gcs + +down-gcs: + docker compose -f ../docker-compose.yml down gcs + mockuser: curl -H 'Content-Type: application/json' -d '{"email": "mock@example.com", "username": "Mock User"}' http://localhost:8080/api/signup @@ -67,4 +75,4 @@ schematyper: go run $(SCHEMATYPER) -o $(MANIFEST_DIR)/schema_translation.go --package manifest --prefix Translation ./schemas/plugin_manifest_translation.json go run $(SCHEMATYPER) -o $(MANIFEST_DIR)/schema_gen.go --package manifest ./schemas/plugin_manifest.json -.PHONY: lint test failcheck e2e build dev-install dev run-app run-db gql mockuser schematyper +.PHONY: lint test failcheck e2e build dev-install dev run-app run-db gql up-gcs down-gcs mockuser schematyper diff --git a/server/README.md b/server/README.md index 19ee54a263..95ccd2e9e3 100644 --- a/server/README.md +++ b/server/README.md @@ -3,3 +3,37 @@ # reearth/server A back-end API server application for Re:Earth + +## Storage + +Visualizer is compatible with the following storage interfaces: + +- [Google Cloud Storage](https://cloud.google.com/storage) +- [Amazon S3](https://aws.amazon.com/s3/) +- Local File System + +### Storage Configuration + +To use these storage interfaces, you need to set the following environment variables in order of priority: 1. `REEARTH_GCS_BUCKETNAME`: Set this to use Google Cloud Storage. 2. `REEARTH_S3_BUCKET_NAME`: Set this to use Amazon S3. + +If neither `REEARTH_GCS_BUCKETNAME` nor `REEARTH_S3_BUCKET_NAME` is configured, the local file system will be used as the default storage interface. + +Additionally, `REEARTH_ASSETBASEURL` is a required environment variable that is used across all storage types. This should be set to the base URL for accessing your stored assets. + +### Testing GCS Locally + +1. `make gcs` ([fake-gcs-server](https://github.com/fsouza/fake-gcs-server) image is up) + +2. create a bucket + +```shell +curl -X POST http://localhost:4443/storage/v1/b\?project\=your-project-id \ + -H "Content-Type: application/json" \ + -d '{ + "name": "test-bucket" + }' +``` + +3. set `REEARTH_GCS_BUCKETNAME` to `test-bucket` + +※ project name and test name is anything you want