If you want to avoid creating a Dockerfile, building the Docker image in Cloud Build and deploying it in Cloud Run, you can simply export an Express app as a function and deploy it with Cloud Functions.
Cloud Functions provides an Express wrapper (Functions Framework) and one of a number of pre-configured containers (e.g. "Node 10") to run the function inside.
If you've exported the app with
exports.example = app, it's easy to test locally by running
You can set environment variables when running the
functions-framework command, and if you've downloaded the credentials for the default service account as JSON, you can provide them here:
GOOGLE_APPLICATION_CREDENTIALS=service-account.json functions-framework --target=example
When you're ready, you can deploy the function:
gcloud functions deploy example --runtime nodejs10 --trigger-http --region $REGION
If you need to set any environment variables, it's easiest to do that in the Cloud Functions console, at the bottom of the "Edit" form.
There are a few downsides to using Cloud Functions instead of Cloud Run:
- You can't assign a subdomain to a function (at least not without using Firebase Hosting).
- The functions framework messes with the request body, so you have to pass
busboyto handle multipart file uploads, instead of a wrapper like