stages:
  - build
  - test
  - deploy

variables:
  - DOCKER_DRIVER: overlay2

services:
  - docker:dind

before_sript:
  - docker info
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

build: 
  stage: build
  script:
    - docker build -t goenglish-backend .

test: 
  stage: test
  script:
    - docker-compose -f docker-compose.prod.yml up -d
    - docker-compose -exec -T app php artisan migrate --env=testing
    - docker-compose -exec -T app vendor/bin/phpunit
    - docker-compose down

deploy:
  stage: deploy
  script:
    - docker tag go-english-backend-container registry.com/go-english-backend/
    - docker push
  only:
    - merge_requests
    - push

