apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: nexus
  name: nexus
spec:
  replicas: 1
  serviceName: nexus
  selector:
    matchLabels:
      app: nexus
  template:
    metadata:
      labels:
        app: nexus
    spec:
      containers:
        - name: nexus
          image: "quay.io/travelaudience/docker-nexus:3.19.1"
          imagePullPolicy: Always
          env:
            - name: INSTALL4J_ADD_VM_PARAMS
              value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
          resources:
            requests:
              cpu: 250m
              # Based on https://support.sonatype.com/hc/en-us/articles/115006448847#mem
              # and https://twitter.com/analytically/status/894592422382063616:
              #   Xms == Xmx
              #   Xmx <= 4G
              #   MaxDirectMemory >= 2G
              #   Xmx + MaxDirectMemory <= RAM * 2/3 (hence the request for 4800Mi)
              #   MaxRAMFraction=1 is not being set as it would allow the heap
              #     to use all the available memory.
              memory: 4800Mi
          ports:
            - containerPort: 5003
              name: nexus-docker-g
            - containerPort: 8081
              name: nexus-http
          volumeMounts:
            - mountPath: /nexus-data
              name: nexus-data
            - mountPath: /nexus-data/backup
              name: nexus-data-backup
        - name: nexus-proxy
          image: "quay.io/travelaudience/docker-nexus-proxy:2.5.0"
          imagePullPolicy: Always
          env:
            - name: ALLOWED_USER_AGENTS_ON_ROOT_REGEX
              value: "GoogleHC"
            - name: CLOUD_IAM_AUTH_ENABLED
              value: "false"
            - name: BIND_PORT
              value: "8080"
            - name: ENFORCE_HTTPS
              value: "false"
            - name: NEXUS_DOCKER_HOST
              value: "containers.example.com"
            - name: NEXUS_HTTP_HOST
              value: "nexus.example.com"
            - name: UPSTREAM_DOCKER_PORT
              value: "5003"
            - name: UPSTREAM_HTTP_PORT
              value: "8081"
            - name: UPSTREAM_HOST
              value: "localhost"
          ports:
            - containerPort: 8080
              name: nexus-proxy
        - name: nexus-backup
          image: "quay.io/travelaudience/docker-nexus-backup:1.5.0"
          imagePullPolicy: Always
          env:
            - name: NEXUS_AUTHORIZATION
              valueFrom:
                secretKeyRef:
                  key: nexus.authorization
                  name: nexus
            - name: NEXUS_BACKUP_DIRECTORY
              value: /nexus-data/backup
            - name: NEXUS_DATA_DIRECTORY
              value: /nexus-data
            - name: NEXUS_LOCAL_HOST_PORT
              value: "localhost:8081"
            - name: OFFLINE_REPOS
              value: "maven-central maven-public maven-releases maven-snapshots"
            - name: TARGET_BUCKET
              value: "gs://nexus-backup"
            - name: GRACE_PERIOD
              value: "60"
            - name: TRIGGER_FILE
              value: .backup
          volumeMounts:
            - mountPath: /nexus-data
              name: nexus-data
            - mountPath: /nexus-data/backup
              name: nexus-data-backup
      terminationGracePeriodSeconds: 10
  volumeClaimTemplates:
    - metadata:
        name: nexus-data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1024Gi
        storageClassName: standard
    - metadata:
        name: nexus-data-backup
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 32Gi
        storageClassName: standard
