meteor

Understanding Google Cloud Platform (GCP)

Google Cloud Platform that is offered by Google as a suite of Cloud Computing Services. It runs on the same infrastructure that Google has for its products. They are proficient in the series of modular cloud services including computing, data storage, data analytics and machine learning. With Google Cloud Platform, we can build, test, and deploy applications on Google’s highly-scalable and reliable infrastructure for our web, mobile, and backend solutions.

GCP frees us from the overhead of managing infrastructure, provisioning servers and configuring networks. To let innovators innovate and let coders, well, just code.

Steps for Deployment:

Run Meteor on Google App Engine Flexible Environment:

Step 1

Create a project in the Google Cloud Platform Console. https://console.cloud.google.com/

Step 2

Enable billing for your project.

Step 3

Install the Google Cloud SDK. https://cloud.google.com/sdk/

Step 4

Install Meteor on your local machine. https://www.meteor.com/install

Step 5

Create a MongoDB instance. https://cloud.google.com/nodejs/getting-started/deploy-mongodb

Step 6

Remember your MONGO_URL, you will need that later. An example MongoDB URI would be mongodb://username:password@host:port.

Step 7

Initialize a Meteor project by running the following commands:

meteor create [YOUR_APP_NAME]

cd [YOUR_APP_NAME]

meteor add reactive-dict

meteor remove autopublish

replacing [YOUR_APP_NAME] with your app name.

Step 8

To add database functionality, edit [YOUR_APP_NAME]/client/main.js to look like:

import { Template } from ‘meteor/templating’;

import { ReactiveVar } from ‘meteor/reactive-var’;

import { Meteor } from ‘meteor/meteor’

import ‘./main.html’;

Template.hello.onCreated(function helloOnCreated() {

  // counter starts at 0

  this.counter = new ReactiveDict({value: ’0′ });

  var instance = this;

   Meteor.subscribe(‘counters’, function () {

    var counterConn = new Mongo.Collection(‘counters’);

    instance.counterConn = counterConn;

 

    var counterList = counterConn.find({}).fetch();

    var dbCounter = counterList[0];

    instance.dbCounter = dbCounter;

     instance.counter.set(‘_id’, dbCounter._id);

    instance.counter.set(‘value’, dbCounter.value);

  });

});

 Template.hello.helpers({

  counter() {

    return Template.instance().counter.get(‘value’);

  },

});

Template.hello.events({

  ‘click button’(event, instance) {

     // Increment counter

    instance.counter.set(‘value’, instance.counter.get(‘value’) + 1);

     // Update counter on DB

    instance.counterConn.update(instance.dbCounter._id, {

      ‘$set’: {‘value’: instance.counter.get(‘value’) }

    });

  },

});

Step 9

Edit [APP_NAME]/server/main.js so that it looks like:

import { Meteor } from ‘meteor/meteor’;

import { Mongo } from ‘meteor/mongo’;

 Meteor.startup(() => {

  // code to run on server at startup

  const Counters = new Mongo.Collection(‘counters’);

   // Make sure a Counter entry exists

  if (Counters.find({}).fetch().length == 0)

    Counters.insert({value: 0})

   // Publish counters

  Meteor.publish(‘counters’, function () {

    return Counters.find({});

  })

});

Step 10

For running the app,

a)        Run the app with the following command:

MONGO_URL=[MONGO_URL] meteor run

replacing [MONGO_URL] with your MongoDB URI.

Step 11

For deploying the app,

a)        Add the following to the package.json file:

“scripts”: {

  “cleanup”: “rm -rf ../bundle/”,

  “dist”: “npm run cleanup && meteor build ../ –directory –architecture os.linux.x86_64                                                                              –server-only”,

  “predeploy”: “npm run dist && cp app.yaml ../bundle/ && cp Dockerfile ../bundle/”,

  “deploy”: “npm run predeploy && (cd ../bundle && gcloud app deploy -q)”

},

These scripts provide you with some tasks that prepare the app for deployment to Google App Engine flexible environment. See https://guide.meteor.com/deployment.html#custom-deployment for more information about custom Meteor deployments.

b)        Configure a https://cloud.google.com/appengine/docs/flexible/custom-runtimes/ by running the following command:

gcloud beta app gen-config –custom

c)         Replace the contents of the Dockerfile file with the following:

FROM gcr.io/google_appengine/nodejs

COPY . /app/

RUN (cd programs/server && npm install –unsafe-perm)

CMD node main.js

The custom Dockerfile is required in order to properly build the Meteor app in production.

d)        Add the following to the generated app.yaml file:

env_variables:

  ROOT_URL: https://[YOUR_PROJECT_ID].appspot-preview.com

  MONGO_URL: [MONGO_URL]

  DISABLE_WEBSOCKETS: “1″

replacing [YOUR_PROJECT_ID] with your Google Cloud Platform project ID and [MONGO_URL] with your MongoDB URI.

e)        Run the following command to deploy your app:

npm run deploy

Visit https://[YOUR_PROJECT_ID].appspot.com to see the Welcome to Meteor! message, replacing [YOUR_PROJECT_ID] with your Google Cloud Platform project ID.

The Pros and Cons:

The clear statement that can be given here are the pros which are undeniable for the complete success. The future proof infrastructure, the most powerful Data and Analytics, the Serverless and fully managed computing, the customer-friendly pricing, the Data Center innovation, the security at scale, the cost affordability for long term use. Along with these pros you could also find to choose your own instance configuration and the load balancing that is been reported much better than the rest.

It may also be obvious to find few cons over it. It clearly shows that some experiences get difficult to get a qualified help and the Google Support is unknown at this juncture.

So, you are to step into the world of Meteor and innovate in a better way.