image: java:8-jdk

services:
  - mysql:latest

 variables:
  # Configure mysql environment variables (https://hub.docker.com/_/mysql/)
  MYSQL_DATABASE: "aitrainer"
  MYSQL_ROOT_PASSWORD: "andio2009"
 

stages:
  - build
  - test
  - deploy

before_script:
  - echo `pwd` # debug
  - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
  - echo "$JAVA_HOME"
  - export GRADLE_USER_HOME=`pwd`/.gradle

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

build:
  stage: build
  script:
    - ./gradlew assemble
  artifacts:
    paths:
      - build/libs/*.jar
    expire_in: 1 week
  only:
    - master

test:
  stage: test
  Host: mysql
  User: aitrainer
  Password: andio2009
  Database: aitrainer

  script:
    - ./gradlew check -Pargs='spring.profiles.active=deploy'

deploy:
  stage: deploy
  script:
    - ./deploy

after_script:
  - echo "End CI"