kind: pipeline
name: Build & publish main

steps:
- name: publish-image
  pull: always
  image: plugins/kaniko:1.7.1-kaniko1.9.1
  settings:
    auto_tag: true
    auto_tag_suffix: latest
    registry: code.groupe-genes.fr
    repo: code.groupe-genes.fr/dsit/documentation-dsit
    username:
      from_secret: docker_username
    password:
      from_secret: docker_password
  when:
    event:
      exclude:
      - pull_request
- name: deploy
  image: alpine
  environment:
    kubernetes_server:
      from_secret: k8s_server
    kubernetes_cert:
      from_secret: k8s_cert
    kubernetes_token:
      from_secret: k8s_token
  commands:
    - apk  add --no-cache curl
    - curl -LL -o /usr/bin/kubectl -v "https://dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl"
    - chmod +x /usr/bin/kubectl
    - echo $kubernetes_token
    - kubectl config set-cluster default --server=$kubernetes_server --insecure-skip-tls-verify=true
    - kubectl config set-credentials user --token=$kubernetes_token
    - kubectl config set-context default --user=user --cluster=default --namespace=documentation-dsit
    - kubectl config use-context default
    - kubectl rollout restart deployment documentation-dsit -n documentation-dsit --v=8
  when:
    event:
      exclude:
      - pull_request