apiVersion: apps/v1
kind: Deployment
metadata:
  name: wcag-ada-worker
  namespace: wcag-ada
spec:
  replicas: 2
  selector:
    matchLabels:
      app: wcag-ada-worker
  template:
    metadata:
      labels:
        app: wcag-ada-worker
    spec:
      initContainers:
      - name: wait-for-services
        image: busybox:1.36
        command: ['sh', '-c', 'until nc -z postgres-service 5432 && nc -z redis-service 6379 && nc -z wcag-ada-api-service 3001; do echo waiting for services; sleep 2; done']
      containers:
      - name: worker
        image: wcag-ada/worker:latest
        ports:
        - containerPort: 3002
        envFrom:
        - configMapRef:
            name: wcag-ada-config
        - secretRef:
            name: wcag-ada-secrets
        livenessProbe:
          httpGet:
            path: /health
            port: 3002
          initialDelaySeconds: 40
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 3002
          initialDelaySeconds: 10
          periodSeconds: 5
        resources:
          requests:
            memory: "512Mi"
            cpu: "250m"
          limits:
            memory: "1Gi"
            cpu: "1000m"
        securityContext:
          capabilities:
            add:
            - SYS_ADMIN
          runAsUser: 1001
          runAsGroup: 1001
---
apiVersion: v1
kind: Service
metadata:
  name: wcag-ada-worker-service
  namespace: wcag-ada
spec:
  selector:
    app: wcag-ada-worker
  ports:
    - port: 3002
      targetPort: 3002
  type: ClusterIP