apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "gogs.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: {{ template "gogs.fullname" . }}
  template:
    metadata:
      labels:
        app: {{ template "gogs.fullname" . }}
    spec:
      {{- with .Values.securityContext }}
      securityContext:
{{ toYaml . | indent 8 }}
      {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      {{- end }}
      {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - containerPort: 3000
            - containerPort: 22
          livenessProbe:
            initialDelaySeconds: 180
            httpGet:
              path: /
              port: 3000
          readinessProbe:
            initialDelaySeconds: 180
            httpGet:
              path: /
              port: 3000
          env:
            # https://github.com/gogits/gogs/tree/master/docker#container-options
            - name: SOCAT_LINK
              value: "false"
          resources:
{{ toYaml .Values.resources | indent 12 }}
          volumeMounts:
            - name: data
              mountPath: /data
            - name: config
              mountPath: /data/gogs/conf/app.ini
              subPath: app.ini
      volumes:
        - name: config
          configMap:
            name: {{ template "gogs.fullname" . }}-config
        - name: data
      {{- if .Values.persistence.enabled }}
          persistentVolumeClaim:
            {{- if .Values.persistence.existingClaim }}
            claimName: {{ .Values.persistence.existingClaim }}
            {{- else }}
            claimName: {{ template "gogs.fullname" . }}
            {{- end -}}
      {{- else }}
          emptyDir: {}
      {{- end -}}
