name: build-jan-server
on:
  workflow_call:
    inputs:
      dockerfile_path:
        required: false
        type: string
        default: './Dockerfile'
      docker_image_tag:
        required: true
        type: string
        default: 'ghcr.io/janhq/jan-server:dev-latest'

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      REGISTRY: ghcr.io
      IMAGE_NAME: janhq/jan-server
    permissions:
      packages: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Log in to the Container registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v3
        with:
          context: .
          file: ${{ inputs.dockerfile_path }}
          push: true
          tags: ${{ inputs.docker_image_tag }}