name: Docker nightly build

on:
  schedule:
    - cron: '0 0 1 * *'

jobs:
  build_image:
    name: Build nodejs-rust:lts
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Setup QEMU
        uses: docker/setup-qemu-action@v1

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

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ secrets.GH_CONTAINER_UNAME }}
          password: ${{ secrets.GH_TOKEN }}

      - name: Build and push alpine
        uses: docker/build-push-action@v2
        with:
          file: alpine.Dockerfile
          platforms: linux/amd64
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine

      - name: Build and push debian
        uses: docker/build-push-action@v2
        with:
          file: debian.Dockerfile
          platforms: linux/amd64
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian

      - name: Build and push debian aarch64 cross
        uses: docker/build-push-action@v2
        with:
          file: debian-aarch64.Dockerfile
          platforms: linux/amd64
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64

      - name: Build and push debian with zig
        uses: docker/build-push-action@v2
        with:
          file: debian-zig.Dockerfile
          platforms: linux/amd64
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-zig

      - name: Build and push alpine with zig
        uses: docker/build-push-action@v2
        with:
          file: alpine-zig.Dockerfile
          platforms: linux/amd64
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig

  build_image_arm:
    name: Build Node.js arm images
    strategy:
      fail-fast: false
      matrix:
        version: ['14', '16', '18']
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Setup QEMU
        uses: docker/setup-qemu-action@v1

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

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ secrets.GH_CONTAINER_UNAME }}
          password: ${{ secrets.GH_TOKEN }}

      - name: Build and push armhf
        uses: docker/build-push-action@v2
        with:
          file: armhf.Dockerfile
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.version }}
          build-args: |
            NODE_VERSION=${{ matrix.version }}

      - name: Build and push aarch64
        uses: docker/build-push-action@v2
        with:
          file: aarch64.Dockerfile
          push: true
          tags: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.version }}
          build-args: |
            NODE_VERSION=${{ matrix.version }}