# StemeDB CI/CD Pipeline
# Push to main → Kaniko builds amd64 image → pushes to registry.threesix.ai → kubectl deploy
when:
  branch: main
  event: push

steps:
  build:
    image: woodpeckerci/plugin-kaniko
    settings:
      registry: registry.threesix.ai
      repo: stemedb-api
      tags:
        - latest
        - ${CI_COMMIT_SHA:0:8}
      context: .
      dockerfile: Dockerfile
      cache: true
      cache_repo: stemedb-api/cache
      skip_tls_verify: true

  deploy:
    image: bitnami/kubectl:latest
    environment:
      KUBECONFIG_DATA:
        from_secret: kubeconfig
    commands:
      - mkdir -p /root/.kube && echo "$KUBECONFIG_DATA" | base64 -d > /root/.kube/config
      - kubectl set image statefulset/stemedb stemedb=registry.threesix.ai/stemedb-api:${CI_COMMIT_SHA:0:8} -n stemedb
      - kubectl rollout status statefulset/stemedb -n stemedb --timeout=300s
    depends_on: [build]
