variables:
  REGISTRY: registry.vshn.net
  NAMESPACE: vshn-servalafe-prod
  OC_IMAGE: docker.io/appuio/oc:v4.16

stages:
  - build
  - deploy

.base:
  stage: build
  image: docker:stable
  tags:
    - dockerbuild_sks
  services:
    - name: docker:dind
      command: ["--mtu=1450"]
  before_script:
    - until docker info; do sleep 5; done
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

docker-build-latest:
  extends: .base
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
    - docker push "$CI_REGISTRY_IMAGE"
  only:
    - main

deploy:
  stage: deploy
  image: $OC_IMAGE
  script:
    - oc -n ${NAMESPACE} apply --overwrite -f deployment/
    - oc -n ${NAMESPACE} rollout restart deployment/servala
  environment:
    name: prod
    url: https://poc.serva.la/
  only:
    - main
