name: 'create docker image on pull request and push to private registery'

on:
  pull_request:
    branches:
    - develop
  workflow_dispatch:

jobs:
  build-image:
    runs-on: self-hosted
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2

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

      -
        name: Login to private registery
        uses: docker/login-action@v2.0.0
        with:
          registry: ${{ secrets.REGISTRY_URL }}
          username: ${{ secrets.REGISTRY_USERNAME }}
          password: ${{ secrets.REGISTRY_PASSWORD }}

      -
        name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          tags: '${{ secrets.REGISTRY_URL }}/fallenbagel/jellyseerr:${{ github.sha }}'
          cache-from: 'type=registry,ref=${{ secrets.REGISTRY_URL }}/fallenbagel/jellyseerr:buildcache'
          cache-to: 'type=registry,ref=${{ secrets.REGISTRY_URL }}/fallenbagel/jellyseerr:buildcache,mode=max'
