Skip to content

Instantly share code, notes, and snippets.

@cryptoquick
Created August 16, 2016 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptoquick/7dd4ff835d15797fe39379fd2ab2cf2b to your computer and use it in GitHub Desktop.
Save cryptoquick/7dd4ff835d15797fe39379fd2ab2cf2b to your computer and use it in GitHub Desktop.
#!/bin/bash
# External Parameters: MONGO_URL, MONGO_OPLOG_URL, ROOT_URL, METEOR_SETTINGS, KADIRA_APP_ID, KADIRA_APP_SECRET
export MONGO_URL=$(curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/MONGO_URL -H "Metadata-Flavor: Google")
export MONGO_OPLOG_URL=$(curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/MONGO_OPLOG_URL -H "Metadata-Flavor: Google")
export ROOT_URL=$(curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/ROOT_URL -H "Metadata-Flavor: Google")
export METEOR_SETTINGS=$(curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/METEOR_SETTINGS -H "Metadata-Flavor: Google")
export KADIRA_APP_ID=$(curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/KADIRA_APP_ID -H "Metadata-Flavor: Google")
export KADIRA_APP_SECRET=$(curl http://metadata.google.internal/computeMetadata/v1/instance/attributes/KADIRA_APP_SECRET -H "Metadata-Flavor: Google")
# Static Parameters
export HOME="/home/YOUR_USER_NAME/"
export ROOT_URL="https://your.app.url"
export PORT=3000
# Change this to your GCS bucket name:
PROJECT="app"
# Nginx
gpg --keyserver keyserver.ubuntu.com --recv-key ABF5BD827BD9BF62
gpg -a --export ABF5BD827BD9BF62 | apt-key add -
grep -q -F 'deb http://nginx.org/packages/debian/ jessie nginx' /etc/apt/sources.list || echo 'deb http://nginx.org/packages/debian/ jessie nginx' >> /etc/apt/sources.list
grep -q -F 'deb-src http://nginx.org/packages/debian/ jessie nginx' /etc/apt/sources.list || echo 'deb-src http://nginx.org/packages/debian/ jessie nginx' >> /etc/apt/sources.list
# NodeJS fix (Fixes: "Hash Sum mismatch")
sudo sed -i -re 's/\w+\.archive\.ubuntu\.com/archive.ubuntu.com/g' /etc/apt/sources.list
# Install packages
apt-get update -y --force-yes && apt-get upgrade -y --force-yes
apt-get install -y --force-yes build-essential
apt-get install -y --force-yes nodejs nginx
npm install -g --unsafe-perm pm2
# Node.js (this script already runs apt-get update)
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
# SSL
mkdir -p /etc/nginx/ssl
gsutil cp gs://$PROJECT/secure/app.pem /etc/nginx/ssl/app.pem
gsutil cp gs://$PROJECT/secure/app.key /etc/nginx/ssl/app.key
# Configure nginx
gsutil cp gs://$PROJECT/config/nginx.conf /etc/nginx/conf.d/default.conf
/etc/init.d/nginx restart
# Get app code
mkdir -p /opt/web/app
cd /opt/web/app
gsutil cp gs://$PROJECT/bundle/app/meteor_app.tar.gz . # Change this to your meteor app directory name.
tar zxf meteor_app.tar.gz
cd bundle
cd programs/server
npm install --unsafe-perm bcrypt fibers # Recompile in case the packages have been compiled for a different archtiecture
npm install --unsafe-perm
# Run
cd ../..
node main # Feel free to try forever or pm2, but simple node has been stable and has worked for us.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment