0
votes

I feel like I am hitting a brick wall with trying to implement CI from a master branch on Github, using Travis-CI and pushing built files onto my server.

Overview of what I am attempting:

  • Push new code to branch on github
  • After tests are run and merged into the master branch, Travis takes over.
  • Travis runs through tests, and then a deploy script on my DigitalOcean box.
  • The deploy script runs through NPM tasks, and then Gulp
  • If all is well, node_modules folder will be updated (from package.json) and all the compiled files from Gulp will be updated on the server.

I have gotten it to almost work and it seems like it is permission issues of some sort (even though I am not getting any build errors)

Travis successfully runs on a master push, finds the deploy script, and runs through it without any issues. It exits with a 0 at the end, and the build is green. However when I ssh to check to make sure changes were applied - nothing looks different.

Seems like Travis is building in it's own container but the actual box isn't getting updated.

Here is my .travis.yml file:

sudo: required
language: node_js
node_js:
  - "stable"

script:
  - /bin/true

deploy:
  - provider: script
    skip_cleanup: true
    script: >-
      wget http://example.com/scripts/deploy_script.sh;
      chmod +x deploy_script.sh;
      sh ./deploy_script.sh theme;
    on:
      branch: master

Here is my deploy_script.sh:

#!/usr/bin/env bash

readonly SELF="$(basename $0)"
readonly SCRIPT_PATH="$(dirname $0)"
readonly REAL_PATH="$(cd "$(dirname "$1")"; pwd)"
readonly DATE=`date +%Y-%m-%d`


usage() {
    cat <<EOF

Usage:
     $SELF <theme | cms>

     Script to deploy headband theme for grav cms

EOF
}




cms() {

    cd /path/to/cms
    echo "Updating CMS ... can add a current date here or what not" >> /tmp/$DATE-deploy.log
    composer install --no-dev -o

}

theme() {
    cd ./themes/headband
    pwd
    echo "Updating Theme ... can add a current date here or what not" >> /tmp/$DATE-deploy.log
    rm -rf ./node_modules >> /tmp/$DATE-deploy.log
    echo "REMOVED NODE MODULES FOLDER"
    npm cache clean >> /tmp/$DATE-deploy.log
    echo "NPM CACHE CLEANED ... ... ... ... ... "
    npm install --save >> /tmp/$DATE-deploy.log
    echo "npm installed ... moving on ..."
    npm update >> /tmp/$DATE-deploy.log
    echo "NPM UPDATED ... ... ... ..."
    gulp >> /tmp/$DATE-deploy.log
    echo "GULP TASK COMPLETED ... ... ... ..."
}


# Exit if user input is < 1 params
if [ "$#" -lt "1" ]; then
    usage
    exit 2
fi


# Check for $action anything else echo usage
while [ "$#" -gt 0 ]; do
    action="$1"
    case $action in
        cms)
            cms
            exit 0
        ;;
        theme)
            theme
            exit 0
        ;;
        *)
            usage
            exit 2
        ;;
    esac
done

usage
exit 2

If anyone could point me in the right direction that would be amazing.

1

1 Answers

0
votes

So after many failed attempts I have successfully deployed while using scp and sans deploy script on the server side ( although still want to go that route to clean up .yml )

Currently it takes some time due to no compression or archiving, however if someone can assist that would be awesome. Otherwise will update at a later time.

I was also trying to get rsync to work but not just yet.

here is the final .travis.yml file that deploys all files from the build directory

sudo: required
language: node_js
node_js:
- stable
script:
- "/bin/true"
addons:
  ssh_known_hosts:
  - <ip-of-server>
after_success:
- openssl aes-256-cbc -K $encrypted_<secret>_key -iv $encrypted_<secret>_iv -in deploy_rsa.enc -out /tmp/deploy_rsa -d
- eval "$(ssh-agent -s)"
- chmod 600 /tmp/deploy_rsa
- ssh-add /tmp/deploy_rsa

deploy:
- provider: script
  skip_cleanup: true
  script: cd <build-directory> && rm -rf dist/ node_modules/ && npm install && gulp
  on:
    branch: master
- provider: script
  skip_cleanup: true
  script: scp -P <port> -r <directory-to-deploy> <user>@<server-ip>:<deploy-directory>
  on:
   branch: master