name: publish-images

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: self-hosted
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Login registry
        run: |
          echo "$REGISTRY_PASSWORD" | docker login cr.danosito.com -u "$REGISTRY_USER" --password-stdin
      - name: Build and push images
        env:
          IMAGE_TAG: ${{ github.sha }}
        run: |
          set -e
          docker build -f docker/api.Dockerfile -t cr.danosito.com/dan/catan-api:latest -t cr.danosito.com/dan/catan-api:$IMAGE_TAG .
          docker build -f docker/game.Dockerfile -t cr.danosito.com/dan/catan-game:latest -t cr.danosito.com/dan/catan-game:$IMAGE_TAG .
          docker build -f docker/ai.Dockerfile -t cr.danosito.com/dan/catan-ai:latest -t cr.danosito.com/dan/catan-ai:$IMAGE_TAG .
          docker build -f docker/analytics.Dockerfile -t cr.danosito.com/dan/catan-analytics:latest -t cr.danosito.com/dan/catan-analytics:$IMAGE_TAG .
          docker build -f docker/web.Dockerfile -t cr.danosito.com/dan/catan-web:latest -t cr.danosito.com/dan/catan-web:$IMAGE_TAG .
          docker push cr.danosito.com/dan/catan-api:latest
          docker push cr.danosito.com/dan/catan-api:$IMAGE_TAG
          docker push cr.danosito.com/dan/catan-game:latest
          docker push cr.danosito.com/dan/catan-game:$IMAGE_TAG
          docker push cr.danosito.com/dan/catan-ai:latest
          docker push cr.danosito.com/dan/catan-ai:$IMAGE_TAG
          docker push cr.danosito.com/dan/catan-analytics:latest
          docker push cr.danosito.com/dan/catan-analytics:$IMAGE_TAG
          docker push cr.danosito.com/dan/catan-web:latest
          docker push cr.danosito.com/dan/catan-web:$IMAGE_TAG
