name: Build nightly container image of latest code

on:
  schedule:
    - cron: '30 7 * * *'

permissions:
  contents: read

jobs:
  nightly-build:
    name: Build image
    runs-on: ubuntu-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
        with:
            disable-sudo-and-containers: false
            egress-policy: block
            allowed-endpoints: >
              github.com:443
              registry-1.docker.io:443
              production.cloudflare.docker.com:443
              auth.docker.io:443
              azure.archive.ubuntu.com:80
              pypi.org:443
              files.pythonhosted.org:443
              wheels.vllm.ai:443
              release-assets.githubusercontent.com:443
              wrapdb.mesonbuild.com:443
              nvcr.io:443
              layers.nvcr.io:443
              archive.ubuntu.com:80
              security.ubuntu.com:80
              astral.sh:443

      - name: Login to DockerHub
        uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
        with:
          username: ${{ vars.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

      - name: Checkout code
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          # for setuptools-scm
          fetch-depth: 0

      - name: Free disk space
        uses: ./.github/actions/free-disk-space

      - name: Setup Python 3.13
        uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
        with:
          python-version: "3.13"

      - name: Get the current date
        run: |
          echo "NOW=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"

      - name: Build lmcache/vllm-openai container image
        run: |
          docker build \
          --build-arg CUDA_VERSION=12.8 --build-arg UBUNTU_VERSION=24.04 \
          --target image-build \
          --tag lmcache/vllm-openai:latest-nightly --tag lmcache/vllm-openai:nightly-${{ env.NOW }} \
          --file docker/Dockerfile .

      - name: Push lmcache/vllm-openai container image to DockerHub
        run: |
          docker push lmcache/vllm-openai:latest-nightly
          docker push lmcache/vllm-openai:nightly-${{ env.NOW }}

      - name: Build lmcache/standalone container image
        run: |
          docker build \
          --build-arg CUDA_VERSION=12.8 --build-arg UBUNTU_VERSION=24.04 \
          --target lmcache-final \
          --tag lmcache/standalone:nightly --tag lmcache/standalone:nightly-${{ env.NOW }} \
          --file docker/Dockerfile.standalone .

      - name: Push lmcache/standalone container image to DockerHub
        run: |
          docker push lmcache/standalone:nightly
          docker push lmcache/standalone:nightly-${{ env.NOW }}
