Build a Meteor app from a Git or SVN repository for using it in a nginx + Passenger environment
I run a server with a number of Meteor apps on nginx and Passenger. To simplify the roll-out of a new version of an app, I've written the script repository_build.sh. It retrieves the source code from the SVN or Git repository, builds the Meteor app and installs it. Afterwards, Passenger is instructed to restart the app. For easier rebuild a script is stored into the app root directory with the used parameters.
As different Meteor versions need different versions of node, the script copies the approbriate node version as delivered as part of the Meteor installation into the root directory of the app. So, you can run different Meteor/node versions on the same installation.
nginx, Passender and Meteor must already be installed on the server.
- Copy the script repository_build.sh to /usr/local/bin
- Give it execution permission by
sudo chmod 755 /usr/local/bin/repository_build.sh
- Replace the /srv/meteor-apps at the start of the script to your preferred path, where the Meteor apps should be running.
- Set the the HOME variable, if you want to use a central repository for all Meteor packages instead of ~/.meteor.
If you use the HOME variable, all users can use the same directory for the Meteor packages (by setting METEOR_WAREHOUSE_DIR to $HOME/.meteor. You have to take care of the right permissions, so the respective users have read and write access.
repository-build.sh project repository [branch]
The project parameter is used to determine the path underneath the app directory (/srv/meteor-apps). repository contains a URL or path to retrieve the source code using Subversion or Git. The Subversion URL must start with svn.
The configuration files resist typically (at least within Debian) in /etc/nginx/sites-available, where the files are symbolically linked to /etc/nginx/sites-enabled. Take nginx.example.com as example and alter it according your own needs (especially by replacing example.com with your own domain/project name).
The script can be used to rebuild an app upon pushing into a local repository by creating an executable file in REPOSITORY.git/hooks/post-update with the contents:
#!/bin/bash
/usr/local/bin/repository-build.sh PROJECT $GIT_DIR
MIT