variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2
  BACKEND_IMAGE: docker.km3net.de/km3mon-backend
  RECO_IMAGE: docker.km3net.de/km3mon-reco
  FRONTEND_IMAGE: docker.km3net.de/km3mon-frontend
  LIVELOG_IMAGE: docker.km3net.de/km3mon-livelog

stages:
  - docker
  - release

backend:
  image: docker:stable
  services:
    - docker:dind
  stage: docker
  script:
    - docker build --pull -t $BACKEND_IMAGE:test backend/
  tags:
    - docker

frontend:
  image: docker:stable
  services:
    - docker:dind
  stage: docker
  script:
    - docker build --pull -t $FRONTEND_IMAGE:test frontend/
  tags:
    - docker

livelog:
  image: docker:stable
  services:
    - docker:dind
  stage: docker
  script:
    - docker build --pull -t $LIVELOG_IMAGE:test livelog/
  tags:
    - docker

reco:
  image: docker:stable
  services:
    - docker:dind
  stage: docker
  script:
    - docker build --pull -t $RECO_IMAGE:test reco/
  tags:
    - docker

backend-release:
  image: docker:stable
  services:
    - docker:dind
  stage: release
  script:
    - docker build --pull -t $BACKEND_IMAGE:${CI_COMMIT_TAG:1} backend/
    - docker tag $BACKEND_IMAGE:${CI_COMMIT_TAG:1} $BACKEND_IMAGE:latest
    - docker push $BACKEND_IMAGE:${CI_COMMIT_TAG:1}
    - docker push $BACKEND_IMAGE:latest
  tags:
    - docker
  only:
    - tags

frontend-release:
  image: docker:stable
  services:
    - docker:dind
  stage: release
  script:
    - docker build --pull -t $FRONTEND_IMAGE:${CI_COMMIT_TAG:1} frontend/
    - docker tag $FRONTEND_IMAGE:${CI_COMMIT_TAG:1} $FRONTEND_IMAGE:latest
    - docker push $FRONTEND_IMAGE:${CI_COMMIT_TAG:1}
    - docker push $FRONTEND_IMAGE:latest
  tags:
    - docker
  only:
    - tags

livelog-release:
  image: docker:stable
  services:
    - docker:dind
  stage: release
  script:
    - docker build --pull -t $LIVELOG_IMAGE:${CI_COMMIT_TAG:1} livelog/
    - docker tag $LIVELOG_IMAGE:${CI_COMMIT_TAG:1} $LIVELOG_IMAGE:latest
    - docker push $LIVELOG_IMAGE:${CI_COMMIT_TAG:1}
    - docker push $LIVELOG_IMAGE:latest
  tags:
    - docker
  only:
    - tags

reco-release:
  image: docker:stable
  services:
    - docker:dind
  stage: release
  script:
    - docker build --pull -t $RECO_IMAGE:${CI_COMMIT_TAG:1} reco/
    - docker tag $RECO_IMAGE:${CI_COMMIT_TAG:1} $RECO_IMAGE:latest
    - docker push $RECO_IMAGE:${CI_COMMIT_TAG:1}
    - docker push $RECO_IMAGE:latest
  tags:
    - docker
  only:
    - tags
