name: Deploy Prod

on:
  pull_request:
    branches:
      - prod
    types: [closed]

jobs:
  build:
    name: Build
    runs-on: [ dev ]
    steps:
      - name: login
        run: docker login -u mathwave -p ${{ secrets.DOCKERHUB_PASSWORD }}
      - name: checkout
        uses: actions/checkout@v4
        with:
          ref: prod
      - name: build
        run: docker build -t mathwave/sprint-repo:platform .
  push:
    name: Push
    runs-on: [ dev ]
    needs: build
    steps:
      - name: push
        run: docker push mathwave/sprint-repo:platform
  deploy-prod:
    name: Deploy prod
    runs-on: [prod]
    needs: push
    steps:
      - name: login
        run: docker login -u mathwave -p ${{ secrets.DOCKERHUB_PASSWORD }}
      - name: checkout
        uses: actions/checkout@v4
        with:
            ref: prod
      - name: deploy
        env:
          PLATFORM_SECURITY_TOKEN: ${{ secrets.PLATFORM_SECURITY_TOKEN }}
          DB_PASSWORD_PROD: ${{ secrets.POSTGRES_PASSWORD_PROD }}
          MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY_PROD }}
          REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD_PROD }}
          RABBITMQ_PASSWORD: ${{ secrets.RABBITMQ_PASSWORD_PROD }}
          VK_SERVICE_TOKEN: ${{ secrets.VK_SERVICE_TOKEN }}
          YANDEX_SERVICE_TOKEN: ${{ secrets.YANDEX_SERVICE_TOKEN }}
        run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml platform
