stages:
  - test
  - build

## Cache composer packages between all jobs and all branches
## of this project...
cache:
  key: one-key-to-rull-them-all
  paths:
    - composer-cache/

before_script:
  - cp env.gitlab-ci .env
  - touch storage/app/db.sqlite
  - COMPOSER_CACHE_DIR=composer-cache composer install
  - php artisan key:generate
  - php artisan migrate

# Test with PHP7.4
test:php74:
  image: cylab/php74
  stage: test
  script:
    - vendor/bin/phpunit --coverage-text --colors=never --coverage-html build/coverage
    - vendor/bin/phpcs
  artifacts:
    paths:
    - build/
    expire_in: 1 month

build:
  image: docker:19.03.1
  stage: build
  tags:
    - dind
  services:
    - docker:19.03.1-dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - docker info
  script:
    - docker build -t cylab/ctf .


build:tagged:
  only:
    - tags
  image: docker:19.03.1
  stage: build
  tags:
    - dind
  services:
    - docker:19.03.1-dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - docker info
  script:
    - docker build -t cylab/ctf:$CI_COMMIT_TAG .
    - docker tag cylab/ctf:$CI_COMMIT_TAG cylab/ctf:latest
    - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
    - docker push cylab/ctf:$CI_COMMIT_TAG
    - docker push cylab/ctf:latest
