name: Docker Build

on:
  push:
    branches:
      - "**"
  pull_request:

jobs:
  docker:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Log in to registry
        if: env.REGISTRY != '' && env.REGISTRY_USER != '' && env.REGISTRY_PASSWORD != ''
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ env.REGISTRY_USER }}
          password: ${{ env.REGISTRY_PASSWORD }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v6
        with:
          context: .
          push: ${{ env.REGISTRY != '' }}
          tags: ${{ env.REGISTRY }}/vitrify-me:${{ github.sha }}

    env:
      REGISTRY: ${{ secrets.REGISTRY }}
      REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
      REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
