Steps to deploy your app to a live (linux) staging and/or production server
If you haven't done so already, purchase a (new) Linux server (i.e. from Digital Ocean, Rackspace, Amazon) and follow server-linux.md to install/setup your Linux server.
NOTE: May need at least 1GB RAM as PhantomJS (for (karma) automated tests) can be a memory hog and will often fail with 512MB RAM. - http://stackoverflow.com/questions/24119506/karma-jasmine-times-out-without-running-tests - karma-runner/karma#598
- [on new server] Install global npm packages:
sudo npm install -g grunt-cli yo bower generator-mean-seed yuidocjs forever less
- [locally on your computer / original server] create a new set of configs (regular and test) in
app/configs
for the new server environment by copying the existingconfig.json
and renaming itconfig-[new-server-environment].json
and updating it accordingly, i.e. for a production or staging linux server change/set at least the following:operatingSystem
tolinux
forever
to1
so it will auto restart forever on code changesserver.domain
andemail.domain
to the domain (or IP address) of the new serversauceLabs
credentials (if you don't already have a Sauce Labs account, create one (they have free tiers) since the selenium standalone server with chrome doesn't currently work on linux (while we could try to get phantom-js working, it's better to run on multiple platforms anyway)- [should also update unique keys and credentials, such as facebook app id, google app id, etc.]
- then copy this new config file to make the test config, which should be named
config-[new-server-environment].test.json
and edit it to change at least:server.port
server.socketPort
db.database
- i.e. totest_temp
Then do one of the following:
RECOMMENDED approach!
Variables used in the instructions below; replace appropriately
GIT_NAME Joe Bob
GIT_EMAIL youremail@gmail.com
GIT_REPO_URL https://github.com/jackrabbitsgroup/my-app.git
GIT_REPO_URL_PASS https://lukemadera:somepass@github.com/jackrabbitsgroup/my-app.git
CONCRETE_PATH /var/www/concrete //this is where on your server you'll install the Concrete CI server to
CONCRETE_PORT 3010 //this MUST match what is set in config.json!
APP_PATH /var/www/my-app //this is where your app will be put
PERMISSIONS_GROUP developers //the (optional) linux user group to give access
APP_DOMAIN someurl.com //this can also be an ip address, i.e. xxx.xxx.xxx.xx
GIT_BRANCH master //this is what branch concrete will use to pull in updates (concrete will run on EVERY git push, even to other branches, but will only pull from THIS branch). E.g. 'master', 'prod', 'dev', 'staging'
- create a Github repo on github.com (if you haven't already) and push to it
- [on new server] setup git config on the new server for your user
git config --global user.name "GIT_NAME"
git config --global user.email "GIT_EMAIL"
git config --global --add color.ui true
- [on new server] install Concrete CI. The regular one/main repo is good but doesn't seem to have auto Git web hooks built in so I used this fork instead: https://github.com/jackrabbitsgroup/concrete
git clone https://github.com/jackrabbitsgroup/concrete.git CONCRETE_PATH
- set permissions for the new
concrete
foldersudo chown -R root:PERMISSIONS_GROUP CONCRETE_PATH
sudo chmod -R g+w CONCRETE_PATH
cd CONCRETE_PATH
npm install
- NOTE: if you get an EACCESS / permission denied error during the npm install, find the folder that had permissions issues (from the log output) and run
sudo chown -R $USER [path to problematic folder]
.
- NOTE: if you get an EACCESS / permission denied error during the npm install, find the folder that had permissions issues (from the log output) and run
- [on new server] Do some setup
- clone the github repo (we'll just have to do this manually once) -
git clone GIT_REPO_URL APP_PATH
- make sure to use the HTTPS git url - otherwise will get a 'Permission denied (publickey).' error!- set permissions on this folder (especially if you cloned with
sudo
)sudo chown -R root:PERMISSIONS_GROUP APP_PATH
sudo chmod -R g+w APP_PATH
- go into the repo -
cd APP_PATH
- if it prompts you for a username and/or password during git pull or other commands, the CI won't work so set your username and password by doing:
git config remote.origin.url GIT_REPO_URL_PASS
(basically just prepend [username]:[password] to your existing remote url).
- set permissions on this folder (especially if you cloned with
- copy and set the
config_environment.json
to use this environment with:cp app/config_environment.json config_environment.json
and then edit the file to set theenvironment
key to your new environment (the SAME name you used when creating the newconfig-[new-server-environment].json
file earlier - these MUST match!) - add the concrete runner to the git config so concrete will run:
git config --add concrete.runner "npm install && bower update && bower install && grunt --type=prod"
- set the git branch (so it will only run if this branch is updated. This is useful for distinguishing between the production and staging/development server for example - so production code is only updated when you push to the production branch)
git config --add concrete.branch GIT_BRANCH
- NOTE: if you change this config later, you'll have to restart concrete for the change to take effect (i.e. with
forever restart [forever process number for concrete]
) - more info: http://codesquire.com/post/ContinuousDeployment
- NOTE: if you change this config later, you'll have to restart concrete for the change to take effect (i.e. with
- set the git branch (so it will only run if this branch is updated. This is useful for distinguishing between the production and staging/development server for example - so production code is only updated when you push to the production branch)
- configure git hooks for worked and failed
- create (if not already present)
.git/hooks/build-failed
and addnode ci.js build=failed
to it, i.e. usingecho 'node ci.js build=failed' > APP_PATH/.git/hooks/build-failed
- create (if not already present)
.git/hooks/build-worked
and addnode ci.js build=worked
to it, i.e. usingecho 'node ci.js build=worked' > APP_PATH/.git/hooks/build-worked
- set permissions so the hooks can be run -
sudo chmod -R +x APP_PATH/.git/hooks
- create (if not already present)
- clone the github repo (we'll just have to do this manually once) -
- [on new server] run concrete server with forever:
cd APP_PATH && forever start CONCRETE_PATH/bin/concrete -p CONCRETE_PORT APP_PATH
- Open a browser to
http://APP_DOMAIN:CONCRETE_PORT
to see your continuous integration server!
- Open a browser to
- On github.com add a webhook to the concrete server so it will run on each git push!
- In your repo on github.com, click on
Settings
thenService Hooks
thenWebHook URLs
and add a URL:http://APP_DOMAIN:CONCRETE_PORT/webhook
- In your repo on github.com, click on
- [locally / on original server] Do a Git push (i.e.
git push origin master
) and then refresh your Concrete page and you should see a new build running!- Now each time you (locally) do a
git push
to github, your 2nd server will automatically get updated, tests run, etc.!
- Now each time you (locally) do a
- NOTE: you may have to do some final setup steps - see cloning.md and make sure all those steps have been done. Most should have already been but a notable one you'll likely still have to do is installing chromedriver for Protractor tests (i.e. with
./node_modules/protractor/bin/webdriver-manager update
)
- [on new server] make
git
directory & initialize bare reposudo mkdir /var/git
sudo mkdir -p /var/git/project.git
sudo git init --bare /var/git/project.git
- set group permissions (do the same for
/var/www
if you haven't already)sudo chgrp -R developers /var/git/project.git
sudo chmod -R g+swX /var/git/project.git
- [on new server] clone the local repo
git clone /var/git/project.git /var/www/project
- [on local computer (where existing files are) - open a NEW terminal/command window and
cd
to the local copy of the website on your computer] add a remote (from local machine) to the server repo then push to it.git remote add prod ssh://lmadera@111.111.111.111/var/git/project.git
git push prod master
- [on new server] set permissions for /var/www/project folder then pull from local repo we just pushed to
sudo chown -R ubuntu:developers /var/www/project
- NOTE: this assumes a 'ubuntu' user exists - if it doesn't try 'root' instead OR your username (i.e.sudo chown -R root:developers /var/www/project
)sudo chmod -R g+w /var/www/project
cd /var/www/project
git pull origin master
- [on new server] setup site as normal (see main README for steps - set config, npm install -g, grunt, etc.).
- [on new server] start server and keep it running with forever.
forever start -w run.js
-w
command will auto-restart the process if it fails and is optional (it can cause (memory) issues during grunt builds / updates while code is rapdily changing)
- [on new server] Restarting server / getting file/code updates
cd /var/www/project
forever stop [forever process uid]
- can use
forever stopall
to stop ALL processes but this is not a good idea - should only stop THIS one!
- can use
git pull origin master
npm install && bower install
grunt q --type=prod
forever start run.js