apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-sites-pvc
  namespace: home-apps
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: nfs-client
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-service
  namespace: home-apps
  labels:
    app: demo-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo-service
  template:
    metadata:
      labels:
        app: demo-service
    spec:
      containers:
        - name: caddy
          image: mirror.gcr.io/caddy:2
          ports:
            - containerPort: 80
              name: http
          volumeMounts:
            - name: caddy-config
              mountPath: /etc/caddy/Caddyfile
              subPath: Caddyfile
            - name: demo-data
              mountPath: /data/demos
            - name: error-page
              mountPath: /app/static/error-page.html
              subPath: error-page.html
          resources:
            requests:
              memory: 32Mi
              cpu: 50m
            limits:
              memory: 128Mi
              cpu: 200m

        - name: api
          # Image is updated automatically by .github/workflows/build-demo-service.yml
          # on every push that changes home-apps/demo-service/**
          image: ghcr.io/wahyd4/demo-manager:git-950fa76
          imagePullPolicy: Always
          ports:
            - containerPort: 3000
              name: api
          env:
            - name: DEMO_ROOT
              value: /data/demos
            - name: DEMO_API_KEY
              value: hermes-demo-secret-key-change-me
            - name: OAUTH_PROXY_URL
              value: https://pass.junv.cc
          volumeMounts:
            - name: demo-data
              mountPath: /data/demos
          resources:
            requests:
              memory: 64Mi
              cpu: 100m
            limits:
              memory: 256Mi
              cpu: 500m

      imagePullSecrets:
        - name: github-image-pull-secret

      volumes:
        - name: caddy-config
          configMap:
            name: demo-caddy-config
        - name: demo-data
          persistentVolumeClaim:
            claimName: demo-sites-pvc
        - name: error-page
          configMap:
            name: error-page-html
---
apiVersion: v1
kind: Service
metadata:
  name: demo-service
  namespace: home-apps
spec:
  selector:
    app: demo-service
  ports:
    - port: 80
      targetPort: 80
      name: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-service-ingress
  namespace: home-apps
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/tls-acme: "true"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - demo.junv.cc
      secretName: demo-service-tls
  rules:
    - host: demo.junv.cc
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: demo-service
                port:
                  number: 80
