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.
Step 1:
Have your MeteorJS code ready. Duh.
Step 2:
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.
Step 3:
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"
},
STEP 4
Install Google Cloud SDK if you have not done so.
STEP 5
Run the following command inside your project root folder:
gcloud beta app gen-config --custom
STEP 6
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
STEP 7
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://<PROJECT_ID>.appspot-preview.com
MONGO_URL: "mongodb://<user>:<pwd>@<instance>.mlab.com:57444/<db_name>"
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.
STEP 8:
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.
Congratulations @felipecaldas! You have received a personal award!
1 Year on Steemit
Click on the badge to view your Board of Honor.
Do not miss the last post from @steemitboard:
Congratulations @felipecaldas! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!