user8508357
user8508357

Reputation:

Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT

Running this code everything is fine.

require('dotenv').config();
const express = require('express');
const Firestore = require('@google-cloud/firestore');
const path = require('path');


const app = express();

app.get('/', function (req, res) {
    console.log('hello-cloud-run', 'request received');

    const target = process.env.TARGET || 'Juan';
    res.send(`Hello ${target} from Notch - Shopify Webhooks!`);
 });

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

 app.listen(port,  () => {
    console.log('Webhook app listening on port ', port);
 });

However if I add the Firestore line (line beginning with const db =) I get the 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.

require('dotenv').config();
const express = require('express');
const Firestore = require('@google-cloud/firestore');
const path = require('path');


const app = express();

const db = new Firestore({
    projectId: 'kuracao-db',
    keyFilename: path.join(__dirname, process.env.GOOGLE_APPLICATION_CREDENTIALS)
});


app.get('/', function (req, res) {
    console.log('hello-cloud-run', 'request received');

    const target = process.env.TARGET || 'Juan';
    res.send(`Hello ${target} from Notch - Shopify Webhooks!`);
});

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

app.listen(port,  () => {
    console.log('Webhook app listening on port ', port);
 });

Why would adding a Firestore db cause a Cloud Run error?

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.

FROM node:14

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . . 

CMD ["npm", "start"]

Upvotes: 0

Views: 504

Answers (1)

user8508357
user8508357

Reputation:

I changed

const db = new Firestore({
  projectId: 'kuracao-db',
  keyFilename: path.join(__dirname, process.env.GOOGLE_APPLICATION_CREDENTIALS)
});

to

const db = new Firestore();

And it works, now I'm wondering why. Don't need credentials when running from Cloud Run? Makes sense, but what does that have to do with the port error?

Upvotes: 2

Related Questions