# Copyright 2021 Chainguard, Inc.
# SPDX-License-Identifier: Apache-2.0

apiVersion: batch/v1
kind: Job
metadata:
  name: createdb
  namespace: trillian-system
spec:
  template:
    spec:
      serviceAccountName: createdb
      restartPolicy: Never
      containers:
      - name: createdb
        image: ko://github.com/vaikas/sigstore-scaffolding/cmd/trillian/createdb
        args: [
        "--mysql_uri=$(MYSQL_USER):$(MYSQL_PASSWORD)@tcp($(DATABASE_HOSTNAME):3306)/",
        "--db_name=trillian"
        ]
        env:
          - name: DATABASE_NAME
            valueFrom:
              secretKeyRef:
                name: trillian-client
                key: name
          - name: MYSQL_USER
            valueFrom:
              secretKeyRef:
                name: trillian-client
                key: username
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: trillian-client
                key: password
          - name: DATABASE_HOSTNAME
            valueFrom:
              secretKeyRef:
                name: trillian-client
                key: host
