apiVersion: apps/v1
kind: Deployment
metadata:
  name: '{{ .Release.Name }}-webapp'
  labels:
    katenary.io/component: webapp
    katenary.io/project: basic
    katenary.io/release: '{{ .Release.Name }}'
  annotations:
    katenary.io/docker-compose-sha1: b9f12bb7d1e97901c1d7680394209525763f6640
    katenary.io/version: master-3619cc4
spec:
  replicas: 1
  selector:
    matchLabels:
      katenary.io/component: webapp
      katenary.io/release: '{{ .Release.Name }}'
  template:
    metadata:
      labels:
        katenary.io/component: webapp
        katenary.io/release: '{{ .Release.Name }}'
    spec:
      initContainers:
        - name: check-database
          image: busybox
          command:
            - sh
            - -c
            - |-
              OK=0
              echo "Checking database port"
              while [ $OK != 1 ]; do
                  echo -n "."
                  nc -z {{ .Release.Name }}-database 3306 2>&1 >/dev/null && OK=1 || sleep 1
              done
              echo
              echo "Done"
      containers:
        - name: webapp
          image: '{{ .Values.webapp.image }}'
          ports:
            - name: webapp
              containerPort: 80
          env:
            - name: DB_HOST
              value: '{{ .Release.Name }}-database'

