before_script:
  - bash .gitlab-ci.sh

stages:
  - testing
  - staging

variables:
  MYSQL_DATABASE: default
  MYSQL_USER: default
  MYSQL_PASSWORD: secret
  MYSQL_ROOT_PASSWORD: root

unitTesting:
  stage: testing
  image: php:7.2.6
  services:
    - mysql:5.7
  script:
    - vendor/bin/phpunit --coverage-text --colors=never

staging:
  stage: staging
  before_script:
    - mkdir -p ~/.ssh
    - echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
    - chmod 400 ~/.ssh/id_rsa
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
    - ssh admin@exchange-staging.izyim.com "cd exchange && git pull origin master && sudo docker-compose -f docker-prod.yml up -d"
  environment:
    name: staging
    url: https://exchange-staging.izyim.com/
  when: manual
