---
kind: pipeline
type: docker
name: deploy prod

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/master

steps:
  - name: npm-install
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - npm install --legacy-peer-deps

  - name: make-prod
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - make prod
    depends_on:
      - npm-install

  - name: deploy-prod
    image: amazon/aws-cli:latest
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      AWS_MAX_ATTEMPTS: 10
    commands:
      - aws s3 sync build s3://insports-prod --delete
      - aws cloudfront create-invalidation --distribution-id E3KY6BCU3AYHEW --paths "/*"
    depends_on:
      - make-prod

  - name: make-auth
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - make auth-production-build
    depends_on:
      - npm-install

  - name: deploy-S3-auth
    image: amazon/aws-cli:latest
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      AWS_MAX_ATTEMPTS: 10
    commands:
      - aws s3 sync build_auth s3://insports-auth --delete
      - aws cloudfront create-invalidation --distribution-id EERIKX9X2SRPJ --paths "/*"
    depends_on:
      - make-auth

  - name: deploy-old-auth-server
    image: node:16-alpine
    environment:
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH
    commands:
      - apk add --no-cache openssh-client rsync
      - eval $(ssh-agent -s)
      - echo -n "$SSH_KEY_AUTH" | tr -d '\r' | ssh-add -
      - mkdir -p ~/.ssh && chmod 700 ~/.ssh
      - ssh-keyscan auth.insports.tv >> ~/.ssh/known_hosts
      - rsync -v -r -C build_auth/ ubuntu@auth.insports.tv:/home/ubuntu/ott-auth/src/frontend/
    depends_on:
      - make-auth

  - name: make-india
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - make india-prod
    depends_on:
      - npm-install

  - name: deploy-india
    image: amazon/aws-cli:latest
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      AWS_MAX_ATTEMPTS: 10
    commands:
      - aws s3 sync build_india s3://insports-india --delete
      - aws cloudfront create-invalidation --distribution-id E5DKN8IPOMASO --paths "/*"
    depends_on:
      - make-india

  - name: make-facr
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - make facr-prod
    depends_on:
      - npm-install

  - name: deploy-facr
    image: amazon/aws-cli:latest
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      AWS_MAX_ATTEMPTS: 10
    commands:
      - aws s3 sync build_facr s3://insports-facr-tv --delete
      - aws cloudfront create-invalidation --distribution-id E1ZYJS9RAJO89D --paths "/*"
    depends_on:
      - make-facr

  - name: make-lff
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - make lff-prod
    depends_on:
      - npm-install

  - name: deploy-lff
    image: amazon/aws-cli:latest
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      AWS_MAX_ATTEMPTS: 10
    commands:
      - aws s3 sync build_lff s3://insports-tv-lff-lv --delete
      - aws cloudfront create-invalidation --distribution-id E2127IDW4TEH4S --paths "/*"
    depends_on:
      - make-lff

#  - name: make-diwansport
#    image: node:16-alpine
#    environment:
#      REACT_APP_STRIPE_PK:
#        from_secret: REACT_APP_STRIPE_PK
#    commands:
#      - apk add --no-cache make
#      - make diwansport-prod
#    depends_on:
#      - npm-install
#
#  - name: deploy-diwansport
#    image: amazon/aws-cli:latest
#    environment:
#      AWS_ACCESS_KEY_ID:
#        from_secret: AWS_ACCESS_KEY_ID
#      AWS_SECRET_ACCESS_KEY:
#        from_secret: AWS_SECRET_ACCESS_KEY
#      AWS_DEFAULT_REGION:
#        from_secret: AWS_DEFAULT_REGION
#      AWS_MAX_ATTEMPTS: 10
#    commands:
#      - aws s3 sync build_insports-diwansport s3://insports-diwansport --delete
#      - aws cloudfront create-invalidation --distribution-id E3LKAH6TR4O2JL --paths "/*"
#    depends_on:
#      - make-diwansport

---
kind: pipeline
type: docker
name: deploy preprod (test.insports.tv)

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/develop

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make preprod
      - aws s3 sync build s3://instat-frontend-test --delete
      - aws cloudfront create-invalidation --distribution-id E2ZD1DVVFA1ACC --paths "/*"

---
kind: pipeline
type: docker
name: deploy test-a

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-a

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-a
      - aws s3 sync build s3://instat-frontend-test-a --delete
      - aws cloudfront create-invalidation --distribution-id E1WZHVCHZ48SG6 --paths "/*"

---
kind: pipeline
type: docker
name: deploy test-b

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-b

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-b
      - aws s3 sync build s3://instat-frontend-test-b --delete
      - aws cloudfront create-invalidation --distribution-id E3FV6BVKSJ892U --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-c

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-c

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-c
      - aws s3 sync build s3://instat-frontend-test-c --delete
      - aws cloudfront create-invalidation --distribution-id E4FBTH9Z3Q4TM --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-d

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-d

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-d
      - aws s3 sync build s3://instat-frontend-test-d --delete
      - aws cloudfront create-invalidation --distribution-id E3E5C472O6CVFK --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-e

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-e

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-e
      - aws s3 sync build s3://instat-frontend-test-e --delete
      - aws cloudfront create-invalidation --distribution-id E1S8ZOPGSJZ7Q3 --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-f

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-f

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-f
      - aws s3 sync build s3://instat-frontend-test-f --delete
      - aws cloudfront create-invalidation --distribution-id E22E79CELC9QUZ --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-g

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-g

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-g
      - aws s3 sync build s3://instat-frontend-test-g --delete
      - aws cloudfront create-invalidation --distribution-id E187U4H1ZQD1UV --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-h

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-h

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-h
      - aws s3 sync build s3://instat-frontend-test-h --delete
      - aws cloudfront create-invalidation --distribution-id E18Y84N03IBWDY --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-i

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-i

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-i
      - aws s3 sync build s3://instat-frontend-test-i --delete
      - aws cloudfront create-invalidation --distribution-id EJYRP4WNVMWD1 --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-j

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-j

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make build-j
      - aws s3 sync build s3://instat-frontend-test-j --delete
      - aws cloudfront create-invalidation --distribution-id EC35D25OP7FSL --paths "/*"


---
kind: pipeline
type: docker
name: deploy test-auth

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/test-auth

steps:
  - name: deploy script
    image: node:16-alpine

    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK_TEST
      SSH_KEY_AUTH_TEST:
        from_secret: SSH_KEY_AUTH_TEST

    commands:
      - apk add --no-cache aws-cli bash git openssh-client make rsync
      - npm install --legacy-peer-deps
      - make auth-build
      - eval $(ssh-agent -s)
      - echo -n "$SSH_KEY_AUTH_TEST" | tr -d '\r' | ssh-add -
      - mkdir -p ~/.ssh && chmod 700 ~/.ssh
      - ssh-keyscan auth.test.insports.tv >> ~/.ssh/known_hosts
      - rsync -v -r -C build_auth/ ubuntu@auth.test.insports.tv:/home/ubuntu/ott-auth/src/frontend/
      - rsync -v -r -C build_auth/clients/* ubuntu@auth.test.insports.tv:/home/ubuntu/ott-auth/src/frontend/templates
      - aws s3 sync build_auth s3://auth-insports-test --delete
      - aws cloudfront create-invalidation --distribution-id E10YI3RFOZZDLZ --paths "/*"


---
kind: pipeline
type: docker
name: deploy auth prod

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/auth

steps:
  - name: npm-install
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - npm install --legacy-peer-deps

  - name: make-auth
    image: node:16-alpine
    environment:
      REACT_APP_STRIPE_PK:
        from_secret: REACT_APP_STRIPE_PK
    commands:
      - apk add --no-cache make
      - make auth-production-build
    depends_on:
      - npm-install

  - name: deploy-S3-auth
    image: amazon/aws-cli:latest
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY:
        from_secret: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION:
        from_secret: AWS_DEFAULT_REGION
      AWS_MAX_ATTEMPTS: 10
    commands:
      - aws s3 sync build_auth s3://insports-auth --delete
      - aws cloudfront create-invalidation --distribution-id EERIKX9X2SRPJ --paths "/*"
    depends_on:
      - make-auth

  - name: deploy-old-auth-server
    image: node:16-alpine
    environment:
      SSH_KEY_AUTH:
        from_secret: SSH_KEY_AUTH
    commands:
      - apk add --no-cache openssh-client rsync
      - eval $(ssh-agent -s)
      - echo -n "$SSH_KEY_AUTH" | tr -d '\r' | ssh-add -
      - mkdir -p ~/.ssh && chmod 700 ~/.ssh
      - ssh-keyscan auth.insports.tv >> ~/.ssh/known_hosts
      - rsync -v -r -C build_auth/ ubuntu@auth.insports.tv:/home/ubuntu/ott-auth/src/frontend/
    depends_on:
      - make-auth
