name: "Run Build Test"
on:
  push:
    paths:
      - 'Dockerfile'
      - 'Dockerfile-*'
      - 'pyproject.toml'
      - 'poetry.lock'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: docker/setup-qemu-action@v3
    - uses: docker/setup-buildx-action@v3

    - name: Check Dockerfile
      run: |
        test -f Dockerfile-ce || cp -f Dockerfile Dockerfile-ce

    - name: Build CE Image
      uses: docker/build-push-action@v5
      with:
        context: .
        push: false
        file: Dockerfile-ce
        tags: jumpserver/core-ce:test
        platforms: linux/amd64
        build-args: |
          APT_MIRROR=http://deb.debian.org
          PIP_MIRROR=https://pypi.org/simple
          PIP_JMS_MIRROR=https://pypi.org/simple
        cache-from: type=gha
        cache-to: type=gha,mode=max

    - name: Prepare EE Image
      run: |
        sed -i 's@^FROM registry.fit2cloud.com@# FROM registry.fit2cloud.com@g' Dockerfile-ee
        sed -i 's@^COPY --from=build-xpack@# COPY --from=build-xpack@g' Dockerfile-ee

    - name: Build EE Image
      uses: docker/build-push-action@v5
      with:
        context: .
        push: false
        file: Dockerfile-ee
        tags: jumpserver/core-ee:test
        platforms: linux/amd64
        build-args: |
          APT_MIRROR=http://deb.debian.org
          PIP_MIRROR=https://pypi.org/simple
          PIP_JMS_MIRROR=https://pypi.org/simple
        cache-from: type=gha
        cache-to: type=gha,mode=max