apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  labels:
    app: backend
spec:
  selector:
    matchLabels:
      app: backend
  strategy:
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  template:
    metadata:
      labels:
        app: backend
    spec:
      imagePullSecrets:
        - name: "cr.seqera.io"
      volumes:
        - name: config-volume
          configMap:
            name: tower-yml
        # Volume for Studios
        #- name: cert-volume
        #  secret:
        #    secretName: platform-oidc-certs
      containers:
        - name: backend
          image: cr.seqera.io/enterprise/platform/backend:v26.2.3
          envFrom:
            - configMapRef:
                name: tower-backend-cfg
          env:
            - name: MICRONAUT_ENVIRONMENTS
              value: "prod,redis,ha"
            # Configuration to optimize JVM memory settings. See https://docs.seqera.io/platform-enterprise/enterprise/configuration/overview#backend-memory-requirements
            - name: JAVA_OPTS
              value: "-Xms1000M -Xmx2000M -XX:MaxDirectMemorySize=800m -Dio.netty.maxDirectMemory=0 -Djdk.nio.maxCachedBufferSize=262144"
            # TLS certificate for Studios
            #- name: TOWER_OIDC_PEM_PATH
            #  value: '/data/certs/oidc.pem'
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: config-volume
              mountPath: /tower.yml
              subPath: tower.yml
            # Volume mount for Studios
            #- name: cert-volume
            #  mountPath: /data/certs
          resources:
            requests:
              cpu: "1"
              memory: "4000Mi"
            limits:
              memory: "4000Mi"
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 5
            timeoutSeconds: 3
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 5
            timeoutSeconds: 3
            failureThreshold: 10
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
  labels:
    app: frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      imagePullSecrets:
        - name: "cr.seqera.io"
      containers:
        - name: frontend
          image: cr.seqera.io/enterprise/platform/frontend:v26.2.3
          ports:
            # From 26.2 the frontend image is unprivileged and listens on 8000.
            # Set this to match NGINX_LISTEN_PORT if you override it.
            - containerPort: 8000
      restartPolicy: Always
---
# Services
apiVersion: v1
kind: Service
metadata:
  name: backend
  labels:
    app: backend
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  selector:
    app: backend
---
#
# Backend API Service (Optional)
#
# This service exposes the backend API directly if you wish to have a separate
# API endpoint (e.g., api.cloud.seqera.io) distinct from the main frontend.
#
# When to use this:
# - You want a dedicated subdomain for API/CLI access (e.g., api.yourcompany.com)
# - You need to separate API traffic from web UI traffic
#
# Required configuration when enabled:
# - Configure appropriate ingress rules for the API subdomain
# - Ensure your DNS points the API subdomain to this service
#
# Note: This service is optional. Most deployments do not need this unless
# you intentionally want to expose the backend API via a dedicated subdomain.
# If not needed, you can remove this service to simplify your deployment and
# avoid potential routing conflicts with the frontend's wildcard setup.
#
---
apiVersion: v1
kind: Service
metadata:
  name: backend-api
spec:
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP
  type: NodePort
  selector:
    app: backend
---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8000
  selector:
    app: "frontend"
---
