name: Build and Push Development Docker Images

on:
  workflow_dispatch:
  schedule:
    - cron: "0 0 * * *"

jobs:
  build-dev-x86:
    if: ${{ github.repository == 'sgl-project/sglang' }}
    runs-on: nvidia
    strategy:
      matrix:
        variant:
          - version: 12.9.1
            type: all
            tag: dev-x86
    steps:
      - name: Delete huge unnecessary tools folder
        run: rm -rf /opt/hostedtoolcache

      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Free disk space
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: true
          docker-images: true
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          swap-storage: true

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

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and Push Dev Image (x86)
        run: |
          docker buildx build --platform linux/amd64 --push -f docker/Dockerfile --build-arg CUDA_VERSION=${{ matrix.variant.version }} --build-arg BUILD_TYPE=${{ matrix.variant.type }} --build-arg CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) -t lmsysorg/sglang:${{ matrix.variant.tag }} --no-cache .

  build-dev-arm:
    if: ${{ github.repository == 'sgl-project/sglang' }}
    runs-on: sgl-kernel-release-node-arm
    strategy:
      matrix:
        variant:
          - version: 12.9.1
            type: blackwell_aarch64
            tag: dev-arm64
    steps:
      - name: Delete huge unnecessary tools folder
        run: rm -rf /opt/hostedtoolcache

      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Free disk space
        uses: jlumbroso/free-disk-space@main
        with:
          tool-cache: true
          docker-images: true
          android: true
          dotnet: true
          haskell: true
          large-packages: true
          swap-storage: true

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

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and Push Blackwell Image (ARM)
        run: |
          docker buildx build --platform linux/arm64 --push -f docker/Dockerfile --build-arg CUDA_VERSION=${{ matrix.variant.version }} --build-arg BUILD_TYPE=${{ matrix.variant.type }} --build-arg CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) -t lmsysorg/sglang:${{ matrix.variant.tag }} --no-cache .

  create-manifests:
    runs-on: ubuntu-22.04
    needs: [build-dev-x86, build-dev-arm]
    if: ${{ github.repository == 'sgl-project/sglang' }}
    strategy:
      matrix:
        variant:
          - tag: dev
            x86_tag: dev-x86
            arm64_tag: dev-arm64
    steps:
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - run: |
          docker buildx imagetools create \
            -t lmsysorg/sglang:${{ matrix.variant.tag }} \
            lmsysorg/sglang:${{ matrix.variant.x86_tag }} \
            lmsysorg/sglang:${{ matrix.variant.arm64_tag }}
