name: Publish Scrypted Common

on:
  workflow_dispatch:
  release:
    types: [published]
  schedule:
    # publish the common base once a month.
    - cron:  '30 8 2 * *'

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    strategy:
      matrix:
        NODE_VERSION: ["18"]
        BUILDPACK_DEPS_BASE: ["bullseye"]
        FLAVOR: ["full", "lite", "thin"]
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2
      
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
        
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Login to Github Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image (scrypted-common)
        uses: docker/build-push-action@v2
        with:
          build-args: NODE_VERSION=${{ matrix.NODE_VERSION }}
          context: docker/
          file: docker/Dockerfile.${{ matrix.FLAVOR }}
          platforms: linux/amd64,linux/arm64,linux/armhf
          push: true
          tags: |
            koush/scrypted-common:${{ matrix.NODE_VERSION }}-${{ matrix.BUILDPACK_DEPS_BASE }}-${{ matrix.FLAVOR }}
#            ${{ matrix.NODE_VERSION == '16-bullseye' && 'koush/scrypted-common:latest' || '' }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
