name: "*** Deploy Crawler to Dev Channel ***"

on:
  workflow_dispatch:
    inputs:
      channel:
        description: Crawler Channel
        type: choice
        required: true
        default: dev
        options: 
          - dev
          - dev-2

jobs:
  build_and_deploy_crawler:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
        with:
          driver-opts: network=host

      - name: Login to Registry
        uses: docker/login-action@v2
        with:
          registry: ${{ secrets.DEPLOY_REGISTRY }}
          username: ${{ secrets.DEPLOY_REGISTRY_API_TOKEN }}
          password: ${{ secrets.DEPLOY_REGISTRY_API_TOKEN }}

      - name: Build Image
        uses: docker/build-push-action@v3
        with:
          context: .
          push: true
          tags: ${{ secrets.DEPLOY_REGISTRY_PATH }}/webrecorder/browsertrix-crawler:${{ github.event.inputs.channel }}
          cache-from: type=gha,scope=backend
          cache-to: type=gha,scope=backend,mode=max
