1
votes

After successfully deploying a container using gcloud builds submit --tag gcr.io/projectname/testserver and then attempting to run gcloud run deploy --image gcr.io/projectname/testserver --platform managed I see this error:

$ gcloud run deploy --image gcr.io/projectname/testserver --platform managed
Please specify a region:
 // options removed

Service name (testserver):  
Allow unauthenticated invocations to [testserver] (y/N)?  y

Deploying container to Cloud Run service [testserver] in project [projectname] region [us-central1]
X Deploying new service... Cloud Run error:
 Container failed to start. Failed to start
 and then listen on the port defined by the
 PORT environment variable. Logs for this r
evision might contain more information.    
  X Creating Revision... Cloud Run error: C
  ontainer failed to start. Failed to start
   and then listen on the port defined by t
  he PORT environment variable. Logs for th
  is revision might contain more informatio
  n.                                       
  . Routing traffic...                     
   Setting IAM Policy...                  
Deployment failed                          
ERROR: (gcloud.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.

I have a very simple project, all in the root folder:

// Dockerfile
FROM node:12-slim

# Create app folder
WORKDIR /usr/src/app

# Install app deps. Copy the lock file
COPY package*.json ./
RUN npm install

COPY . ./
CMD ["node", "testServer.js"]
// testServer.js
const Koa = require("koa");
const koa = new Koa();

koa.get('/', async ctx => {
  ctx.body = "Koa server running"
});

const port = process.env.PORT || 8080;

koa.listen(port);

Anyone know what's causing this? Been trying to solve it since yesterday and now even with this minimal project it seems to be having issues.

2
What if any errors are being logged from the startup of the container? Can you collect all your artifacts and put them in a temporary GitHub repo and post the link. Maybe some kind soul might attempt a recreate?Kolban

2 Answers

2
votes

I received TypeError: app.get is not a function with your code. Looks like this syntax is obsolete. Rewrote with koa-router and worked just fine.

Anyway try to test your code locally with docker run before deploying. And also you can find more precise error messages during deployment in console-> logging-> cloud run revision-> revision_id

1
votes

Same error here. I solved that increasing the timeout.