apiVersion: apps/v1
kind: Deployment
metadata:
  name: java-guestbook-backend
  labels:
    app: java-guestbook
    tier: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: java-guestbook
      tier: backend
  template:
    metadata:
      labels:
        app: java-guestbook
        tier: backend
    spec:
      initContainers:
      - name: init-db-ready
        image: mongo:4
        command: ['/bin/sh', '-c']
        args:
          - echo "Waiting for mongodb at java-guestbook-mongodb:27017 to go live before the BE..."; 
          - until (mongo --host java-guestbook-mongodb:27017 >/dev/null) do echo "Waiting for connection for 2 sec."; sleep 2; done
      containers:
      - name: backend
        image: java-guestbook-backend
        ports:
        - name: http-server
          containerPort: 8080
        env:
        - name: PORT
          value: "8080"
        - name: GUESTBOOK_DB_ADDR
          value: "java-guestbook-mongodb:27017"
        # This environment variable enables debugging support for the container.
        # Remove this to disable the debug build.
        - name: JAVA_TOOL_OPTIONS
          value: -agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=n,quiet=y
