apiVersion: batch/v1
kind: Job
metadata:
  name: openpitrix-app-db-ctrl-job
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    job: openpitrix-app-db-ctrl
    version: ${VERSION}
spec:
  activeDeadlineSeconds: 600
  backoffLimit: 6
  completions: 1
  parallelism: 1
  template:
    metadata:
      labels:
        app: openpitrix
        job: openpitrix-app-db-ctrl
        version: ${VERSION}
      name: openpitrix-app-db-ctrl
    spec:
      initContainers:
      - name: wait-mysql
        image: busybox:1.28.4
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'until nc -z openpitrix-db.${NAMESPACE}.svc 3306; do echo "waiting for mysql"; sleep 2; done;']
      containers:
      - command: ["flyway", "-X", "-url=jdbc:mysql://openpitrix-db.${NAMESPACE}.svc/app", "-user=root", "-validateOnMigrate=false", "-locations=filesystem:/flyway/sql/app", "migrate"]
        env:
        - name: FLYWAY_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password.txt
              name: mysql-pass
        image: ${FLYWAY_IMAGE}
        imagePullPolicy: ${IMAGE_PULL_POLICY}
        name: openpitrix-app-db-ctrl
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: OnFailure
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
