name: Build CI Docker Image

on:
  push:
    branches: [main]
    paths:
      - ".github/Dockerfile"
      - ".github/workflows/docker-ci-image.yml"
      - "e2e/docker-entrypoint.sh"
  workflow_dispatch:

permissions:
  contents: read
  packages: write

jobs:
  build-image:
    name: Build and push CI image
    runs-on: ubuntu-latest
    environment: Production
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          file: .github/Dockerfile
          push: true
          provenance: false
          tags: |
            ghcr.io/tinyhumansai/openhuman_ci:latest
            ghcr.io/tinyhumansai/openhuman_ci:rust-1.93.0
