-
Notifications
You must be signed in to change notification settings - Fork 0
Add gcp cloud function #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prajwal-pai77
wants to merge
4
commits into
main
Choose a base branch
from
gcp-cloud-serverless
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Google Cloud Function Configuration | ||
PROJECT_ID=<gcp-project-id> | ||
REGION=<gcp-region> | ||
MEMORY=128Mi | ||
TIMEOUT=120s | ||
RUNTIME=nodejs22 | ||
|
||
# Cluster Credentials | ||
DATA_API_ENDPOINT=<capella-data-api-endpoint> | ||
DB_USERNAME=<capella-cluster-username> | ||
DB_PASSWORD=<capella-cluster-password> | ||
DB_BUCKET_NAME=travel-sample | ||
DB_SCOPE=inventory | ||
DB_COLLECTION=airport |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Node.js dependencies | ||
node_modules/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Environment files | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# IDE and editor files | ||
.vscode/ | ||
.idea/ | ||
*.swp | ||
*.swo | ||
*~ | ||
|
||
# OS generated files | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
ehthumbs.db | ||
Thumbs.db | ||
|
||
# Git files | ||
.git/ | ||
.gitignore | ||
|
||
# Build outputs | ||
dist/ | ||
build/ | ||
*.tgz | ||
|
||
# Logs | ||
logs/ | ||
*.log | ||
|
||
# Runtime data | ||
pids/ | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage/ | ||
|
||
# Dependency directories | ||
jspm_packages/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# Scripts and deployment files | ||
scripts/ | ||
# *.md | ||
|
||
# Spec files | ||
*.yaml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Node.js dependencies | ||
node_modules/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage/ | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
jspm_packages/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# Environment variables | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
public | ||
|
||
# Storybook build outputs | ||
.out | ||
.storybook-out | ||
|
||
# Temporary folders | ||
tmp/ | ||
temp/ | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# OS generated files | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
ehthumbs.db | ||
Thumbs.db | ||
|
||
# IDE and Editor files | ||
.vscode/ | ||
.idea/ | ||
*.swp | ||
*.swo | ||
*~ | ||
*.sublime-project | ||
*.sublime-workspace | ||
|
||
# Google Cloud specific | ||
.gcloud/ | ||
.google-cloud/ | ||
|
||
# Deployment artifacts | ||
zips/ | ||
*.zip | ||
*.tar.gz | ||
|
||
# Local development | ||
.local/ | ||
local/ | ||
|
||
# Test files | ||
test-results/ | ||
coverage/ | ||
|
||
# Build outputs | ||
build/ | ||
dist/ | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# deployment packages | ||
*.zip | ||
|
||
# Local configuration files | ||
config/local.json | ||
config/development.json | ||
config/production.json | ||
|
||
# Backup files | ||
*.bak | ||
*.backup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# GCP Cloud Functions API for Couchbase | ||
|
||
This project demonstrates how to build a serverless API using **GCP Cloud Functions and API Gateway** that interfaces with Couchbase's Data API to manage airport data from the travel-sample dataset. | ||
|
||
**Note:** The FTS features require: | ||
1. A Full Text Search index with geo-spatial mapping on hotel documents | ||
2. The travel-sample dataset with hotel documents in the `inventory.hotel` collection | ||
3. Hotels must have geo coordinates (`geo.lat` and `geo.lon` fields) for proximity search | ||
|
||
## Prerequisites | ||
|
||
- [Node.js](https://nodejs.org/) (v22.x or later) | ||
- [Google Cloud CLI](https://cloud.google.com/sdk/docs/install) configured with appropriate credentials | ||
- Google Cloud Project with Cloud Functions and API Gateway with [services enabled](https://cloud.google.com/api-gateway/docs/secure-traffic-gcloud#enabling_required_services) | ||
- [Couchbase Capella](https://www.couchbase.com/products/capella/) cluster with Data API enabled | ||
- Couchbase [travel-sample](https://docs.couchbase.com/dotnet-sdk/current/ref/travel-app-data-model.html) bucket loaded | ||
|
||
## Setup | ||
|
||
1. Clone the repository | ||
```bash | ||
git clone https://github.com/couchbase-examples/couchbase-data-api-serverless-cookbook.git | ||
``` | ||
|
||
2. Navigate to the gcp directory: | ||
```bash | ||
cd couchbase-data-api-serverless-cookbook/gcp | ||
``` | ||
|
||
3. Install dependencies: | ||
```bash | ||
npm install | ||
``` | ||
|
||
4. Configure your environment variables: | ||
Copy the example environment file and update with your values: | ||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
Update the `.env` file with your actual values: | ||
```env | ||
# Google Cloud Function Configuration | ||
PROJECT_ID=<gcp-project-id> | ||
REGION=europe-west1 | ||
MEMORY=128Mi | ||
TIMEOUT=120s | ||
RUNTIME=nodejs22 | ||
|
||
# Cluster Credentials | ||
DATA_API_ENDPOINT=<capella-data-api-endpoint> | ||
DB_USERNAME=<capella-cluster-username> | ||
DB_PASSWORD=<capella-cluster-password> | ||
DB_BUCKET_NAME=travel-sample | ||
DB_SCOPE=inventory | ||
DB_COLLECTION=airport | ||
``` | ||
|
||
5. Authenticate with Google Cloud: | ||
```bash | ||
gcloud auth login | ||
``` | ||
|
||
## FTS Index Setup | ||
|
||
Before using the hotel search functionality, you need to create a Full Text Search index. Use the Node.js script provided in the root of the repository. | ||
|
||
See [../scripts/README.md](../scripts/README.md) for detailed instructions on creating the required `hotel-geo-index` for geo-spatial hotel searches. | ||
|
||
|
||
## Deployment | ||
|
||
### Deploy Cloud Functions | ||
|
||
First, deploy your Cloud Functions: | ||
|
||
```bash | ||
npm run deploy-gcp-cloud-function | ||
``` | ||
|
||
This will deploy all functions defined in the `FUNCTIONS` array in `config.js`. | ||
|
||
### Deploy API Gateway | ||
|
||
After functions are deployed, run the API Gateway deployment: | ||
|
||
```bash | ||
npm run deploy-api-gateway | ||
``` | ||
|
||
This script will: | ||
1. Create a new API Gateway | ||
2. Set up Cloud Function integrations | ||
3. Create a gateway and output the API endpoint URL | ||
|
||
## Testing | ||
|
||
### Integration Testing | ||
|
||
The integration tests will automatically discover your API Gateway endpoint and test all API operations through it: | ||
```bash | ||
npm run test | ||
``` | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.