steps:
  build:
    image: plugins/kaniko
    settings:
      repo: gitea.hottis.de/wn/snmp-mqtt
      registry: 
        from_secret: container_registry
      tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
      username: 
        from_secret: container_registry_username
      password: 
        from_secret: container_registry_password
      dockerfile: Dockerfile
    when:
      - event: [push, tag]

  deploy:
    image: portainer/kubectl-shell:latest
    secrets:
      - source: kube_config
        target: KUBE_CONFIG_CONTENT
      - source: image_name
        target: IMAGE_NAME
    commands:
      - printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
      - export KUBECONFIG=/tmp/kubeconfig
      - cat $CI_WORKSPACE/deployment/deploy-yml.tmpl | sed -e 's,%IMAGE%,'$IMAGE_NAME':'$CI_COMMIT_TAG',' | kubectl apply -f - 
    when:
      - event: tag
