variables:
  IMAGE_NAME: funkwhale/funkwhale
  IMAGE: $IMAGE_NAME:$CI_BUILD_REF
  IMAGE_LATEST: $IMAGE_NAME:latest



stages:
  - test
  - build
  - deploy

test_api:
  stage: test
  image: funkwhale/funkwhale:base
  before_script:
    - cd api
    - pip install -r requirements/test.txt
  script:
    - pytest

  tags:
    - docker

build_front:
  stage: build
  image: node:6-alpine
  before_script:
    - cd front

  script:
    - npm install
    - npm run build
  cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
      - front/node_modules
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
  only:
    - master
    - develop
  tags:
    - docker


pages:
  stage: test
  image: alpine
  before_script:
    - cd docs
  script:
    - apk --no-cache add py2-pip python-dev
    - pip install sphinx
    - apk --no-cache add make
    - make html
    - mv _build/html/ ../public
  artifacts:
    paths:
      - public
  only:
    - develop
  tags:
    - docker

docker_develop:
  stage: deploy
  before_script:
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
    - cd api
  script:
    - docker build -t $IMAGE .
    - docker push $IMAGE
  only:
    - develop
  tags:
    - dind

docker_release:
  stage: deploy
  before_script:
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
    - cd api
  script:
    - docker build -t $IMAGE -t $IMAGE_LATEST .
    - docker push $IMAGE
    - docker push $IMAGE_LATEST
  only:
    - master
  tags:
    - dind
