Last active
April 3, 2017 13:54
-
-
Save emgee3/a6fa17e1d6935aff39dc to your computer and use it in GitHub Desktop.
Deploy script for self-hosted Meteor deployments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
#--------------------------------------------------- | |
# Meteor Deployment Script | |
#--------------------------------------------------- | |
#-REQS---------------------------------------------- | |
# | |
# Remote server should have the following: | |
# - Allow passwordless SSH logins | |
# - Have `nvm` installed | |
# - Have `pm2` installed | |
#-CONFIGURATION ------------------------------------ | |
export APP_SOURCE=/Users/emgee/Meteor/testapp/meteor | |
export APP_NAME=testapp | |
export SERVER_USERNAME=meteor | |
export SERVER_ADDRESS=10.1.0.50 | |
export SERVER_HOME=/home/meteor | |
export SERVER_ARCH=os.linux.x86_64 | |
export NODE_VERSION=0.10.36 | |
export APP_PATH=${SERVER_HOME}/${APP_NAME} | |
#--------------------------------------------------- | |
#-SHOULD NOT REQUIRE MODIFICATIONS BELOW THiS LINE-- | |
#--------------------------------------------------- | |
set -e | |
set -u | |
set -o pipefail | |
#--------------------------------------------------- | |
# Sanity checks | |
#--------------------------------------------------- | |
# We should have Meteor installed | |
if [ ! -e `which meteor` ]; | |
then | |
echo "Can't find Meteor" | |
exit 1 | |
fi | |
# Test remote system for nvm | |
set +e | |
ssh ${SERVER_USERNAME}@${SERVER_ADDRESS} 'bash -s' << ENDSSH | |
# We're in a non-interactive shell so need to manually source .nvm | |
if [ -d ${SERVER_HOME}/.nvm ]; | |
then | |
source .nvm/nvm.sh | |
export -f nvm | |
else | |
exit 3 | |
fi | |
# Make sure we have the correct version of node installed | |
nvm ls ${NODE_VERSION} | |
if [ \$? -eq 3 ]; | |
then | |
nvm install ${NODE_VERSION} | |
fi | |
# Use the correct version of node | |
nvm use ${NODE_VERSION} | |
if [ ! -x `which node` ]; | |
then | |
exit 4 | |
fi | |
if [ ! -x `which npm` ]; | |
then | |
exit 5 | |
fi | |
if [ ! -x `which pm2` ]; | |
then | |
exit 6 | |
fi | |
ENDSSH | |
if [ "$?" = "3" ]; | |
then | |
echo "nvm not installed on remote server" | |
exit 1 | |
fi | |
if [ "$?" = "4" ]; | |
then | |
echo "Problem executing node" | |
exit 1 | |
fi | |
if [ "$?" = "5" ]; | |
then | |
echo "Problem executing npm" | |
exit 1 | |
fi | |
if [ "$?" = "5" ]; | |
then | |
echo "Problem executing pm2" | |
exit 1 | |
fi | |
set -e | |
cd ${APP_SOURCE} | |
echo "Building ${APP_NAME}..." | |
meteor build --directory ../build --architecture ${SERVER_ARCH} | |
echo "Backing up running copy of ${APP_NAME}..." | |
ssh ${SERVER_USERNAME}@${SERVER_ADDRESS} 'bash -s' << ENDSSH | |
rm -rf ${APP_PATH}/bundle.bk | |
cp -r ${APP_PATH}/bundle ${APP_PATH}/bundle.bk | |
ENDSSH | |
echo "Updating ${APP_NAME} files..." | |
rsync -azhe ssh --delete ../build/bundle/ ${SERVER_USERNAME}@${SERVER_ADDRESS}:${APP_PATH}/bundle | |
echo "Restarting ${APP_NAME}..." | |
ssh ${SERVER_USERNAME}@${SERVER_ADDRESS} 'bash -s' << ENDSSH | |
set -e | |
source .nvm/nvm.sh | |
export -f nvm | |
nvm use ${NODE_VERSION} | |
cd ${APP_PATH}/bundle/programs/server | |
npm install --production | |
cd ${APP_PATH} | |
pm2 restart ${APP_NAME} | |
ENDSSH | |
echo "Done deploying \"${APP_NAME}\"." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"apps": [ | |
{ | |
"name": "quicklook", | |
"script": "main.js", | |
"log_date_format": "YYYY-MM-DD HH:mm Z", | |
"cwd": "/data/quicklook/bundle", | |
"env": { | |
"HOME": "/home/meteor", | |
"MONGO_URL": "mongodb://10.1.0.100/testapp", | |
"ROOT_URL": "http://testapp.internal.organization.com", | |
"MAIL_URL": "smtp://127.0.0.1:25/", | |
"PORT": 3010, | |
"METEOR_SETTINGS": "{\"database\":{\"server\":\"10.50.0.200\",\"database\":\"test-01\",\"user\":\"username\",\"password\":\"password\",\"public\":{\"property\":\"value\"}}}" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment