apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-guestbook-backend
  labels:
    app: guestbook
    tier: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: guestbook
      tier: backend
  template:
    metadata:
      labels:
        app: guestbook
        tier: backend
    spec:
      initContainers:
      - name: init-db-ready
        image: mongo:4
        command: ['/bin/sh', '-c']
        args:
          - echo "Waiting for mongodb at go-guestbook-mongodb:27017 to go live before the BE..."; 
          - until (mongo --host go-guestbook-mongodb:27017 >/dev/null) do echo "Waiting for connection for 2 sec."; sleep 2; done
      containers:
      - name: backend
        image: go-guestbook-backend
        ports:
        - name: http-server
          containerPort: 8080
        - name: debug
          containerPort: 3000
        env:
        - name: PORT
          value: "8080"
        - name: GUESTBOOK_DB_ADDR
          value: go-guestbook-mongodb:27017
