name: Build and Push Docker Images
on:
  push:
    branches:
      - main
    paths:
      - 'apps/**'

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: frankchine
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and push Worker Image
        uses: docker/build-push-action@v4
        with:
          context: ./apps/worker
          push: true
          tags: frankchine/geocrop-worker:latest, frankchine/geocrop-worker:${{ github.sha }}

      - name: Build and push API Image
        uses: docker/build-push-action@v4
        with:
          context: ./apps/api
          push: true
          tags: frankchine/geocrop-api:latest, frankchine/geocrop-api:${{ github.sha }}

      - name: Build and push Web Image
        uses: docker/build-push-action@v4
        with:
          context: ./apps/web
          push: true
          tags: frankchine/geocrop-web:latest, frankchine/geocrop-web:${{ github.sha }}
