image: nexus-registry.xlab.si:5001/docker:dind

variables:
  REGISTRY: registry-gitlab.xlab.si

before_script:
  - export SERVICE=$(grep SERVICE MANIFEST | cut -d '=' -f2)
  - export VERSION=$(grep VERSION MANIFEST | cut -d '=' -f2)

stages:
  - build
  - test
  - push

build:
  stage: build
  script: 
    - docker build --no-cache -t $REGISTRY/medina/$SERVICE:$VERSION .  
  only:
    - develop
    - master

test:
  stage: test
  script:
    - echo "not yet implemented"
  only:
    - develop
    - master

push:
  stage: push
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $REGISTRY
    - docker tag $REGISTRY/medina/$SERVICE:$VERSION $REGISTRY/medina/$SERVICE:latest
    - docker push $REGISTRY/medina/$SERVICE:$VERSION
    - docker push $REGISTRY/medina/$SERVICE:latest
    - docker logout $REGISTRY
  only:
    - master