Cloud Run runs stateless containers on a fully managed environment.
Sample | Description | Deploy |
---|---|---|
Hello World | Quickstart | |
System Packages | Use system-installed binaries in your service. | |
Pub/Sub | Processing messages from a Pub/Sub push subscription | |
Image Processing | Cloud Storage & Pub/Sub-driven image analysis & transformation | |
Manual Logging | Structured logging without client library | |
Hello Broken | Something is wrong, how do you fix it? | |
Identity Platform | Authenticate users and connect to a Cloud SQL postgreSQL databases | |
Markdown Preview | Create a secure two-service application running on Cloud Run | - |
Cloud SQL (MySQL) | Use MySQL with Cloud Run | - |
Cloud SQL (Postgres) | Use Postgres with Cloud Run | - |
Service to Service Requests ➥ | Create requests to authenticated-only services | - |
Eventarc: Pub/Sub | Event-driven service with Events for Cloud Run for Pub/Sub | - |
Eventarc: Cloud Storage | Event-driven service with Events for Cloud Run for GCS | - |
For more Cloud Run samples beyond Node.js, see the main list in the Cloud Run Samples repository.
Clone this repository:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
Note: Some samples in the list above are hosted in other repositories. They are noted with the symbol "➥".
export SAMPLE=<SAMPLE_NAME>cd$SAMPLE docker build --tag $SAMPLE.
With the built container:
PORT=8080 && docker run --rm -p 8080:${PORT} -e PORT=${PORT}$SAMPLE
Overriding the built container with local code:
PORT=8080 && docker run --rm \ -p 8080:${PORT} -e PORT=${PORT} \ -v $PWD:/usr/src/app $SAMPLE
Injecting your service account key:
export SA_KEY_NAME=my-key-name-123 PORT=8080 && docker run --rm \ -p 8080:${PORT} -e PORT=${PORT} \ -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/${SA_KEY_NAME}.json \ -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/${SA_KEY_NAME}.json:ro \ -v $PWD:/usr/src/app $SAMPLE
Opening a shell in the container (e.g., updating the
package-lock.json
):Build the container.
Run the container with a shell:
PORT=8080 && docker run --rm \ --interactive --tty \ -p 8080:${PORT} -e PORT=${PORT} \ -v $PWD:/usr/src/app $SAMPLE \ /bin/bash
- Re-generate the
package-lock.json
:
rm package-lock.json npm install
Because we're using a read/write volume mount, the revised file will be written to the host's local filesystem. Once you exit the container you can add the file to version control.
- Exit the container:
Ctrl-D
Run unit tests:
npm test
Run system tests:
export GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID> npm run system-test
Note: See sample READMEs for specific environment variables needed for testing.
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE} gcloud run deploy ${SAMPLE} \ # Needed for Manual Logging sample. --set-env-vars GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT} \ --image gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
See Building containers and Deploying container images for more information.