fga-eps-mds/2019.1-unbrake

View on GitHub
.travis.yml

Summary

Maintainability
Test Coverage
sudo: required

language: minimal

services:
  - docker

notifications:
  slack:
    secure: pP5E+YX1+qR3chyZmyBwt/00wZ2HL4ENjFBSxqLbf/0rOjr+SBwf/IwQbFCEqdWkAGxccD71uegZ0q7Kgs4nCNqItCyau/2S61QWBOvGUJtdhsnSZQ7sQjLOKBUUgeQlZGC7xDandxRV6XgVegUu6/l28xttxTkNcE1Q3i/0WoAXUcmOyH32Flw454WxIlSMgOX0xb1Npj+15F+sKoo3od26/Nd7UyHnGQD3fO0Kk5DHLMs2Kr8x1UFI7+nIrQmI4FVGcVEnOMa+mKI0LlhvAi7Ma6C8l+BQJTAwPG3HqamCrq7l7cyWmDpQY3ySjPSfp2f1LzPBLx3Bx54wb0YQiLt0nQlW/oymlXDH+8q53KEIyXm72yOTvWZR5bldmjf5Ap7OEAWLbSZRMEleZCcKrZ6q8zJn+IRuSqT0VJQUS89IjTlG9MKznipD0qBmI9N5QbPl8wk502po+5U3oYuptGV+JOSC2aC6RcJqWtgKaElHFJMfAqm80VDzuW9+9f7llIsLEpwbKCj3xpysHZQOYVT0zwo2gP/15kGr445xbGOaYhJ7rEnTXhixgyRD+SeXmJkzTLX6HY1HlPaNLNy3ggcbg+4yEr/t4lN61RVGK+hfsO0DwSta++rLC8xj/prfI91BPS4ttCB8/5R5f5plN15sRgkyZ9zboUAxv0ERWyE=
    on_success: change
    on_failure: always

cache:
  directories:
    - "unbrake-frontend/node_modules"

addons:
  ssh_known_hosts:
    - unbrake-hom.ml
    - unbrake.ml

env:
  global:
    - DOCKER_COMPOSE_VERSION=1.23.2

    - DOCKER_DEVELOPMENT_TAG="latest-development"

    # Staging things
    - DOCKER_STAGING_TMP_TAG="latest-staging-tmp"
    - DOCKER_STAGING_TAG=latest-staging
    - STAGING_HOST=unbrake-hom.ml

    # Production things
    - DOCKER_PRODUCTION_TAG=latest
    - PRODUCTION_HOST=unbrake.ml

    # code climate test reporter id (it's not so secret)
    - secure: "CFCx6LcmtNOBVyFjxgW8NcrmAs3Fr7ueq4tbjg8f7LCHRodsQMxAAL8+8BbeP41YDZ34mqEwemc8QG5dXXSE8lFVAzJfUUQnYncpu1YiywwYmxP6cNWcBtu1h6sBUOfObBz2mQyJnt1yL2TKob4vaK0jtzy099Mew8aIxRzqcHL04TqxG902ITdGiraH89nIN64MKw7CQMUy65S0kRo1RJkQQDJ9s5CKVnBy3n0Vv8qJj+JqKrzJeRSOrpxElg0yOEe7hFNQkavyBbyGt++f0O1AupQxP9drCxrWRsYTUt/+WNWiZnkNXWSBqHgwrYn13ObthrmgHw5vNTA8sYnzav68kypRbuQm4b4oUaSuQWa5c6cfl0wKa7Uk5t8np78wVByK9+yy84+KL91kDYrxFVEoWe55CDDvL1G6HWP28x1cmL8GA35H+rADDdXQaxxEeDpbExTwOf7N3brNfUh416psDF9VyVqDq46wtJapuAE3Onj9rWmP+EMYxaBdVeV+2wi24/sowwqPQF+sBHWnW0pM+xmOztrptZRdMnwCuVzWt+ROVWm+/tAVn5k+Q1/KW9IXF3JF3975A14Bj+x5HxbbHAs95TOcD79qsAO0L+FMHxadgrMcEFwSPP9sTEfwagKLoX7jnXwOQq9hFwkUxGHDDH4Tj7y7OEM/JXo+JJw="

    # docker user
    - secure: "JjYzX/71jkBYS7NcfrXQuvNyyUepw/5ZFfKdYi7bnF6s6bDxoKGv8SFSoczToOfwaynQWc5mnG5s5BZO8rQJCN5i8dgKvoLEkRF3wzXZMa7nNAZrZW0pc/4kkRy13PZyc/ZV3MTtO5ccwLeErQ1gLDb+UixtBxDxZ7N/+lseylTO149BgiT48anc7U1rmzI8XJiMzareajJzuHssVyZTZfkxj34eHTXIAp+8mTJGL3vWA8/0bvcl0kLWQDIoGeX8qqM6CSfiK0mRj+mVqn9l8FXVgQayZQU8/HJg+5KhAbiPbtyQ+0CZWYrj2UiqV7T6IckI23NAsvG9TISr9q77fzgNLgEL7yEwVzSntcGjeD5bq8aODrMSlLxbqZPykptZtv/NuXDbtH4pASQe14mjTNtvYGk9E1yIKH4WfmKKMU1GePclb5bN3J+j33lWqpLGOhHnAgJtpkoJ1UREu1ves6TP5ELdaDXx9dBNQh/IrUBQwYcjj5qhxr6iA2wzei7jWJv3RcN1s7m80kSHRcaTSQZkuNUaXhNbtZYXO/aVu3y2KspRByu9gITnmG0Dib5Ed2nx8QYKWZppb3SHCz14jWAFRiSua7pkCJ/QheJLAIFIPTuDCAOHpC7Y7+AUuGYfn2CUJkajoXg9dAb9tKaGU32Eo2PYR3cq/PM5HhIqgns="

    # docker password
    - secure: "WOvXPmJMLdtgUdCw96qn78erQ35ggcVh7OJ6pzhdoOt8vCufROgnGqGMDlQYRoIL1MnFFo5zoaaw09kOi92WiL7w2Q0QcFBQ3VkJR4Q3ooH3A/Vk0mlmGD3RXQHNzOA8Af+jK/vMxt3VVS/CUvIOI4pPWvettiazVE/KCaPDODVyT7P11iHXXO5BvufJ/BGs5g/m5q97M8xPF3GPbObCWZ6BvATIX1vfbPdiPXLzMwfzI0UrfApSaxZwVzNgr3LwOdIVaFoI68wI1QWIsR6RmIbB+M+WDnQpmYFEC4HEO6wzFk/kaJqwUxpw68K2szdO+TpqgrCx07uP06VdZrQnmfsekmEjp6s8rDQkKu84zFd1b5ZRgvSjDeNbTFP5vJOma5DQE0X03U0295oKJacEa2H6jiLJitWrrsEG+Wvb4OHeAUUGxLKmCQnQ4R4GpSq6HH5zhmLkCJ9CUz3SPouhUFztfRbfcnln/2nxbZm84vdm0TBio0RVi5oLdCboR6obCcEpmsTYo8pcUwKSVg/0rgVINNnsIGhPFwGuoDl9q833PD4gkJxJUY45wu9k/YZJye0TijfxQYlOaTxa91AvYlxi9F3M9VYuodoaRpHN1gzUiWEnorKwwf24BmrQFy3wZeAHvlmsCDS5IHlbJYJHWP+lVd3afl6jVckZWcSHiyA="

before_install:
  # Update Docker Compose
  - sudo rm /usr/local/bin/docker-compose
  - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
  - chmod +x docker-compose
  - sudo mv docker-compose /usr/local/bin

  # Update Docker
  - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  - sudo apt-get update
  - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

  # General secrets from API
  - openssl aes-256-cbc -K $encrypted_ec73e88a7c5d_key -iv $encrypted_ec73e88a7c5d_iv -in unbrake-api/secrets/API_DJANGO_SECRET_KEY.enc -out unbrake-api/secrets/API_DJANGO_SECRET_KEY -d
  - openssl aes-256-cbc -K $encrypted_e2b707099939_key -iv $encrypted_e2b707099939_iv -in unbrake-api/secrets/DB_PASSWORD.enc -out unbrake-api/secrets/DB_PASSWORD -d
  - openssl aes-256-cbc -K $encrypted_12b7f6274154_key -iv $encrypted_12b7f6274154_iv -in unbrake-api/secrets/HTTPS_KEY.enc -out unbrake-api/secrets/HTTPS_KEY -d

  # Deploy Key
  - openssl aes-256-cbc -K $encrypted_46d61bdc678c_key -iv $encrypted_46d61bdc678c_iv -in deploy/deploy_key.enc -out deploy/deploy_key -d

  # MQTT environment variables
  - openssl aes-256-cbc -K $encrypted_a8aa7a1b7e93_key -iv $encrypted_a8aa7a1b7e93_iv -in deploy/.env_mqtt.enc -out deploy/.env_mqtt -d
  - openssl aes-256-cbc -K $encrypted_ddb8f7363e54_key -iv $encrypted_ddb8f7363e54_iv -in unbrake-api/secrets/MQTT_READING_KEY.enc -out unbrake-api/secrets/MQTT_READING_KEY -d
  - openssl aes-256-cbc -K $encrypted_6d56a259a9f3_key -iv $encrypted_6d56a259a9f3_iv -in unbrake-api/secrets/MQTT_WRITING_KEY.enc -out unbrake-api/secrets/MQTT_WRITING_KEY -d


before_script:
  - 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


# Aliases -------------------------------------------------------
build_staging: &build_development
  stage: "build staging/development environments"
  before_script: skip
  script:
    - docker build "$BUILD_FOLDER/" -t "$DOCKER_IMAGE:${DOCKER_DEVELOPMENT_TAG}" -f "$BUILD_FOLDER/Dockerfile"
    - echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
    - docker push "$DOCKER_IMAGE:${DOCKER_DEVELOPMENT_TAG}"
    - docker logout

build_staging: &build_staging
  stage: "build staging/development environments"
  before_script: skip
  script:
    - docker build "$BUILD_FOLDER/" -t "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}" -f "$BUILD_FOLDER/production/Dockerfile"
    - echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
    - docker push "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}"
    - docker logout

deploy_staging: &deploy_staging
  stage: "deploy staging images"
  if: branch = devel AND type != pull_request
  before_script: skip
  script:
    - docker pull "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}"
    - docker tag "$DOCKER_IMAGE:${DOCKER_STAGING_TMP_TAG}" "$DOCKER_IMAGE:${DOCKER_STAGING_TAG}" 
    - echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
    - docker push "$DOCKER_IMAGE:${DOCKER_STAGING_TAG}"
    - docker logout
# --------------------------------------------------------------

jobs:
  include:
    # Build all these images images on parallel for speed
    - <<: *build_development
      name: "Build frontend (development)"
      env:
        - BUILD_FOLDER=unbrake-frontend
        - DOCKER_IMAGE=unbrake/frontend

    - <<: *build_development
      name: "Build API (development)"
      env:
        - BUILD_FOLDER=unbrake-api
        - DOCKER_IMAGE=unbrake/api

    - <<: *build_staging
      name: "Build frontend (staging)"
      env:
        - BUILD_FOLDER=unbrake-frontend
        - DOCKER_IMAGE=unbrake/frontend

    - <<: *build_staging
      name: "Build API (staging)"
      env:
        - BUILD_FOLDER=unbrake-api
        - DOCKER_IMAGE=unbrake/api

    - stage: "development checkings and tests"
      name: "General git checks"
      before_install: skip
      before_script: skip
      script:
        - git diff --check || (echo 'Trailing whitespaces or conflict marks found!' && exit 1)
        - if [ -d unbrake ]; then echo 'The unbrake folder must not exist!' && (exit 1); fi

    - name: "Static analysis"
      script:
        - sudo docker pull "unbrake/api:$DOCKER_DEVELOPMENT_TAG"
        - sudo docker pull "unbrake/frontend:$DOCKER_DEVELOPMENT_TAG"
        - sudo docker pull "unbrake/local"
        - sed -i -e "/\s\+build/d" -e "/\s\+context/d" -e "/\s\+dockerfile/d" docker-compose.yml

        - docker-compose up -d 

        - docker-compose exec frontend npm run check_format
        - docker-compose exec frontend npm run check_lint

        - docker-compose exec api python manage.py check_format
        - docker-compose exec api python manage.py check_lint

        - docker-compose down -v

        - (cd unbrake-local && ./scripts/check_format)
        - (cd unbrake-local && ./scripts/check_lint)

    - name: "Run tests and collect coverage"
      script:
        - sudo docker pull "unbrake/api:$DOCKER_DEVELOPMENT_TAG"
        - sudo docker pull "unbrake/frontend:$DOCKER_DEVELOPMENT_TAG"
        - sudo docker pull "unbrake/local"
        - sed -i -e "/\s\+build/d" -e "/\s\+context/d" -e "/\s\+dockerfile/d" docker-compose.yml

        - docker-compose up -d
        - docker-compose exec frontend npm run check_tests:coverage
        - docker-compose exec api python manage.py check_tests_coverage
        - docker-compose down -v

        - (cd unbrake-local && ./scripts/check_tests_coverage)

        # Collect coverage
        - mkdir coverage
        - (cd unbrake-frontend && ./../cc-test-reporter format-coverage -t lcov -o ../coverage/frontend.json -p /app/frontend src/tests/coverage/lcov.info)
        - (cd unbrake-api && ./../cc-test-reporter format-coverage -t coverage.py -o ../coverage/api.json -p /app/api)
        - (cd unbrake-local && ./../cc-test-reporter format-coverage -t gocov -o ../coverage/local.json -p github.com/fga-eps-mds/2019.1-unbrake/unbrake-local coverage.out)

        # Merge coverage results and upload
        - ./cc-test-reporter sum-coverage -o coverage/codeclimate.json -p 3 coverage/*.json
        - if [[ "$TRAVIS_TEST_RESULT" == 0 ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter upload-coverage -i coverage/codeclimate.json; fi

    - <<: *deploy_staging
      name: "Deploy frontend"
      env:
        - DOCKER_IMAGE=unbrake/frontend

    - <<: *deploy_staging
      name: "Deploy API"
      env:
        - DOCKER_IMAGE=unbrake/api
    
    - stage: "deploy to staging environment"
      name: "Deploy to staging environment"
      if: branch = devel AND type != pull_request
      script:
        # Deploy key to travis environment
        - eval "$(ssh-agent -s)"
        - chmod 600 deploy/deploy_key
        - ssh-add deploy/deploy_key

        # Deploy to staging environment
        - (cd deploy && bash scripts/deploy "$STAGING_HOST" staging)

    - stage: "deploy to production environment"
      name: "Deploy to production environment"
      if: branch = master AND type != pull_request
      script:
        # Pull latest staging images
        - docker pull "unbrake/frontend:${DOCKER_STAGING_TAG}"
        - docker pull "unbrake/api:${DOCKER_STAGING_TAG}"

        # Re-tag lastest staging images to production images
        - docker tag "unbrake/frontend:${DOCKER_STAGING_TAG}" "unbrake/frontend:${DOCKER_PRODUCTION_TAG}" 
        - docker tag "unbrake/api:${DOCKER_STAGING_TAG}" "unbrake/api:${DOCKER_PRODUCTION_TAG}" 

        # Push images as production images
        - echo "$DOCKER_PASSWORD" | docker login -u "${DOCKER_USERNAME}" --password-stdin
        - docker push "unbrake/frontend:${DOCKER_PRODUCTION_TAG}" 
        - docker push "unbrake/api:${DOCKER_PRODUCTION_TAG}" 
        - docker logout

        # Deploy key to travis environment
        - eval "$(ssh-agent -s)"
        - chmod 600 deploy/deploy_key
        - ssh-add deploy/deploy_key

        # Deploy to staging environment
        - (cd deploy && bash scripts/deploy "$PRODUCTION_HOST" prod)