---
kind: pipeline
type: kubernetes
name: build

trigger:
  event: [ push ]
  branch: [ master ]

steps:
- name: build
  image: plugins/docker
  settings:
    registry: https://gitea.home.jbrumond.me
    username: drone
    password:
      from_secret: gitea-jbrumond-me-password
    repo: gitea.home.jbrumond.me/doc-utils/docs
    cache_from: gitea.home.jbrumond.me/doc-utils/docs:ci
    tags:
    - ci

---
kind: pipeline
type: kubernetes
name: deploy-stg

trigger:
  event: [ promote ]
  target: [ stg ]

steps:
- name: build-and-publish
  image: plugins/docker
  settings:
    registry: https://gitea.home.jbrumond.me
    username: drone
    password:
      from_secret: gitea-jbrumond-me-password
    repo: gitea.home.jbrumond.me/doc-utils/docs
    cache_from: gitea.home.jbrumond.me/doc-utils/docs:ci
    tags:
    - stg

- name: deploy-stg
  image: gitea.home.jbrumond.me/images/kubectl:1.24
  pull: always
  environment:
    KUBERNETES_SERVER: https://nephthys:6443
    KUBERNETES_TOKEN:
      from_secret: kubernetes-web-ns-service-account-token
    KUBERNETES_CERT:
      from_secret: kubernetes-web-ns-service-account-cert
  commands:
  - /bin/kubectl-setup
  - kubectl -n web set image "deployment/doc-utils-stg-deploy" "doc-utils-stg=gitea.home.jbrumond.me/doc-utils/docs:stg"
  - kubectl -n web rollout restart "deployment/doc-utils-stg-deploy"
  - kubectl -n web rollout status "deployment/doc-utils-stg-deploy"

---
kind: pipeline
type: kubernetes
name: deploy-prod

trigger:
  event: [ promote ]
  target: [ prod ]

steps:
- name: tag-image
  image: gitea.home.jbrumond.me/images/docker
  pull: always
  volumes:
  - name: dockersock
    path: /var/run/
  environment:
    DOCKER_REGISTRY: https://gitea.home.jbrumond.me
    DOCKER_USER: drone
    DOCKER_PASS:
      from_secret: gitea-jbrumond-me-password
  commands:
  - /bin/docker-setup
  - docker pull gitea.home.jbrumond.me/doc-utils/docs:stg
  - docker tag gitea.home.jbrumond.me/doc-utils/docs:stg gitea.home.jbrumond.me/doc-utils/docs:prod
  - docker push gitea.home.jbrumond.me/doc-utils/docs:prod

- name: deploy-prod
  image: gitea.home.jbrumond.me/images/kubectl:1.24
  pull: always
  environment:
    KUBERNETES_SERVER: https://nephthys:6443
    KUBERNETES_TOKEN:
      from_secret: kubernetes-web-ns-service-account-token
    KUBERNETES_CERT:
      from_secret: kubernetes-web-ns-service-account-cert
  commands:
  - /bin/kubectl-setup
  - kubectl -n web set image "deployment/doc-utils-prod-deploy" "doc-utils-prod=gitea.home.jbrumond.me/doc-utils/docs:prod"
  - kubectl -n web rollout restart "deployment/doc-utils-prod-deploy"
  - kubectl -n web rollout status "deployment/doc-utils-prod-deploy"

volumes:
- name: dockersock
  host:
    path: /var/run/

