apiVersion: apps/v1
kind: Deployment
metadata:
  name: servala
spec:
  template:
    spec:
      containers:
        - name: servala
          env:
            - name: SERVALA_ENVIRONMENT
              value: staging
            - name: SERVALA_ALLOWED_HOSTS
              value: staging.portal.servala.com
        - name: ssh-tunnel
          image: servala-2nkgm.app.codey.ch/servala/servala-portal:latest
          command:
            - "/bin/bash"
            - "-c"
            - |
              mkdir -p /app/.ssh && chmod 700 /app/.ssh
              echo "$SSH_PRIVATE_KEY" > /app/.ssh/id
              chmod 600 /app/.ssh/id
              ssh $SSH_HOST -l $SSH_USER -o StrictHostKeyChecking=no -L 8443:127.0.0.1:8443 -N -i /app/.ssh/id -v
          env:
            - name: SSH_HOST
              valueFrom:
                secretKeyRef:
                  name: servala-sshclient
                  key: ssh-host
            - name: SSH_USER
              valueFrom:
                secretKeyRef:
                  name: servala-sshclient
                  key: ssh-user
            - name: SSH_PRIVATE_KEY
              valueFrom:
                secretKeyRef:
                  name: servala-sshclient
                  key: ssh-private-key
