apiVersion: v1
kind: Service
metadata:
  name: app-repository
  namespace: {{ .Release.Namespace }}
spec:
  type: ClusterIP
  selector:
    app: app-repository
  ports:
  - name: http
    port: 80
    targetPort: http
    protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  namespace: {{ .Release.Namespace }}
  {{- if .Values.certificateIssuer }}
  annotations:
    acme.cert-manager.io/http01-edit-in-place: "true"
    cert-manager.io/cluster-issuer: {{ .Values.certificateIssuer }}
  {{- end }}
spec:
  ingressClassName: {{ .Values.ingressClassName }}
  {{- if .Values.certificateIssuer }}
  tls:
  - hosts:
    - {{ .Values.domain }}
    secretName: cert-app-repository
  {{- end }}
  rules:
  - host: {{ .Values.domain }}
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: app-repository
            port:
              name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-repository
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      app: app-repository
  replicas: 1
  template:
    metadata:
      labels:
        app: app-repository
    spec:
      containers:
      - name: app-repository
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - name: http
          containerPort: 8080
          protocol: TCP
        command:
        - app-repository
        - --port=8080
        - --apps-dir={{ .Values.appsDir }}
        - --scheme-with-host=https://{{ .Values.domain }}
