trigger: none


stages:
- stage: DEV
  displayName: DEV
  jobs:
  - job: Deploy
    pool:
      name: Paynance Docker
    variables:
    - name: host
      value: landing-dev.k8spaynance.com
      
    steps:

          - task: Kubernetes@1
            displayName: 'Delete Landing resources'
            inputs:
              connectionType: 'Kubernetes Service Connection'
              kubernetesServiceEndpoint: 'Paynance Kubernetes DEV'
              namespace: 'dev-443-ingress'
              command: 'delete'
              arguments: 'deployments,services,ingress landing --insecure-skip-tls-verify'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'
            continueOnError: true

          - task: Kubernetes@1
            displayName: 'Create Landing Deployment'
            inputs:
              connectionType: 'Kubernetes Service Connection'
              kubernetesServiceEndpoint: 'Paynance Kubernetes DEV'
              namespace: 'dev-443-ingress'
              command: 'apply'
              useConfigurationFile: true
              configurationType: 'inline'
              inline: |
                apiVersion: apps/v1
                kind: Deployment
                metadata:
                  name: landing
                  labels:
                    env: dev
                spec:
                  replicas: 1
                  selector:
                    matchLabels:
                      app: landing
                      env: dev
                  template:
                    metadata:
                      labels:
                        app: landing
                        env: dev
                    spec:
                      enableServiceLinks: false
                      containers:
                        - name: landing
                          image: paynance/landing
                          ports:
                            - containerPort: 443
                            - containerPort: 80
                          volumeMounts:
                          - name: ssl
                            mountPath: "/etc/nginx/ssl/"
                            readOnly: true
                      volumes:
                      - name: ssl
                        secret:
                          secretName: nginx-tls-secret
                      imagePullSecrets:
                        - name: paynance-docker
                ---
                apiVersion: v1
                kind: Service
                metadata:
                  name: landing
                  labels:
                    env: dev
                spec:
                  type: NodePort
                  selector:
                    app: landing
                    env: dev
                  ports:
                    - protocol: TCP
                      port: 8088
                      targetPort: 443
                ---
                apiVersion: networking.k8s.io/v1
                kind: Ingress
                metadata:
                  name: landing
                  annotations:
                    kubernetes.io/ingress.class: "nginx"
                    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
                    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
                spec:
                  rules:
                  - host: $(DEV_HOST)
                    http:
                      paths:
                        - path: /
                          pathType: Prefix
                          backend:
                            service:
                              name: landing
                              port:
                                number: 8088
              arguments: '--insecure-skip-tls-verify'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'
              outputFormat: 'yaml'
            continueOnError: true

- stage: TST
  displayName: TST
  jobs:
  - job: Deploy
    pool:
      name: Paynance Docker
    variables:
    - name: host
      value: landing-tst.k8spaynance.com
      
    steps:

          - task: Kubernetes@1
            displayName: 'Delete Landing resources'
            inputs:
              connectionType: 'Kubernetes Service Connection'
              kubernetesServiceEndpoint: 'Paynance Kubernetes TST'
              namespace: 'tst-443-ingress'
              command: 'delete'
              arguments: 'deployments,services,ingress landing --insecure-skip-tls-verify'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'
            continueOnError: true

          - task: Kubernetes@1
            displayName: 'Create Landing Deployment'
            inputs:
              connectionType: 'Kubernetes Service Connection'
              kubernetesServiceEndpoint: 'Paynance Kubernetes TST'
              namespace: 'tst-443-ingress'
              command: 'apply'
              useConfigurationFile: true
              configurationType: 'inline'
              inline: |
                apiVersion: apps/v1
                kind: Deployment
                metadata:
                  name: landing
                  labels:
                    env: tst
                spec:
                  replicas: 1
                  selector:
                    matchLabels:
                      app: landing
                      env: tst
                  template:
                    metadata:
                      labels:
                        app: landing
                        env: tst
                    spec:
                      enableServiceLinks: false
                      containers:
                        - name: landing
                          image: paynance/landing
                          ports:
                            - containerPort: 443
                            - containerPort: 80
                          volumeMounts:
                          - name: ssl
                            mountPath: "/etc/nginx/ssl/"
                            readOnly: true
                      volumes:
                      - name: ssl
                        secret:
                          secretName: nginx-tls-secret
                      imagePullSecrets:
                        - name: paynance-docker
                ---
                apiVersion: v1
                kind: Service
                metadata:
                  name: landing
                  labels:
                    env: tst
                spec:
                  type: NodePort
                  selector:
                    app: landing
                    env: tst
                  ports:
                    - protocol: TCP
                      port: 8088
                      targetPort: 443
                ---
                apiVersion: networking.k8s.io/v1
                kind: Ingress
                metadata:
                  name: landing
                  annotations:
                    kubernetes.io/ingress.class: "nginx"
                    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
                    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
                spec:
                  rules:
                  - host: $(TST_HOST)
                    http:
                      paths:
                        - path: /
                          pathType: Prefix
                          backend:
                            service:
                              name: landing
                              port:
                                number: 8088
              arguments: '--insecure-skip-tls-verify'
              secretType: 'dockerRegistry'
              containerRegistryType: 'Azure Container Registry'
              outputFormat: 'yaml'
            continueOnError: true

- stage: PRD
  displayName: PRD
  jobs:
  - job: Deploy
    pool:
      name: Paynance Docker
    steps:

    - task: Kubernetes@1
      displayName: 'Delete Landing resources'
      inputs:
        connectionType: 'Kubernetes Service Connection'
        kubernetesServiceEndpoint: 'Paynance Kubernetes PRD'
        namespace: 'prd-443-ingress'
        command: 'delete'
        arguments: 'deployments,services,ingress landing --insecure-skip-tls-verify'
        secretType: 'dockerRegistry'
        containerRegistryType: 'Azure Container Registry'
      continueOnError: true

    - task: Kubernetes@1
      displayName: 'Create Landing Deployment'
      inputs:
        connectionType: 'Kubernetes Service Connection'
        kubernetesServiceEndpoint: 'Paynance Kubernetes PRD'
        namespace: 'prd-443-ingress'
        command: 'apply'
        useConfigurationFile: true
        configurationType: 'inline'
        inline: |
          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: landing
            labels:
              env: dev
          spec:
            replicas: 1
            selector:
              matchLabels:
                app: landing
                env: dev
            template:
              metadata:
                labels:
                  app: landing
                  env: dev
              spec:
                enableServiceLinks: false
                containers:
                  - name: landing
                    image: paynance/landing
                    env:
                    - name: DBHOST
                      value: $(DBHOST)
                    ports:
                      - containerPort: 443
                      - containerPort: 80
                    volumeMounts:
                    - name: ssl
                      mountPath: "/etc/nginx/ssl/"
                      readOnly: true
                volumes:
                - name: ssl
                  secret:
                    secretName: nginx-tls-secret
                imagePullSecrets:
                  - name: paynance-docker
          ---
          apiVersion: v1
          kind: Service
          metadata:
            name: landing
            labels:
              env: dev
          spec:
            type: NodePort
            selector:
              app: landing
              env: dev
            ports:
              - protocol: TCP
                port: 8088
                targetPort: 443
          ---
          apiVersion: networking.k8s.io/v1
          kind: Ingress
          metadata:
            name: landing
            annotations:
              kubernetes.io/ingress.class: "nginx"
              nginx.ingress.kubernetes.io/ssl-passthrough: "true"
              nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
          spec:
            rules:
            - host: $(PRD_HOST)
              http:
                paths:
                  - path: /
                    pathType: Prefix
                    backend:
                      service:
                        name: landing
                        port:
                          number: 8088
        arguments: '--insecure-skip-tls-verify'
        secretType: 'dockerRegistry'
        containerRegistryType: 'Azure Container Registry'
        outputFormat: 'yaml'
      continueOnError: true