{"id":13547964,"url":"https://github.com/GoogleCloudPlatform/cloud-run-microservice-template-nodejs","last_synced_at":"2025-04-02T20:31:14.344Z","repository":{"id":37925628,"uuid":"346142715","full_name":"GoogleCloudPlatform/cloud-run-microservice-template-nodejs","owner":"GoogleCloudPlatform","description":"Microservice template for Cloud Run","archived":false,"fork":false,"pushed_at":"2025-03-26T02:54:53.000Z","size":816,"stargazers_count":91,"open_issues_count":1,"forks_count":54,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-03-30T15:42:32.179Z","etag":null,"topics":["cloud-run","google-cloud","nodejs","samples","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleCloudPlatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-09T20:59:32.000Z","updated_at":"2025-03-26T02:54:55.000Z","dependencies_parsed_at":"2023-02-18T09:45:41.176Z","dependency_job_id":"5245087d-4c9b-41a3-8d76-e79159bb49d1","html_url":"https://github.com/GoogleCloudPlatform/cloud-run-microservice-template-nodejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleCloudPlatform","download_url":"https://codeload.github.com/GoogleCloudPlatform/cloud-run-microservice-template-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246887958,"owners_count":20850174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-run","google-cloud","nodejs","samples","serverless"],"created_at":"2024-08-01T12:01:03.850Z","updated_at":"2025-04-02T20:31:14.339Z","avatar_url":"https://github.com/GoogleCloudPlatform.png","language":"JavaScript","readme":"# Cloud Run Template Microservice\n\nA template repository for a Cloud Run microservice, written in Node.js. \n\n[![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://deploy.cloud.run)\n\n## Prerequisite\n\n* Enable the Cloud Run API via the [console](https://console.cloud.google.com/apis/library/run.googleapis.com?_ga=2.124941642.1555267850.1615248624-203055525.1615245957) or CLI:\n\n```bash\ngcloud services enable run.googleapis.com\n```\n\n## Features\n\n* **Express**: Web server framework\n* **Buildpack support** Tooling to build production-ready container images from source code and without a Dockerfile\n* **Dockerfile**: Container build instructions, if needed to replace buildpack for custom build\n* **SIGTERM handler**: Catch termination signal for cleanup before Cloud Run stops the container\n* **Service metadata**: Access service metadata, project Id and region, at runtime\n* **Local development utilities**: Auto-restart with changes and prettify logs\n* **Structured logging w/ Log Correlation** JSON formatted logger, parsable by Cloud Logging, with [automatic correlation of container logs to a request log](https://cloud.google.com/run/docs/logging#correlate-logs).\n* **Unit and System tests** Basic unit and system tests setup for the microservice\n\n## Local Development\n\n### Cloud Code\n\nThis template works with [Cloud Code](https://cloud.google.com/code), an IDE extension\nto let you rapidly iterate, debug, and run code on Kubernetes and Cloud Run.\n\nLearn how to use Cloud Code for:\n\n* Local development - [VSCode](https://cloud.google.com/code/docs/vscode/developing-a-cloud-run-service), [IntelliJ](https://cloud.google.com/code/docs/intellij/developing-a-cloud-run-service)\n\n* Local debugging - [VSCode](https://cloud.google.com/code/docs/vscode/debugging-a-cloud-run-service), [IntelliJ](https://cloud.google.com/code/docs/intellij/debugging-a-cloud-run-service)\n\n* Deploying a Cloud Run service - [VSCode](https://cloud.google.com/code/docs/vscode/deploying-a-cloud-run-service), [IntelliJ](https://cloud.google.com/code/docs/intellij/deploying-a-cloud-run-service)\n* Creating a new application from a custom template (`.template/templates.json` allows for use as an app template) - [VSCode](https://cloud.google.com/code/docs/vscode/create-app-from-custom-template), [IntelliJ](https://cloud.google.com/code/docs/intellij/create-app-from-custom-template)\n\n### CLI tooling\n\n#### Local development\n\n1. Set Project Id:\n    ```bash\n    export GOOGLE_CLOUD_PROJECT=\u003cGCP_PROJECT_ID\u003e\n    ```\n2. Start the server with hot reload:\n    ```bash\n    npm run dev\n    ```\n\n#### Deploying a Cloud Run service\n\n1. Set Project Id:\n    ```bash\n    export GOOGLE_CLOUD_PROJECT=\u003cGCP_PROJECT_ID\u003e\n    ```\n\n1. Enable the Artifact Registry API:\n    ```bash\n    gcloud services enable artifactregistry.googleapis.com\n    ```\n\n1. Create an Artifact Registry repo:\n    ```bash\n    export REPOSITORY=\"samples\"\n    export REGION=us-central1\n    gcloud artifacts repositories create $REPOSITORY --location $REGION --repository-format \"docker\"\n    ```\n  \n1. Use the gcloud credential helper to authorize Docker to push to your Artifact Registry:\n    ```bash\n    gcloud auth configure-docker\n    ```\n\n2. Build the container using a buildpack:\n    ```bash\n    npm run build-image\n    ```\n    \n3. Deploy to Cloud Run:\n    ```bash\n    npm run deploy\n    ```\n\n### Run sample tests\n\n1. [Pass credentials via `GOOGLE_APPLICATION_CREDENTIALS` env var](https://cloud.google.com/docs/authentication/production#passing_variable):\n    ```bash\n    export GOOGLE_APPLICATION_CREDENTIALS=\"[PATH]\"\n    ```\n\n2. Set Project Id:\n    ```bash\n    export GOOGLE_CLOUD_PROJECT=\u003cGCP_PROJECT_ID\u003e\n    ```\n3. Run unit tests\n    ```bash\n    npm run test\n    ```\n\n4. Run system tests\n    ```bash\n    gcloud builds submit \\\n        --config test/advance.cloudbuild.yaml \\\n        --substitutions 'COMMIT_SHA=manual'\n    ```\n    The Cloud Build configuration file will build and deploy the containerized service\n    to Cloud Run, run tests managed by NPM, then clean up testing resources. This configuration restricts public\n    access to the test service. Therefore, service accounts need to have the permission to issue Id tokens for request authorization:\n    * Enable Cloud Run, Cloud Build, Artifact Registry, and IAM APIs:\n        ```bash\n        gcloud services enable run.googleapis.com cloudbuild.googleapis.com iamcredentials.googleapis.com artifactregistry.googleapis.com\n        ```\n\n    * Set environment variables.\n        ```bash\n        export PROJECT_ID=\"$(gcloud config get-value project)\"\n        export PROJECT_NUMBER=\"$(gcloud projects describe $(gcloud config get-value project) --format='value(projectNumber)')\"\n        ```\n\n    * Create an Artifact Registry repo (or use another already created repo):\n        ```bash\n        export REPOSITORY=\"samples\"\n        export REGION=us-central1\n        gcloud artifacts repositories create $REPOSITORY --location $REGION --repository-format \"docker\"\n        ```\n  \n    * Create service account `token-creator` with `Service Account Token Creator` and `Cloud Run Invoker` roles.\n        ```bash\n        gcloud iam service-accounts create token-creator\n\n        gcloud projects add-iam-policy-binding $PROJECT_ID \\\n            --member=\"serviceAccount:token-creator@$PROJECT_ID.iam.gserviceaccount.com\" \\\n            --role=\"roles/iam.serviceAccountTokenCreator\"\n        gcloud projects add-iam-policy-binding $PROJECT_ID \\\n            --member=\"serviceAccount:token-creator@$PROJECT_ID.iam.gserviceaccount.com\" \\\n            --role=\"roles/run.invoker\"\n        ```\n\n    * Add `Service Account Token Creator` role to the Cloud Build service account.\n        ```bash\n        gcloud projects add-iam-policy-binding $PROJECT_ID \\\n            --member=\"serviceAccount:$PROJECT_NUMBER@cloudbuild.gserviceaccount.com\" \\\n            --role=\"roles/iam.serviceAccountTokenCreator\"\n        ```\n\n## Maintenance \u0026 Support\n\nThis repo performs basic periodic testing for maintenance. Please use the issue tracker for bug reports, features requests and submitting pull requests.\n\n## Contributions\n\nPlease see the [contributing guidelines](CONTRIBUTING.md)\n\n## License\n\nThis library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleCloudPlatform%2Fcloud-run-microservice-template-nodejs/lists"}