# our build should run within a Ruby box
box: wercker/nodejs
build:
  steps:
    # - npm-install

    # install gitbook itself
    - script:
        name: install gitbook
        code: sudo npm install -g gitbook

    # build gitbooks
    - script:
        name: build user docs
        code: gitbook install docs/user/ && gitbook build docs/user/

    - script:
        name: build dev docs
        code: gitbook install docs/dev/ && gitbook build docs/dev/

deploy:
  steps:
    - install-packages:
        packages: sshpass  #needed by cdn77

    - script:
        name: deploy user docs to cdn
        code: rsync -avz --progress --rsh="sshpass -p $SSHPASS ssh -l $SSHUSER -o StrictHostKeyChecking=no" docs/user/_book/* $SSHUSER@$SSHHOST:/www/rtbiz/user/

    - script:
        name: deploy dev docs to cdn
        code: rsync -avz --progress --rsh="sshpass -p $SSHPASS ssh -l $SSHUSER -o StrictHostKeyChecking=no" docs/dev/_book/* $SSHUSER@$SSHHOST:/www/rtbiz/dev/


  after-steps:
    - script:
        name: purge cdn
        code: curl --data "cdn_id=$CDNID&login=$APIUSER&passwd=$APIPASS" https://client.cdn77.com/api/v2.0/data/purge-all

    - sherzberg/slack-notify:
        subdomain: rtcamp
        token: $SLACKTOKEN
        channel: "#docs"
        username: wercker
        icon_url: https://avatars3.githubusercontent.com/u/1695193?s=140
