Search code examples
node.jsgoogle-cloud-run

How to deploy Typescript project on Cloud Run


Cloud Run error: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information. 

My project uses port 8080. But Cloud Run doesn't seem to recognize it. It seems that the JavaScript node js did not need to be set separately, but it seems to be necessary here. I use ts-node to open ports normally.


Solution

  • Cloud Run works with Typescript. However, Buildpacks doesn't know how to manage it.

    Why am I talking about Buildpacks? Because your issue should come from your deployment mode. You shoud do gcloud run deploy source=. ... and let the Cloud Run service doing the things automatically.

    When you do that, the source are set to Cloud Build and Buildpack is used to build the container automatically. It works great with a subset of languages: nodejs, go, java, ruby, python (but you have to add stuff),...

    Typescript is not supported yet.


    The solution here is to add a Dockerfile that help Cloud Build to build a correct container, with the required layer to install the sufficient library to run your code. Having a Dockerfile in the directory bypass Buildpack and use Docker Build command instead.