From 8129be1ac5e57d9d69c3f4fb2d44b72a2b582167 Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 3 Oct 2025 18:26:33 +0000 Subject: [PATCH 01/10] Make container universal and use MAX nightly --- genai-cookbook/Dockerfile | 32 ++++++++++++++++++++++++++---- genai-cookbook/ecosystem.config.js | 7 +++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/genai-cookbook/Dockerfile b/genai-cookbook/Dockerfile index d79e8c5..c1c0bbc 100644 --- a/genai-cookbook/Dockerfile +++ b/genai-cookbook/Dockerfile @@ -1,8 +1,12 @@ -ARG GPU_TYPE=nvidia -FROM modular/max-${GPU_TYPE}-base +# ////////////////////////////////////////////////////////////////////// +# BASE ON UNIVERSAL MAX CONTAINER +FROM modular/max-full WORKDIR /app +# ////////////////////////////////////////////////////////////////////// +# UPDATE SYSTEM + RUN apt-get update && apt-get install -y \ curl \ build-essential \ @@ -10,9 +14,26 @@ RUN apt-get update && apt-get install -y \ wget \ && rm -rf /var/lib/apt/lists/* +# ////////////////////////////////////////////////////////////////////// +# USE NIGHTLY MAX + +RUN curl -LsSf https://astral.sh/uv/install.sh | sh + +ENV PATH="/root/.local/bin:${PATH}" + +RUN uv venv /app/.venv && \ + uv pip install \ + --python /app/.venv/bin/python \ + --index-url https://dl.modular.com/public/nightly/python/simple/ \ + --prerelease allow \ + modular + +# ////////////////////////////////////////////////////////////////////// +# INSTALL NODE & NPM PACKAGES + RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ - && apt-get install -y nodejs \ - && rm -rf /var/lib/apt/lists/* +&& apt-get install -y nodejs \ +&& rm -rf /var/lib/apt/lists/* RUN npm install -g pm2 wait-on@7.2.0 @@ -20,6 +41,9 @@ COPY package*.json ./ RUN npm install +# ////////////////////////////////////////////////////////////////////// +# BUILD WEB APP + COPY . /app RUN npm run build diff --git a/genai-cookbook/ecosystem.config.js b/genai-cookbook/ecosystem.config.js index da255dd..042f797 100644 --- a/genai-cookbook/ecosystem.config.js +++ b/genai-cookbook/ecosystem.config.js @@ -2,8 +2,11 @@ module.exports = { apps: [ { name: 'max-llm', - script: 'max', - args: `serve --model ${process.env.MAX_MODEL || 'google/gemma-3-27b-it'} --trust-remote-code`, + script: '/bin/bash', + args: [ + '-c', + 'source /app/.venv/bin/activate && exec max serve --model "${MAX_MODEL:-google/gemma-3-27b-it}" --trust-remote-code', + ], interpreter: 'none', autorestart: true, watch: false, From b3a7c329d97d3e40369b0b03af38bbbdff62a8b9 Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 3 Oct 2025 18:30:16 +0000 Subject: [PATCH 02/10] Update readme --- genai-cookbook/README.md | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/genai-cookbook/README.md b/genai-cookbook/README.md index 97b3368..8891e7b 100644 --- a/genai-cookbook/README.md +++ b/genai-cookbook/README.md @@ -175,27 +175,21 @@ To use the cookbook with MAX: ## Running with Docker -The GenAI Cookbook can be run entirely within a Docker container, including the MAX model server and web application. +The GenAI Cookbook can be run entirely within a Docker container, including the MAX model server and web application. The container uses the universal MAX image with the nightly build, supporting both NVIDIA and AMD GPUs. ### Building the Container -The Dockerfile defaults to NVIDIA GPUs: +Build the universal container image: ```bash -docker build --ulimit nofile=65535:65535 -t max-recipes:latest . -``` - -Use the `--build-arg` flag to specify AMD: - -```bash -docker build --build-arg GPU_TYPE=amd --ulimit nofile=65535:65535 -t max-recipes:latest . +docker build --ulimit nofile=65535:65535 -t max-cookbook:latest . ``` **Note:** The `--ulimit nofile=65535:65535` flag increases the file descriptor limit, which is needed for Next.js builds. ### Running the Container -#### With NVIDIA GPUs +#### NVIDIA GPU ```bash docker run --gpus all \ @@ -205,10 +199,10 @@ docker run --gpus all \ --env "MAX_MODEL=google/gemma-3-27b-it" \ -p 8000:8000 \ -p 3000:3000 \ - max-recipes:latest + max-cookbook:latest ``` -#### With AMD GPUs +#### AMD GPU ```bash docker run \ @@ -222,7 +216,7 @@ docker run \ --env "MAX_MODEL=google/gemma-3-27b-it" \ -p 8000:8000 \ -p 3000:3000 \ - max-recipes:latest + max-cookbook:latest ``` **Configuration:** From 263a0e57c422bfe9a02949186d8c949e48527bd3 Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 3 Oct 2025 19:56:29 +0000 Subject: [PATCH 03/10] Support legacy MAX --- genai-cookbook/Dockerfile | 14 -------------- genai-cookbook/ecosystem.config.js | 6 +++--- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/genai-cookbook/Dockerfile b/genai-cookbook/Dockerfile index c1c0bbc..7602e98 100644 --- a/genai-cookbook/Dockerfile +++ b/genai-cookbook/Dockerfile @@ -14,20 +14,6 @@ RUN apt-get update && apt-get install -y \ wget \ && rm -rf /var/lib/apt/lists/* -# ////////////////////////////////////////////////////////////////////// -# USE NIGHTLY MAX - -RUN curl -LsSf https://astral.sh/uv/install.sh | sh - -ENV PATH="/root/.local/bin:${PATH}" - -RUN uv venv /app/.venv && \ - uv pip install \ - --python /app/.venv/bin/python \ - --index-url https://dl.modular.com/public/nightly/python/simple/ \ - --prerelease allow \ - modular - # ////////////////////////////////////////////////////////////////////// # INSTALL NODE & NPM PACKAGES diff --git a/genai-cookbook/ecosystem.config.js b/genai-cookbook/ecosystem.config.js index 042f797..20a48b7 100644 --- a/genai-cookbook/ecosystem.config.js +++ b/genai-cookbook/ecosystem.config.js @@ -5,7 +5,7 @@ module.exports = { script: '/bin/bash', args: [ '-c', - 'source /app/.venv/bin/activate && exec max serve --model "${MAX_MODEL:-google/gemma-3-27b-it}" --trust-remote-code', + 'exec python -m max.entrypoints.pipelines serve --model-path "${MAX_MODEL:-google/gemma-3-27b-it}" --trust-remote-code', ], interpreter: 'none', autorestart: true, @@ -16,13 +16,13 @@ module.exports = { MAX_SERVE_PORT: 8000, NODE_ENV: 'production', }, - }, + }, { name: 'web-app', script: '/bin/bash', args: [ '-c', - 'wait-on http-get://0.0.0.0:8000/health -t 600000 -i 2000 && npm start', + 'wait-on http-get://0.0.0.0:8000/v1/health -t 600000 -i 2000 && npm start', ], interpreter: 'none', autorestart: true, From 92d0827a936c3b440c8f1b557587eb70e00070aa Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 3 Oct 2025 20:16:16 +0000 Subject: [PATCH 04/10] Update README --- genai-cookbook/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genai-cookbook/README.md b/genai-cookbook/README.md index 8891e7b..39be335 100644 --- a/genai-cookbook/README.md +++ b/genai-cookbook/README.md @@ -196,7 +196,7 @@ docker run --gpus all \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_HUB_ENABLE_HF_TRANSFER=1" \ --env "HF_TOKEN=your-huggingface-token" \ - --env "MAX_MODEL=google/gemma-3-27b-it" \ + --env "MAX_MODEL=mistral-community/pixtral-12b" \ -p 8000:8000 \ -p 3000:3000 \ max-cookbook:latest @@ -213,7 +213,7 @@ docker run \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_HUB_ENABLE_HF_TRANSFER=1" \ --env "HF_TOKEN=your-huggingface-token" \ - --env "MAX_MODEL=google/gemma-3-27b-it" \ + --env "MAX_MODEL=mistral-community/pixtral-12b" \ -p 8000:8000 \ -p 3000:3000 \ max-cookbook:latest From 7c7228f71790be7730f4be80628ec98b857c47ae Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 6 Oct 2025 15:05:25 +0000 Subject: [PATCH 05/10] Remove unnecessary apt-get from Dockerfile --- genai-cookbook/Dockerfile | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/genai-cookbook/Dockerfile b/genai-cookbook/Dockerfile index 7602e98..ce03085 100644 --- a/genai-cookbook/Dockerfile +++ b/genai-cookbook/Dockerfile @@ -1,25 +1,20 @@ # ////////////////////////////////////////////////////////////////////// # BASE ON UNIVERSAL MAX CONTAINER -FROM modular/max-full +FROM modular/max-full:25.7.0.dev2025100305 +# FROM modular/max-nvidia-base:nightly +# FROM modular/max-nvidia-base:25.6.0 WORKDIR /app # ////////////////////////////////////////////////////////////////////// -# UPDATE SYSTEM +# INSTALL NODE -RUN apt-get update && apt-get install -y \ - curl \ - build-essential \ - git \ - wget \ +RUN wget -qO- https://deb.nodesource.com/setup_18.x | bash - \ + && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # ////////////////////////////////////////////////////////////////////// -# INSTALL NODE & NPM PACKAGES - -RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ -&& apt-get install -y nodejs \ -&& rm -rf /var/lib/apt/lists/* +# INSTALL NPM PACKAGES RUN npm install -g pm2 wait-on@7.2.0 From 4483a425f48da22000b00027e05fb1943fbd2fec Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 6 Oct 2025 15:45:03 +0000 Subject: [PATCH 06/10] Fix bug in .sample.env file --- genai-cookbook/.sample.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai-cookbook/.sample.env b/genai-cookbook/.sample.env index dbcec6f..a7fdebc 100644 --- a/genai-cookbook/.sample.env +++ b/genai-cookbook/.sample.env @@ -2,6 +2,6 @@ COOKBOOK_ENDPOINTS='[ { "id": "max", "baseUrl": "http://127.0.0.1:8000/v1", - "apiKey": "EMPTY", + "apiKey": "EMPTY" } ]' From 88abfe605e32b9f9e4388e82dda8f487aedee2d4 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 6 Oct 2025 17:13:17 +0000 Subject: [PATCH 07/10] Validated max-amd:nightly works as base container --- genai-cookbook/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/genai-cookbook/Dockerfile b/genai-cookbook/Dockerfile index ce03085..7cfa729 100644 --- a/genai-cookbook/Dockerfile +++ b/genai-cookbook/Dockerfile @@ -1,15 +1,15 @@ # ////////////////////////////////////////////////////////////////////// # BASE ON UNIVERSAL MAX CONTAINER -FROM modular/max-full:25.7.0.dev2025100305 -# FROM modular/max-nvidia-base:nightly -# FROM modular/max-nvidia-base:25.6.0 +# FROM modular/max-full:25.7.0.dev2025100305 +# FROM modular/max-nvidia-full:nightly +FROM modular/max-amd:nightly WORKDIR /app # ////////////////////////////////////////////////////////////////////// # INSTALL NODE -RUN wget -qO- https://deb.nodesource.com/setup_18.x | bash - \ +RUN wget -qO- https://deb.nodesource.com/setup_22.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* From 341ebf2307f1e8f9feb4dc17550bb01e576a6da7 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 6 Oct 2025 18:54:16 +0000 Subject: [PATCH 08/10] Validated max-nvidia-full:nightly works as base container --- genai-cookbook/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genai-cookbook/Dockerfile b/genai-cookbook/Dockerfile index 7cfa729..40341bd 100644 --- a/genai-cookbook/Dockerfile +++ b/genai-cookbook/Dockerfile @@ -1,8 +1,8 @@ # ////////////////////////////////////////////////////////////////////// # BASE ON UNIVERSAL MAX CONTAINER # FROM modular/max-full:25.7.0.dev2025100305 -# FROM modular/max-nvidia-full:nightly -FROM modular/max-amd:nightly +FROM modular/max-nvidia-full:nightly +# FROM modular/max-amd:nightly WORKDIR /app From 0e65941ec0903a75374f717d5eb42bb6d7bbed3b Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 6 Oct 2025 19:17:42 +0000 Subject: [PATCH 09/10] Refactor Dockerfile to support multiple base images --- genai-cookbook/Dockerfile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/genai-cookbook/Dockerfile b/genai-cookbook/Dockerfile index 40341bd..2914139 100644 --- a/genai-cookbook/Dockerfile +++ b/genai-cookbook/Dockerfile @@ -1,8 +1,18 @@ # ////////////////////////////////////////////////////////////////////// # BASE ON UNIVERSAL MAX CONTAINER -# FROM modular/max-full:25.7.0.dev2025100305 -FROM modular/max-nvidia-full:nightly -# FROM modular/max-amd:nightly +# Use MAX_VARIANT build arg to select base image: +# - omitted/default → max-full:nightly +# - MAX_VARIANT=amd → max-amd-full:nightly +# - MAX_VARIANT=nvidia → max-nvidia-full:nightly + +ARG MAX_GPU=universal +ARG MAX_TAG=latest + +FROM modular/max-full:${MAX_TAG} AS base-universal +FROM modular/max-amd:${MAX_TAG} AS base-amd +FROM modular/max-nvidia-full:${MAX_TAG} AS base-nvidia + +FROM base-${MAX_GPU} AS final WORKDIR /app From 7bac93b0497442a5b325e213b879b53c82812b3d Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 6 Oct 2025 19:17:49 +0000 Subject: [PATCH 10/10] Update README with build argument details --- genai-cookbook/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/genai-cookbook/README.md b/genai-cookbook/README.md index 39be335..63435a3 100644 --- a/genai-cookbook/README.md +++ b/genai-cookbook/README.md @@ -187,6 +187,32 @@ docker build --ulimit nofile=65535:65535 -t max-cookbook:latest . **Note:** The `--ulimit nofile=65535:65535` flag increases the file descriptor limit, which is needed for Next.js builds. +#### Build Arguments + +You can customize the Docker build using these arguments to reduce container size: + +- **MAX_GPU**: Selects the base image (default: `universal`) + - `universal` → `modular/max-full` (larger, supports all GPU types) + - `amd` → `modular/max-amd` (smaller, AMD-specific) + - `nvidia` → `modular/max-nvidia-full` (smaller, NVIDIA-specific) + +- **MAX_TAG**: Selects the image version (default: `latest`) + - `latest` → Latest stable release + - `nightly` → Nightly development builds + - Specific versions (e.g., `25.7.0`) + +**Examples:** + +Build smaller AMD-specific container: +```bash +docker build --build-arg MAX_GPU=amd --ulimit nofile=65535:65535 -t max-cookbook:amd . +``` + +Build smaller NVIDIA-specific container with nightly builds: +```bash +docker build --build-arg MAX_GPU=nvidia --build-arg MAX_TAG=nightly --ulimit nofile=65535:65535 -t max-cookbook:nvidia-nightly . +``` + ### Running the Container #### NVIDIA GPU