apiVersion: batch/v1
kind: Job
metadata:
  name: <%= app_name %>-setup
  labels:
    app: <%= app_name %>
spec:
  template:
    metadata:
      name: <%= app_name %>-setup
    spec:
      containers:
      - name: setup
        image: <%= registry_host %>:<%= registry_port %>/<%= app_name %>:latest
        args: ["bin/rails db:environment:set RAILS_ENV=production && DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rake db:create && rake db:migrate && rake db:seed"]
        env:
        - name: DATABASE_USER
          valueFrom:
            secretKeyRef:
              name: <%= app_name %>-db-user
              key: username
        - name: DATABASE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: <%= app_name %>-db-user-pass
              key: password
        - name: DATABASE_NAME
          valueFrom:
            secretKeyRef:
              name: <%= app_name %>-db-name
              key: name
        - name: RAILS_ENV
          value: production
        - name: SECRET_KEY_BASE
          valueFrom:
            secretKeyRef:
              name: <%= app_name %>-secrets
              key: secret-key-base          
        - name: REDIS_PASS
          valueFrom:
            secretKeyRef:
              name: redis
              key: redis-password
        - name: REDIS_HOST
          value: <%= redis_host %>
        - name: REDIS_PORT
          value: "<%= redis_port %>"
      restartPolicy: Never
  backoffLimit: 1
