83 lines
3.3 KiB
YAML
83 lines
3.3 KiB
YAML
apiVersion: batch/v1
|
|
kind: Job
|
|
metadata:
|
|
name: django-service-user
|
|
namespace: django
|
|
annotations:
|
|
kustomize.toolkit.fluxcd.io/substitute: disabled
|
|
kustomize.toolkit.fluxcd.io/force: enabled
|
|
spec:
|
|
backoffLimit: 6
|
|
template:
|
|
metadata:
|
|
annotations:
|
|
sidecar.istio.io/inject: "false"
|
|
vault.hashicorp.com/agent-inject: "true"
|
|
vault.hashicorp.com/agent-pre-populate-only: "true"
|
|
vault.hashicorp.com/auth-path: auth/kubernetes
|
|
vault.hashicorp.com/role: django
|
|
vault.hashicorp.com/agent-inject-secret-django-postgresql: secrets/data/apps/django/postgres
|
|
vault.hashicorp.com/agent-inject-template-django-postgresql: |-
|
|
{{- with secret "secrets/data/apps/django/postgres" -}}
|
|
DJANGO_POSTGRES_HOST={{ index .Data.data "host" }}
|
|
DJANGO_POSTGRES_PORTS={{ index .Data.data "port" }}
|
|
DJANGO_POSTGRES_DATABASE={{ index .Data.data "database" }}
|
|
DJANGO_POSTGRES_USER={{ index .Data.data "username" }}
|
|
DJANGO_POSTGRES_PASSWORD={{ index .Data.data "password" }}
|
|
{{- end -}}
|
|
vault.hashicorp.com/agent-inject-secret-django-jwt-public: secrets/data/vault/common/jwt_public
|
|
vault.hashicorp.com/agent-inject-template-django-jwt-public: |-
|
|
{{- with secret "secrets/data/vault/common/jwt_public" -}}
|
|
{{ index .Data.data "public_key" }}
|
|
{{- end -}}
|
|
vault.hashicorp.com/agent-inject-secret-service-user: secrets/data/vault/common/django_auth
|
|
vault.hashicorp.com/agent-inject-template-service-user: |-
|
|
{{- with secret "secrets/data/vault/common/django_auth" -}}
|
|
SERVICE_USERNAME={{ index .Data.data "username" }}
|
|
SERVICE_PASSWORD={{ index .Data.data "password" }}
|
|
{{- end -}}
|
|
spec:
|
|
serviceAccountName: django-vault
|
|
restartPolicy: Never
|
|
imagePullSecrets:
|
|
- name: regcred
|
|
containers:
|
|
- name: service-user
|
|
image: cr.yandex/crp3ccidau046kdj8g9q/backend:production_7d0ec48b
|
|
imagePullPolicy: IfNotPresent
|
|
workingDir: /opt/sarex
|
|
command: ["/bin/sh", "-ec"]
|
|
args:
|
|
- |
|
|
set -a
|
|
. /vault/secrets/service-user
|
|
set +a
|
|
exec python manage.py shell -c '
|
|
import os
|
|
from django.contrib.auth import get_user_model
|
|
name = os.environ["SERVICE_USERNAME"]
|
|
user, created = get_user_model().objects.get_or_create(username=name)
|
|
user.set_password(os.environ["SERVICE_PASSWORD"])
|
|
user.is_active = True
|
|
user.is_staff = True
|
|
user.is_superuser = True
|
|
user.save()
|
|
print("service user", name, "created" if created else "updated")
|
|
'
|
|
env:
|
|
- name: DJANGO_SETTINGS_MODULE
|
|
value: config.settings.production
|
|
resources:
|
|
requests:
|
|
cpu: 50m
|
|
memory: 256Mi
|
|
volumeMounts:
|
|
- name: django-configmap
|
|
mountPath: /opt/sarex/config/settings/production.py
|
|
subPath: production.py
|
|
readOnly: true
|
|
volumes:
|
|
- name: django-configmap
|
|
configMap:
|
|
name: django-configmap
|