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

concurrency:
  limit: 1

platform:
  os: linux
  arch: amd64

trigger:
  ref:
  - refs/heads/master

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
      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 prod
#      - aws s3 sync build s3://insports-prod --delete
#      - aws cloudfront create-invalidation --distribution-id E3KY6BCU3AYHEW --paths "/*"
      - aws s3 sync build s3://instat-frontend-test-a --delete
      - aws cloudfront create-invalidation --distribution-id E1WZHVCHZ48SG6 --paths "/*"
      - make auth-production-build
      - 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/
      - rsync -v -r -C build_auth/clients/* ubuntu@auth.insports.tv:/home/ubuntu/ott-auth/src/frontend/templates
      - ssh ubuntu@auth.insports.tv 'bash -s' < ./run.sh OTT-2535 docker-compose-stage.yaml

---
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 "/*"
##      - make auth-build
##      - 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/
##      - rsync -v -r -C build_auth/clients/* ubuntu@auth.insports.tv:/home/ubuntu/ott-auth/src/frontend/templates
##      - ssh ubuntu@auth.insports.tv 'bash -s' < ./run.sh OTT-2535 docker-compose-stage.yaml


---
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-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:
        from_secret: SSH_KEY_AUTH

    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" | 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
      - ssh ubuntu@auth.test.insports.tv 'bash -s' < ./run.sh OTT-2535-test docker-compose-test.yaml
