# Kaniko is used for building images in kubernetes.
# For more information see: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    # entrypoint needs to be overridden see: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
    entrypoint: [""]
  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  tags:
    - kubernetes

# Helm is used for deploying everything to kubernetes
# Afterwards we do a rolling restart of our deployment
deploy:
  stage: deploy
  image: dtzar/helm-kubectl
  tags:
    - kubernetes
  script:
    - envsubst < helm/values/develop.yaml > values.yaml
    - helm upgrade -i manifest-service helm/manifest-service -f values.yaml
    - kubectl rollout restart deployment manifest-service
  environment:
    name: $CI_COMMIT_REF_SLUG
    url: https://manifest-$CI_COMMIT_REF_SLUG.k3s.os.oxui.de/
  only:
    - main
