stages:
    - install
    - build
    - deploy

variables:
    CONTAINER_IMAGE: portus.lam.fr/anis/anis-client

install:
    image: node:11
    stage: install
    script:
        - yarn global add @angular/cli
        - yarn install
        - ng build --prod
    cache:
        paths:
            - dist
        policy: push
    only:
        refs:
            - develop

build:
    image: docker:stable
    stage: build
    script:
        - docker login -u fagneray -p $PORTUS_TOKEN portus.lam.fr
        - docker pull $CONTAINER_IMAGE:latest-dev || true
        - docker build --cache-from $CONTAINER_IMAGE:latest-dev -t $CONTAINER_IMAGE:latest-dev .
        - docker push $CONTAINER_IMAGE:latest-dev
    cache:
        paths:
            - dist
        policy: pull
    only:
        refs:
            - develop

deploy:
    image: alpine
    stage: deploy
    script:
        - apk add --update curl
        - curl -XPOST $DEV_WEBHOOK
    only:
        refs:
            - develop