apiVersion: apps/v1
kind: Deployment
metadata:
  name: astrojs
spec:
  selector:
    matchLabels:
      app: astrojs
  replicas: 1
  template:
    metadata:
      labels:
        app: astrojs
    spec:
      imagePullSecrets:
        - name: registry-auth
      initContainers:
        - name: init-dir
          image: alpine:latest
          command:
            - chown
            - 1001:1001
            - /app/cache
          volumeMounts:
          - name: cache
            mountPath: "/app/cache"
      containers:
        - name: web
          image: registry.k8s.astropenguin.net/astrojs:IMAGE_TAG
          securityContext:
            runAsGroup: 1001
            runAsNonRoot: true
            runAsUser: 1001
          env:
            - name: DEBUG
              value: "0"
            - name: FLASK_DEBUG
              value: "0"
            - name: FLASK_ENV
              value: "production"
            - name: RUN_MODE
              value: "web"
            - name: REDIS_CONN
              value: "redis://:@localhost:6379/9"
          volumeMounts:
          - name: cache
            mountPath: "/app/cache"
          livenessProbe:
            exec:
              command:
                - sh
                - -c
                - wget -qO - http://127.0.0.1:5000/rjs/System | grep -q function
        - name: redis
          image: redis:6.0.8-alpine
        - name: compiler
          image: registry.k8s.astropenguin.net/astrojs:IMAGE_TAG
          securityContext:
            runAsGroup: 1001
            runAsNonRoot: true
            runAsUser: 1001
          env:
            - name: RUN_MODE
              value: "tasks"
            - name: DEBUG
              value: "0"
            - name: REDIS_CONN
              value: "redis://:@localhost:6379/9"
          volumeMounts:
          - name: cache
            mountPath: "/app/cache"
        - name: assets
          image: nginx:alpine
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: cache
            - mountPath: "/etc/nginx/templates"
              name: nginx-conf-templates
      volumes:
        - name: cache
          persistentVolumeClaim:
            claimName: astrojs-cache
        - name: nginx-conf-templates
          secret:
            secretName: nginx-conf-templates

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: astrojs-cache
spec:
  accessModes: [ "ReadWriteOnce" ]
  resources:
    requests:
      storage: 1Gi
  storageClassName: local-storage

---

apiVersion: v1
kind: Service
metadata:
  name: astrojs
spec:
  selector:
    app: astrojs
  ports:
    - port: 5000
      targetPort: 5000
      name: application
    - port: 80
      targetPort: 80
      name: files