datacite/lupo

View on GitHub
.travis.yml

Summary

Maintainability
Test Coverage
language: ruby
rvm:
- 2.6.5
sudo: required

services:
  - mysql
  - docker
  - memcached

before_install:
  - curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-amd64.deb
  - sudo dpkg -i --force-confnew elasticsearch-7.1.1-amd64.deb
  - sudo sed -i.old 's/-Xms1g/-Xms512m/' /etc/elasticsearch/jvm.options
  - sudo sed -i.old 's/-Xmx1g/-Xmx512m/' /etc/elasticsearch/jvm.options
  - echo -e '-XX:+DisableExplicitGC\n-Djdk.io.permissionsUseCanonicalPath=true\n-Dlog4j.skipJansi=true\n-server\n' | sudo tee -a /etc/elasticsearch/jvm.options
  - sudo chown -R elasticsearch:elasticsearch /etc/default/elasticsearch
  - sudo systemctl start elasticsearch
  - sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
  - sudo mysql_upgrade -u root
  - sudo service mysql restart
  - mysql -e 'CREATE DATABASE lupo_test;'

install:
  - travis_retry bundle install
  - curl -sL https://sentry.io/get-cli/ | bash
  - sentry-cli --version

before_script:
  - memcached -p 11211 &
  - cp .env.travis .env
  - mkdir -p tmp/pids tmp/storage
  - chmod -R 755 tmp/storage
  - bundle exec rake db:setup RAILS_ENV=test
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
  - chmod +x ./cc-test-reporter
  - ./cc-test-reporter before-build

script:
  - bundle exec rubocop
  - bundle exec rspec spec
after_script:
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

after_success:
  - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD";
  - REPO=datacite/lupo;
  - AUTO_DEPLOY=false;
  - if [ "${TRAVIS_TAG?}" ]; then
      docker build -f Dockerfile -t $REPO:$TRAVIS_TAG .;
      docker push $REPO:$TRAVIS_TAG;
      echo "Pushed to" $REPO:$TRAVIS_TAG;
      AUTO_DEPLOY=true;
    elif [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then
      docker build -f Dockerfile -t $REPO .;
      docker push $REPO;
      echo "Pushed to" $REPO;
      AUTO_DEPLOY=true;
    else
      docker build -f Dockerfile -t $REPO:$TRAVIS_BRANCH .;
      docker push $REPO:$TRAVIS_BRANCH;
      echo "Pushed to" $REPO:$TRAVIS_BRANCH;
    fi

  - if [ "$AUTO_DEPLOY" == "true" ]; then
      wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz;
      tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz;
      rm dockerize-linux-amd64-v0.6.0.tar.gz;
      export GIT_SHA=$(git rev-parse --short HEAD);
      export GIT_REVISION=$(git rev-parse HEAD);
      export GIT_TAG=$(git describe --tags $(git rev-list --tags --max-count=1));

      git clone "https://${TRAVIS_SECURE_TOKEN}@github.com/datacite/mastino.git";
      ./dockerize -template vendor/docker/_lupo.auto.tfvars.tmpl:mastino/stage/services/client-api/_lupo.auto.tfvars;
        
      sentry-cli releases new lupo:${GIT_TAG} --finalize --project lupo;

      if [ "${TRAVIS_TAG?}" ]; then
        ./dockerize -template vendor/docker/_lupo.auto.tfvars.tmpl:mastino/prod-eu-west/services/client-api/_lupo.auto.tfvars;
        ./dockerize -template vendor/docker/_lupo.auto.tfvars.tmpl:mastino/test/services/client-api/_lupo.auto.tfvars;
        sentry-cli releases deploys lupo:${GIT_TAG} new -e production;
      else
        sentry-cli releases deploys lupo:${GIT_TAG} new -e stage;
      fi

      sentry-cli releases set-commits --auto lupo:${GIT_TAG};
      
      cd mastino;
      git remote;
      git config user.email ${DOCKER_EMAIL};
      git config user.name ${DOCKER_USERNAME};
      
      if [ "${TRAVIS_TAG?}" ]; then
        git add prod-eu-west/services/client-api/_lupo.auto.tfvars;
        git add test/services/client-api/_lupo.auto.tfvars;
        git commit -m "Adding lupo git variables for commit tagged ${TRAVIS_TAG?}";
        git push "https://${TRAVIS_SECURE_TOKEN}@github.com/datacite/mastino.git" master;
      else
        git add stage/services/client-api/_lupo.auto.tfvars;
        git commit -m "Adding lupo git variables for latest commit";
        git push "https://${TRAVIS_SECURE_TOKEN}@github.com/datacite/mastino.git" master;
      fi
    fi

notifications:
  slack: datacite:Wt8En0ALoTA6Kjc5EOKNDWxN
  email: false