# dev-api-server.yml - Kubernetes deployment file for development API server
#
# Persistent volume specification that defines a Kubernetes persistent volume
# mapped to the server source directory. Each time you restart the server, the
# current source from your local client will be used.
apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ smoacks_app_name_k }}-dev-server
  labels:
    type: server
spec:
  accessModes:
    - ReadOnlyMany
  capacity:
    storage: {{ smoacks_app_volume_size }}
  storageClassName: server
  hostPath:
    path: {{ smoacks_local_dev_path }}
---
# Claim for development server
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {{ smoacks_app_name_k }}-dev-server-claim
spec:
  storageClassName: server
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: {{ smoacks_app_volume_size }}
---
# Deployment specification for development server
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: {{ smoacks_app_name_k }}-dev-server
spec:
  selector:
    matchLabels:
      app: {{ smoacks_app_name_k }}-dev-server
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: {{ smoacks_app_name_k }}-dev-server
      annotations:
        user: root
    spec:
      containers:
      - image: {{ smoacks_server_base }}
        name: {{ smoacks_app_name_k }}-dev-server
        env:
        - name: {{ smoacks_app_name_c }}_MODE
          value: "development"
        command: ["/app/src/server-loop"]
        ports:
        - containerPort: {{ smoacks_server_container_port }}
        volumeMounts:
        - name: {{ smoacks_app_name_k }}-dev-server-vol
          mountPath: /app
      volumes:
      - name: {{ smoacks_app_name_k }}-dev-server-vol
        persistentVolumeClaim:
          claimName: {{ smoacks_app_name_k }}-dev-server-claim
---
# Service that exposes development server to local network
apiVersion: v1
kind: Service
metadata:
  name: {{ smoacks_app_name_k }}-dev-server
spec:
  type: NodePort
  ports:
  - port: {{ smoacks_server_container_port }}
    nodePort: {{ smoacks_dev_server_service_port }}
    targetPort: {{ smoacks_server_container_port }}
  selector:
    app: {{ smoacks_app_name_k }}-dev-server
