image: docker:git

services:
  - docker:dind

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""

stages:
  - build
  - deploy

build_master:
  stage: build
  tags:
    - build-push-to-registry
  only:
    - master
  script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - docker build -t registry.forge.grandlyon.com/web-et-numerique/factory/llle_project/self-data-technical-doc .
    - docker push registry.forge.grandlyon.com/web-et-numerique/factory/llle_project/self-data-technical-doc

deploy_master:
  stage: deploy
  tags:
    - ns-cpd-p01-syn
  only:
    - master
  before_script:
    - NAMESPACE=ns-cpd-p01-syn
    - echo $READ_REGISTRY_TOKEN
    - echo $KUBE_CONFIG_CPD_PROD
    - export KUBECONFIG=$KUBE_CONFIG_CPD_PROD
  script:
    - oc create secret -n $NAMESPACE docker-registry forge-secret --docker-server=$CI_REGISTRY --docker-username=forge-secret --docker-password=$READ_REGISTRY_TOKEN --dry-run=client -o yaml | oc apply -f -
    - oc apply -f k8s/deployment.yml
    - oc apply -f k8s/service.yml
    - oc apply -f k8s/route.yml
    - oc delete pod -l app=self-data-doc
  