# Copyright (c) 2021 SIGHUP s.r.l All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

---
apiVersion: batch/v1
kind: Job
metadata:
  name: kong-migrations
  namespace: kong
spec:
  template:
    metadata:
      name: kong-migrations
    spec:
      initContainers:
      - name: wait-for-postgres
        image: busybox
        envFrom:
          - secretRef:
              name: kong-settings
        command: [ "/bin/sh", "-c", "until nc -zv $KONG_PG_HOST $KONG_PG_PORT -w1; do echo 'waiting for db'; sleep 1; done" ]
      containers:
      - name: kong-migrations
        image: kong
        envFrom:
          - secretRef:
              name: kong-settings
        command: [ "/bin/sh", "-c", "kong migrations bootstrap" ]
      restartPolicy: OnFailure
