apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "content-services.fullname" . }}-repository
  labels:
    app: {{ template "content-services.fullname" . }}-repository
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.repository.replicaCount }}
  template:
    metadata:
      labels:
        app: {{ template "content-services.fullname" . }}-repository
        release: {{ .Release.Name }}
    spec:
      imagePullSecrets:
        - name: {{ .Values.registryPullSecrets }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.repository.image.repository }}:{{ .Values.repository.image.tag }}"
          imagePullPolicy: {{ .Values.repository.image.pullPolicy }}
          envFrom:
          - configMapRef:
              name: {{ template "content-services.fullname" . }}-repository-configmap
          ports:
            - containerPort: {{ .Values.repository.image.internalPort }}
          resources:
{{ toYaml .Values.repository.resources | indent 12 }}
          volumeMounts:
          - name: data
            mountPath: {{ .Values.persistence.repository.data.mountPath }}
            subPath: {{ .Values.persistence.repository.data.subPath }}
      initContainers:
        - name: init-db
          image: busybox
          command: ['sh', '-c', 'until nc -w1 {{ template "database.hostname" . }} {{ template "database.port" . }}; do echo "waiting for {{ .Values.database.type }}"; sleep 2; done;']
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim }}
