Hi all,
Recently I decided to use MeteorJs to develop a private web app and although developing for MeteorJs was very fun, deploying to a cloud server like Google Cloud or Amazon... not so much. In my head, all I had to do was to start up an App Engine instance, remote SSH, install MeteorJs, clone my repo, run the code and that was it.
But little did I know that by the time I closed the SSH window, my App Engine instance would shut down.
So after a lot of googling and, having been able to find articles that helped me, none of them delivered the full solution and I had to get the ideas from all of them so could get it working.
Ok, so let's cut to the chase - this will be short and sweet.
Have your MeteorJS code ready. Duh.
Create an account with mLabs (www.mlabs.com) and create a MongoDB instance using Google Cloud. They have a free tier. You can also get a MongoDB instance in Google Cloud yourself and manage that. Refer to this link!
Create a user for your MongoDB, and don't forget the credentials as you are going to need it later on.
Edit your package.json file at the root of your MeteorJs project and add the following (do not remove the "start" line):
"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)",
"start": "meteor run"
},
Install Google Cloud SDK if you have not done so.
Run the following command inside your project root folder:
gcloud beta app gen-config --custom
A Dockerfile will be creted in your project. Delete all contents inside and add this:
FROM gcr.io/google_appengine/nodejs
COPY . /app/
RUN (cd programs/server && npm install --unsafe-perm)
CMD node main.js
Delete everything inside the app.yaml file that was also created in your project and add this:
entrypoint: meteor run
env: flex
runtime: custom
env_variables:
ROOT_URL: https://.appspot-preview.com
MONGO_URL: "mongodb://:@.mlab.com:57444/"
DISABLE_WEBSOCKETS: "1"
skip_files:
- ^(.*/)?\.dockerignore$
- ^(.*/)?\npm-debug.log$
- ^(.*/)?\yarn-error.log$
- ^(.*/)?\.git$
- ^(.*/)?\.hg$
- ^(.*/)?\.svn$
The project_id you will take from the Google Cloud Dashboard. The mongo_url you will take from the mLabs dashboard.
Run npm run deploy. It will take a while but after a few minutes you should see a brand new App Engine instance up and running and you can then try accessing your webapp in your browser!
Hope this helps.