apiVersion: batch/v1
kind: Job
metadata:
  name: create-superuser-chalk-ENV
spec:
  template:
    spec:
      serviceAccountName: chalk-ENV
      shareProcessNamespace: true
      containers:
        - name: create-superuser-cloud-sql-proxy
          image: gcr.io/cloudsql-docker/gce-proxy:latest
          command:
            - "/cloud_sql_proxy"
            - "-instances=GCP_PROJECT:us-east4:chalk-ENV=tcp:5432"
          securityContext:
            runAsNonRoot: true
        - name: create-superuser
          image: gcr.io/GCP_PROJECT/chalk-server:local-latest
          command: ["/bin/sh", "-c"]
          args:
            - |
              sleep 5s
              python manage.py createsuperuser --no-input;
              sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;
          securityContext:
            capabilities:
              add:
                - SYS_PTRACE
          env:
            - name: DJANGO_SUPERUSER_EMAIL
              valueFrom:
                secretKeyRef:
                  name: chalk-ENV-server
                  key: django-email
            - name: DJANGO_SUPERUSER_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: chalk-ENV-server
                  key: django-password
            - name: DJANGO_SUPERUSER_USERNAME
              valueFrom:
                secretKeyRef:
                  name: chalk-ENV-server
                  key: django-username
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: chalk-ENV-server
                  key: db-password
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: chalk-ENV-server
                  key: secret-key
            - name: DB_NAME
              value: chalk-ENV
            - name: DB_USER
              value: chalk-ENV
      restartPolicy: Never
  backoffLimit: 3

