name: Docker Commit

on:
  push:
    branches:
      - "*"
  pull_request:
    branches:
      - "*"
    tags-ignore:
      - "*"

jobs:
  # Alpine build.
  # WARNING: Deprecated, will be removed as it is not recommended
  #          for uWebSockets.js
  alpine:
    if: "!contains(github.event.head_commit.message, 'skip ci')"

    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        node:
          - '16'

    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000

    name: Tag & Test Alpine Commit (node:${{ matrix.node }})

    steps:
      - uses: actions/checkout@v3.0.2

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

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

      - name: Login to Quay
        uses: docker/login-action@v2
        with:
          registry: quay.io
          username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
          password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

      - name: Build and Push
        uses: docker/build-push-action@v3
        with:
          push: true
          context: .
          tags: quay.io/soketi/soketi:${{ github.sha }}-${{ matrix.node }}-alpine
          build-args: |
            VERSION=${{ matrix.node }}

  # Distroless build.
  distroless:
    if: "!contains(github.event.head_commit.message, 'skip ci')"

    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        node:
          - '16'

    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000

    name: Tag & Test Distroless Commit (node:${{ matrix.node }})

    steps:
      - uses: actions/checkout@v3.0.2

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

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

      - name: Login to Quay
        uses: docker/login-action@v2
        with:
          registry: quay.io
          username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
          password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

      - name: Build and Push
        uses: docker/build-push-action@v3
        with:
          push: true
          context: .
          tags: quay.io/soketi/soketi:${{ github.sha }}-${{ matrix.node }}-distroless
          file: Dockerfile.distroless
          build-args: |
            VERSION=${{ matrix.node }}

  # Stable Debian build.
  debian:
    if: "!contains(github.event.head_commit.message, 'skip ci')"

    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        node:
          - '16'

    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000

    name: Tag & Test Debian Commit (node:${{ matrix.node }})

    steps:
      - uses: actions/checkout@v3.0.2

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

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

      - name: Login to Quay
        uses: docker/login-action@v2
        with:
          registry: quay.io
          username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
          password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

      - name: Build and Push
        uses: docker/build-push-action@v3
        with:
          push: true
          context: .
          tags: quay.io/soketi/soketi:${{ github.sha }}-${{ matrix.node }}-debian
          file: Dockerfile.debian
          build-args: |
            VERSION=${{ matrix.node }}
