Deploying Roots CMS to a server

Josh Rowley edited this page Mar 5, 2014 · 5 revisions
Clone this wiki locally

Here's one way of deploying roots-cms and a roots project to a server in order to allow content management. We'll be using pm2 to manage our node server and deploy for deployment.

On the server

Get a server

I recommend an Ubuntu server from Digital Ocean.

Install node

Here are good instructions on how to install node on a Ubuntu server.

Install pm2

pm2 will manage our node server processes. Install with npm install pm2@latest -g, more documentation can be found in the repo readme.

On your local dev machine

Install deploy

Clone down the repo and run make install.

Configure the roots-cms deploy conf

Roots-CMS has an example deploy.conf.example file inside of the repo.

  • cp deploy.conf.example deploy.conf
  • Update deploy.conf with the correct config values for user, host, repo, path, and ref
Setup your deploy directories

deploy production setup - Deploy will SSH to your server and build all necessary directories at the path you specify.

Configure your roots project to work with Roots-CMS

Add a cms.json file to the root of your roots project with the following config and update with your values. None of the keys are required, a more detailed guide to configuring your roots project to work with roots-cms will be coming soon:

{
  "content_dir": "",
  "basic_auth": {
    "username": "user",
    "password": "password"
   },
  "templates": {
    "content_edit": "assets/cms/templates/_content_show.jade"
  },
  "css": "assets/css/_blogging.styl",
  "aws": {
    "key": "XXXXXXXXXXXXXXXXXX",
    "secret": "XXXXXXXXXXXXXXXXXXX",
    "bucket": "bucket-name"
  }
  "uploader": "fs",
  "img_upload_dir": "uploads"
}
Set your image uploader

In the cms.json example above, the uploader key specifies how you want to upload images. Use "fs" to upload images directly into your roots project on the server (Note, there are no security precautions taken with this feature, use at your own risk, getting this to be production ready is on the roadmap). You can also use s3 to upload images to an Amazon S3 bucket (requires aws to be defined).

img_upload_dir will specify a directory inside either assets/img or on the S3 bucket (depending on the uploader) where uploaded images should be stored.

Clone your roots project onto the server

I like to put it in /var/www as well, but you can choose another location if you want: cd /var/www && git clone <git_url>

Configure roots-cms

Roots-CMS needs to know where your roots project is. For now we'll store this config information in a shared file, we'll link it to the current release in the next step.

  • cd /var/www/roots-cms/shared/
  • touch config.json
  • Edit the file to contain the following:
{
  "project_dir": "/var/www/<your-roots-project>"
}
Set up a post deploy script

We'll need a post deploy script to manage linking the shared config file into the current release directory, to load any new npm dependencies, as well as to restart the node server. This can easily be done with deploy.

Open up your deploy.conf and add this last line to the file:

post-deploy sh ../shared/post_deploy.sh

On the server add post_deploy.sh into /var/www/roots-cms/shared/
Here's my post-deploy.sh file, feel free to edit for your needs. Mine runs npm install, symlinks the config file into the current relase, and restarts the node server via pm2.

(cd ../current/; npm install)
rm ../current/config.json
ln -s ../shared/config.json ../current/config.json
pm2 kill
nohup pm2 start ../current/app.coffee >/dev/null 2>&1 </dev/null
echo "Daemon started"

Note that there's no robust authentication system in roots-cms right now outside of HTTP basic auth, please do your due diligence if you need a secure system.