apiVersion: apps/v1
kind: Deployment
metadata:
  name: backstage
  namespace: backstage
  labels:
    backstage.io/kubernetes-id: backstage
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backstage
  template:
    metadata:
      labels:
        app: backstage
        backstage.io/kubernetes-id: backstage
    spec:
      serviceAccountName: backstage
      containers:
        - name: backstage
          image: allardkrings/backstage:1.44.0
          imagePullPolicy: Always
          env:
            - name: PORT
              value: "7007"
            - name: POSTGRES_USER
              value: backstage
            - name: POSTGRES_PASSWORD
              value: backstage
            - name: POSTGRES_DB
              value: backstage
            - name: POSTGRES_SERVICE_HOST
              value: postgres13.postgres.svc.cluster.local
            - name: POSTGRES_SERVICE_PORT
              value: "5432"
            - name: APP_CONFIG_auth_environment
              value: development
            - name: NODE_ENV
              value: development
            - name: GITHUB_TOKEN
              valueFrom:
                secretKeyRef:
                  name: github-token
                  key: GITHUB_TOKEN
            - name: GITEA_TOKEN
              valueFrom:
                secretKeyRef:
                  name: gitea-token
                  key: GITEA_TOKEN
          volumeMounts:
            # Mount the configmap as a single file
            - mountPath: /app/app-config.production.yaml
              subPath: app-config.yaml
              name: app-configmap
            # Mount the PVC as the TechDocs storage directory
            - mountPath: /tmp/techdocs-storage
              name: techdocs-storage
            - name: private-users
              mountPath: /backstage/catalog/private-users
      volumes:
        # ConfigMap for app config
        - name: app-configmap
          configMap:
            name: backstage-app-config
        # PVC for TechDocs storage
        - name: techdocs-storage
          persistentVolumeClaim:
            claimName: backstage-pvc
        - name: private-users
          configMap:
            name: backstage-private-users

---
apiVersion: v1
kind: Service
metadata:
  name: backstage
  namespace: backstage
  labels:
    backstage.io/kubernetes-id: backstage
spec:
  type: ClusterIP
  selector:
    app: backstage
  ports:
    - name: http
      port: 7007
      targetPort: 7007

---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: backstage-tls
  namespace: backstage
  labels:
    backstage.io/kubernetes-id: backstage
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`backstage-dev.allarddcs.nl`)
      kind: Rule
      services:
        - name: backstage
          port: 7007
  tls:
    secretName: backstage-dev.allarddcs.nl-tls
