1

When I run gcloud app deploy I get error response 9. The error message I get is

Updating service [default] (this may take several minutes)...failed.                                                                                                                
ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error:

app.js

// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore');

// Your Google Cloud Platform project ID
const projectId = 'myid';

// Creates a client
const datastore = new Datastore({
    projectId: projectId,
});

// The kind for the new entity
const kind = 'Task';
// The name/ID for the new entity
const name = 'sampletask1';
// The Cloud Datastore key for the new entity
const taskKey = datastore.key([kind, name]);

// Prepares the new entity
const task = {
    key: taskKey,
    data: {
        description: 'Buy milk',
    },
};

// Saves the entity
datastore
    .save(task)
    .then(() => {
        console.log(`Saved ${task.key.name}: ${task.data.description}`);
    })
    .catch(err => {
        console.error('ERROR:', err);
    });

package.json

{
  "name": "first-application",
  "version": "1.0.0",
  "description": "First program using cloud datastore",
  "main": "app.js",
  "scripts": {
    "start":"node app.js",
    "deploy":"gcloud app deploy",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Ragav",
  "license": "ISC",
  "dependencies": {
    "@google-cloud/datastore": "^1.4.1"
  }
}

app.yaml

runtime: nodejs
vm: true

Please help me, I am trying to learn deploying my app server on GCP. Appreciate your help.

Thanks!

1
  • Have you solved the issue yet? Commented Jul 23, 2018 at 13:42

2 Answers 2

1

In order to run the example you show, please follow the instructions in the docs:

  1. Download the credentials JSON file and create an environment variable that points to this file:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credential-file.json"

  1. Copy the code in, i.e., sample.js file and run node sample.js.

On the other hand, if you want to deploy a nodejs app, you'll need express.js or any other framework.

I did the following with the help of express.js:

I wrapped your code in a function called saveEntity(datastore)

Then I added express.js to the app like in the sample nodejs app and from there I called saveEntity(datastore):

app.get('/', (req, res) => {
    saveEntity(datastore);
    res.status(200).send("Entity saved").end();
}); 

// [START listen]
const PORT = process.env.PORT || 8080;
app.listen(process.env.PORT || 8080, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');
});
// [END listen]
// [END app]

module.exports = app;

The complete result is this:

// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore');
//Needed to create the node app
const express = require('express')

const app = express();

// Your Google Cloud Platform project ID
const projectId = 'my-project-id';

// Creates a client
const datastore = new Datastore({
    projectId: projectId,
});

function saveEntity(datastore){
    // The kind for the new entity
    const kind = 'JulyTask';
    // The name/ID for the new entity
    const name = 'sampletask1';
    // The Cloud Datastore key for the new entity
    const taskKey = datastore.key([kind, name]);

    // Creates entity data
    const task = {
        name: 'Learn something',
        status: 'In progress',
        description: 'Friday 6 July'
    }

    //With the data and the key, create the entity
    const entity = {
        key: taskKey,
        data: task
    }

    // Saves the entity
    datastore
        .upsert(entity)
        .then(() => {
            console.log('Saved:\n' + JSON.stringify(entity));
            return true;
        })
        .catch(err => {
            console.error('ERROR:', err);
            return false;
        });
}

app.get('/', (req, res) => {
    saveEntity(datastore);
    res.status(200).send("Entity saved").end();
}); 

// [START listen]
const PORT = process.env.PORT || 8080;
app.listen(process.env.PORT || 8080, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.');
});
// [END listen]
// [END app]

module.exports = app;

The package.json:

{
    "name": "first-application",
    "version": "1.0.0",
    "description": "First program using cloud datastore",
    "main": "app.js",
    "scripts": {
        "start": "node app.js",
        "deploy": "gcloud app deploy",
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "Ragav",
    "license": "ISC",
    "dependencies": {
        "@google-cloud/datastore": "^1.4.1",
        "express": "^4.16.3"
    }
}

Also you should know that this is deprecated:

runtime: nodejs
vm: true

You could do this instead:

runtime: nodejs
env: flex
service: my-service-name
Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem. At the loggin it also said:

ERROR: build step 0

I solved it deleting two of the buckets on the project I was trying to deploy. Go to https://console.cloud.google.com/storage/ and delete the buckets that start with:

stagging....
artifact...

After doing this you can deploy again

I am not sure what was the exact cause of the problem as the error is not clear nor the documentation.

My guess is that there is a problem with storage limit but as I said I can't be sure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.