name: Docker Image Microservice CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches:
      - 'main'
  workflow_dispatch:

env:
  DOCKER_TAG: dev

jobs:

  build-1:

    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build the docker image
        run: docker-compose -f docker-compose.yml -f docker-compose.ms.yml build user saas sys realtime

      - name: Docker login
        if: |
          github.event_name == 'push'
          && github.repository == 'go-saas/kit'
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: Push docker image
        if: |
          github.event_name == 'push'
          && github.repository == 'go-saas/kit'

        run: docker-compose -f docker-compose.yml -f docker-compose.ms.yml push user saas sys realtime

          
  build-2:

    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build the docker image
        run: docker-compose -f docker-compose.yml -f docker-compose.ms.yml build payment order product

      - name: Docker login
        if: |
          github.event_name == 'push'
          && github.repository == 'go-saas/kit'
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: Push docker image
        if: |
          github.event_name == 'push'
          && github.repository == 'go-saas/kit'

        run: docker-compose -f docker-compose.yml -f docker-compose.ms.yml push payment order product