language: go

sudo: required

services:
    - docker

cache:
    directories:
        - "${HOME}/google-cloud-sdk/"

before_install:
    # Workaround to make gsutil work (see travis-ci#7940).
    # TODO(random-liu): Remove this after travis-ci#7940 is fixed.
    - sudo rm -f /etc/boto.cfg
    # libseccomp in trusty is not new enough, need backports version.
    - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' > /etc/apt/sources.list.d/backports.list"
    - sudo apt-get update
    # Encrypted data is not available for pull request for security concern.
    - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
        openssl aes-256-cbc -K $encrypted_b5f8c391f742_key -iv $encrypted_b5f8c391f742_iv -in gcp-secret.json.enc -out gcp-secret.json -d;
      fi

install:
    - sudo apt-get install btrfs-tools
    - sudo apt-get install libseccomp2/trusty-backports
    - sudo apt-get install libseccomp-dev/trusty-backports
    - sudo apt-get install libapparmor-dev
    - sudo apt-get install socat
    - docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
    # Pull request test doesn't need google cloud sdk.
    - if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ ! -d ${HOME}/google-cloud-sdk ]; then
        rm -rf "${HOME}/google-cloud-sdk"; 
        export CLOUDSDK_CORE_DISABLE_PROMPTS=1;
        curl https://sdk.cloud.google.com | bash;
        gcloud version;
      fi

before_script:
    - export PATH=$HOME/gopath/bin:$PATH
    - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
        gcloud auth activate-service-account --key-file gcp-secret.json --project=k8s-cri-containerd;
      fi

jobs:
  include:
    - stage: Build
      script:
        - make install.tools
        - make .gitvalidation
        - make binaries
      go: 1.9.x
    - script:
        - make install.tools
        - make .gitvalidation
        - make binaries
      go: tip
    - stage: Test
      script:
        - make install.deps
        - make test
        - make test-integration
        - make test-cri
      after_script:
        # Abuse travis to preserve the log.
        - cat /tmp/test-integration/cri-containerd.log
        - cat /tmp/test-integration/containerd.log
        - cat /tmp/test-cri/cri-containerd.log
        - cat /tmp/test-cri/containerd.log
      go: 1.9.x
    - stage: E2E Test
      script:
        # Skip node e2e test for pull request.
        - test "${TRAVIS_PULL_REQUEST}" != "false" && exit 0 || true
        - make install.deps
        - UPLOAD_LOG=true make test-e2e-node
      go: 1.9.x
