variables:
  APP_VERSION: $CI_COMMIT_REF_SLUG
  DOCKER_AUTH_CONFIG: '{"auths":{"$DOCKER_REGISTRY":{"username":"$DOCKER_USER","password":"$DOCKER_PASSWORD"}}}'

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:v1.6.0-debug
    entrypoint: [""]
  tags:
    - kube
  only:
    - master
  script:
    - mkdir -p /kaniko/.docker
    - echo "$DOCKER_AUTH_CONFIG" > /kaniko/.docker/config.json
    - /kaniko/executor
      --context .
      --dockerfile deploy/Dockerfile
      --destination "$DOCKER_REGISTRY/s3rius/blog:latest"
      --cache=true
      --force

deploy:
  stage: deploy
  image:
    name: alpine/helm:3.7.1
    entrypoint: ["/bin/sh", "-c"]
  tags:
    - kube
  only:
    - master
  environment:
    name: blog-production
    kubernetes:
      namespace: "$NAMESPACE"
    action: start
    url: "https://s3rius.blog/"
  script:
    - helm
      upgrade
      "s3rius-blog"
      ./deploy/helm
      --install
      --wait
      --create-namespace
      --atomic
      --timeout 2m
      --namespace "$NAMESPACE"
      -f "$HELM_CONFIG"
