apiVersion: apps/v1
kind: Deployment
metadata:
  name: gluetun
  namespace: family-apps
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gluetun
  template:
    metadata:
      labels:
        app: gluetun
    spec:
      nodeName: vmi2853337
      containers:
      - name: gluetun
        image: dannydirect/tinyproxy:latest
        args: ["ANY"]
        ports:
        - name: proxy
          containerPort: 8888
---
apiVersion: v1
kind: Service
metadata:
  name: gluetun-svc
  namespace: family-apps
spec:
  ports:
  - port: 8888
    targetPort: 8888
    name: proxy
  selector:
    app: gluetun
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: musicseerr
  namespace: family-apps
spec:
  replicas: 1
  selector:
    matchLabels:
      app: musicseerr
  template:
    metadata:
      labels:
        app: musicseerr
    spec:
      nodeName: vmi2853337
      containers:
      - name: musicseerr
        image: frankchine/geocrop-musicseerr:latest
        imagePullPolicy: Always
        env:
        - name: GLUETUN_PROXY_URL
          value: "http://gluetun-svc:8888"
        - name: TELEGRAM_BOT_TOKEN
          valueFrom:
            secretKeyRef:
              name: musicseerr-secrets
              key: telegram-bot-token
              optional: true
        - name: LASTFM_AUTO_DOWNLOAD_USER
          value: "fchinex"
        - name: LASTFM_AUTO_DOWNLOAD_INTERVAL_HOURS
          value: "12"
        ports:
        - name: http
          containerPort: 8000
        volumeMounts:
        - name: downloads
          mountPath: /tmp/downloads
        - name: media
          mountPath: /remote-music
          mountPropagation: HostToContainer
      # Rclone sidecar container configured exactly like Jellyfin and Navidrome
      - name: rclone
        image: rclone/rclone:latest
        args:
        - mount
        - "seedhost:/home2/tadiwanashe/downloads/media"
        - /data
        - --allow-other
        - --allow-non-empty
        - --vfs-cache-mode
        - full
        - --vfs-cache-max-size
        - 5G
        - --cache-dir
        - /cache
        securityContext:
          privileged: true
          capabilities:
            add: ["SYS_ADMIN"]
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "fusermount -u /data"]
        envFrom:
        - secretRef:
            name: rclone-secret
        volumeMounts:
        - name: media
          mountPath: /data
          mountPropagation: Bidirectional
        - name: cache
          mountPath: /cache
      volumes:
      - name: downloads
        emptyDir: {}
      - name: media
        emptyDir: {}
      - name: cache
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: musicseerr
  namespace: family-apps
spec:
  ports:
  - port: 8000
    targetPort: 8000
    name: http
  selector:
    app: musicseerr
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: musicseerr-ingress
  namespace: family-apps
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - musicseerr.techarvest.co.zw
    secretName: musicseerr-tls
  rules:
  - host: musicseerr.techarvest.co.zw
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: musicseerr
            port:
              number: 8000
