[CI] Add output_tag input to the Patch Docker Image workflow (#34253)
This commit is contained in:
@@ -4,15 +4,18 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
pr_numbers:
|
pr_numbers:
|
||||||
description: "Comma-separated PR numbers to apply (e.g. 18962,19010)"
|
description: "Comma-separated PR numbers to apply (e.g. 18962,19010). Empty = fast-forward the base image to latest main."
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
image_tag:
|
image_tag:
|
||||||
description: "Base image tag to patch (e.g. dev-x86, dev-x86-cu13)"
|
description: "Base image tag to patch (e.g. dev, dev-cu13, dev-cu12)"
|
||||||
|
required: true
|
||||||
|
output_tag:
|
||||||
|
description: "Tag to publish as. Must start with 'patch-' (e.g. patch-myfeature)."
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: patch-docker-${{ inputs.image_tag }}
|
group: patch-docker-${{ inputs.image_tag }}-${{ inputs.output_tag }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -20,6 +23,40 @@ jobs:
|
|||||||
if: github.repository == 'sgl-project/sglang'
|
if: github.repository == 'sgl-project/sglang'
|
||||||
runs-on: x64-docker-build-node
|
runs-on: x64-docker-build-node
|
||||||
steps:
|
steps:
|
||||||
|
- name: Resolve and validate image tags
|
||||||
|
env:
|
||||||
|
# Inject via env so a crafted input cannot break out of the script.
|
||||||
|
IMAGE_TAG: ${{ inputs.image_tag }}
|
||||||
|
OUTPUT_TAG: ${{ inputs.output_tag }}
|
||||||
|
run: |
|
||||||
|
# Whole-string checks. A '^...$' regex anchors per LINE, so a
|
||||||
|
# multi-line value would pass and then inject extra GITHUB_ENV lines.
|
||||||
|
validate_tag() {
|
||||||
|
case "$2" in
|
||||||
|
""|[!a-zA-Z0-9_]*|*[!a-zA-Z0-9._-]*)
|
||||||
|
echo "::error::${1} is not a valid Docker tag"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
validate_tag image_tag "${IMAGE_TAG}"
|
||||||
|
validate_tag output_tag "${OUTPUT_TAG}"
|
||||||
|
|
||||||
|
# Released tags belong to release-docker*.yml, which builds them as
|
||||||
|
# multi-arch manifests. This job is x64-only, so it publishes under a
|
||||||
|
# prefix those builders never emit rather than denylisting their
|
||||||
|
# current names, which would rot as the release tag scheme changes.
|
||||||
|
case "${OUTPUT_TAG}" in
|
||||||
|
patch-?*) ;;
|
||||||
|
*)
|
||||||
|
echo "::error::output_tag must start with 'patch-' (e.g. patch-myfeature)"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "BASE_IMAGE=lmsysorg/sglang:${IMAGE_TAG}" >> "$GITHUB_ENV"
|
||||||
|
echo "OUT_IMAGE=lmsysorg/sglang:${OUTPUT_TAG}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Cleanup workspace (remove root-owned files from prior runs)
|
- name: Cleanup workspace (remove root-owned files from prior runs)
|
||||||
run: sudo rm -rf "$GITHUB_WORKSPACE"/* || true
|
run: sudo rm -rf "$GITHUB_WORKSPACE"/* || true
|
||||||
|
|
||||||
@@ -36,24 +73,28 @@ jobs:
|
|||||||
|
|
||||||
- name: Pull base image and extract commit
|
- name: Pull base image and extract commit
|
||||||
run: |
|
run: |
|
||||||
IMAGE="lmsysorg/sglang:${{ inputs.image_tag }}"
|
docker pull "${BASE_IMAGE}"
|
||||||
docker pull "${IMAGE}"
|
if BASE_SHA=$(docker run --rm "${BASE_IMAGE}" git -C /sgl-workspace/sglang rev-parse HEAD 2>/dev/null); then
|
||||||
if BASE_SHA=$(docker run --rm "${IMAGE}" git -C /sgl-workspace/sglang rev-parse HEAD 2>/dev/null); then
|
|
||||||
echo "Image built from commit: ${BASE_SHA}"
|
echo "Image built from commit: ${BASE_SHA}"
|
||||||
else
|
else
|
||||||
BASE_SHA=""
|
BASE_SHA=""
|
||||||
echo "::warning::Image has no .git directory — cannot extract base commit"
|
echo "::warning::Image has no .git directory - cannot extract base commit"
|
||||||
fi
|
fi
|
||||||
echo "BASE_SHA=${BASE_SHA}" >> "$GITHUB_ENV"
|
echo "BASE_SHA=${BASE_SHA}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Generate patches
|
- name: Generate patches
|
||||||
|
env:
|
||||||
|
PR_NUMBERS: ${{ inputs.pr_numbers }}
|
||||||
run: |
|
run: |
|
||||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||||
git fetch origin main
|
git fetch origin main
|
||||||
|
# Fixed path on a persistent runner: drop patches left by prior runs
|
||||||
|
# so they cannot be picked up by this run's COPY *.patch.
|
||||||
|
rm -rf /tmp/patch-ctx
|
||||||
mkdir -p /tmp/patch-ctx
|
mkdir -p /tmp/patch-ctx
|
||||||
|
|
||||||
if [ -n "${{ inputs.pr_numbers }}" ]; then
|
if [ -n "${PR_NUMBERS}" ]; then
|
||||||
IFS=',' read -ra PRS <<< "${{ inputs.pr_numbers }}"
|
IFS=',' read -ra PRS <<< "${PR_NUMBERS}"
|
||||||
for pr in "${PRS[@]}"; do
|
for pr in "${PRS[@]}"; do
|
||||||
pr=$(echo "${pr}" | xargs)
|
pr=$(echo "${pr}" | xargs)
|
||||||
echo "Fetching PR #${pr}"
|
echo "Fetching PR #${pr}"
|
||||||
@@ -64,26 +105,23 @@ jobs:
|
|||||||
echo " PR #${pr}: $(wc -l < /tmp/patch-ctx/${pr}.patch) lines"
|
echo " PR #${pr}: $(wc -l < /tmp/patch-ctx/${pr}.patch) lines"
|
||||||
done
|
done
|
||||||
elif [ -n "${BASE_SHA}" ]; then
|
elif [ -n "${BASE_SHA}" ]; then
|
||||||
echo "Generating diff: image ${BASE_SHA} → latest main"
|
echo "Generating diff: image ${BASE_SHA} -> latest main"
|
||||||
git fetch origin "${BASE_SHA}"
|
git fetch origin "${BASE_SHA}"
|
||||||
git diff "${BASE_SHA}..origin/main" > /tmp/patch-ctx/main.patch
|
git diff "${BASE_SHA}..origin/main" > /tmp/patch-ctx/main.patch
|
||||||
echo " main: $(wc -l < /tmp/patch-ctx/main.patch) lines"
|
echo " main: $(wc -l < /tmp/patch-ctx/main.patch) lines"
|
||||||
else
|
else
|
||||||
echo "::error::No PR numbers specified and image has no .git — cannot generate diff against main"
|
echo "::error::No PR numbers specified and image has no .git - cannot generate diff against main"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TOTAL=$(cat /tmp/patch-ctx/*.patch | wc -l)
|
TOTAL=$(cat /tmp/patch-ctx/*.patch | wc -l)
|
||||||
if [ "${TOTAL}" -eq 0 ]; then
|
if [ "${TOTAL}" -eq 0 ]; then
|
||||||
echo "::warning::All patches are empty — image is already up to date"
|
echo "::error::All patches are empty - nothing to apply on top of ${BASE_IMAGE}"
|
||||||
echo "SKIP_BUILD=true" >> "$GITHUB_ENV"
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Build patched image
|
- name: Build patched image
|
||||||
if: env.SKIP_BUILD != 'true'
|
|
||||||
run: |
|
run: |
|
||||||
IMAGE="lmsysorg/sglang:${{ inputs.image_tag }}"
|
|
||||||
|
|
||||||
cat <<'DOCKERFILE' > /tmp/patch-ctx/Dockerfile
|
cat <<'DOCKERFILE' > /tmp/patch-ctx/Dockerfile
|
||||||
ARG BASE_IMAGE
|
ARG BASE_IMAGE
|
||||||
FROM ${BASE_IMAGE}
|
FROM ${BASE_IMAGE}
|
||||||
@@ -103,16 +141,25 @@ jobs:
|
|||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
--no-cache \
|
--no-cache \
|
||||||
--build-arg BASE_IMAGE="${IMAGE}" \
|
--build-arg BASE_IMAGE="${BASE_IMAGE}" \
|
||||||
-t "${IMAGE}" \
|
-t "${OUT_IMAGE}" \
|
||||||
/tmp/patch-ctx/
|
/tmp/patch-ctx/
|
||||||
|
|
||||||
- name: Push patched image
|
- name: Push patched image
|
||||||
if: env.SKIP_BUILD != 'true'
|
env:
|
||||||
|
PR_NUMBERS: ${{ inputs.pr_numbers }}
|
||||||
run: |
|
run: |
|
||||||
IMAGE="lmsysorg/sglang:${{ inputs.image_tag }}"
|
docker push "${OUT_IMAGE}"
|
||||||
docker push "${IMAGE}"
|
|
||||||
|
|
||||||
echo "### Patched \`${IMAGE}\`" >> "$GITHUB_STEP_SUMMARY"
|
if [ -n "${PR_NUMBERS}" ]; then
|
||||||
echo "- **Base commit:** \`${BASE_SHA:-unknown (no .git)}\`" >> "$GITHUB_STEP_SUMMARY"
|
SOURCE="PRs: ${PR_NUMBERS}"
|
||||||
echo "- **Source:** ${{ inputs.pr_numbers && format('PRs: {0}', inputs.pr_numbers) || 'latest main' }}" >> "$GITHUB_STEP_SUMMARY"
|
else
|
||||||
|
SOURCE="latest main"
|
||||||
|
fi
|
||||||
|
{
|
||||||
|
echo "### Patched \`${OUT_IMAGE}\`"
|
||||||
|
echo "- **Base image:** \`${BASE_IMAGE}\`"
|
||||||
|
echo "- **Base commit:** \`${BASE_SHA:-unknown (no .git)}\`"
|
||||||
|
echo "- **Source:** ${SOURCE}"
|
||||||
|
echo "- **Platform:** \`linux/amd64\` only - patched on an x64 runner, so the base image's multi-arch manifest is not carried over"
|
||||||
|
} >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
|||||||
Reference in New Issue
Block a user