Give me feedback on this github action. What can be improved? [code]
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Give me feedback on this github action. What can be improved?
name: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
vllm_tag:
description: 'vLLM version to use. Must be the name of a tag in https://github.com/vllm-project/vllm'
required: true
default: 'v0.8.2'
image_tag:
description: 'Tag for the resulting Docker image. Normally, the vLLM tag will be used, but this can be overridden. For releases, an override is not allowed. Please note that for the arm64 version, a suffix "-arm" will be appended to the tag.'
required: false
default: ''
push_image:
description: 'Push Docker image to registry'
type: boolean
required: false
default: false
is_release:
description: 'Perform a release. I.e., push to the "intrafind" section instead of the "dev" section of the registry. Requires that this action is triggered on a Git tag.'
type: boolean
required: false
default: false
jobs:
build-and-push:
runs-on: ubuntu-24.04
permissions:
contents: write
env:
BUILD_TAG: ${{ github.run_id }}
steps:
- name: Display parameters
run: |
echo "Current workflow commit: ${{ github.sha }}"
echo "vLLM tag: ${{ github.event.inputs.vllm_tag }}"
echo "Image tag: ${{ github.event.inputs.image_tag }}"
echo "Push image: ${{ github.event.inputs.push_image }}"
echo "Is release: ${{ github.event.inputs.is_release }}"
- name: Releases must have a Git tag
if: ${{ github.event.inputs.is_release == 'true' && !startsWith(github.ref, 'refs/tags/') }}
run: |
echo "Error: When release is requested, the commit must have a Git tag."
exit 1
- name: Releases must not override the Docker tag
if: ${{ github.event.inputs.is_release == 'true' && github.event.inputs.image_tag != '' }}
run: |
echo "Error: When release is requested, the image tag must not be overridden, but it has been set to '${{ github.event.inputs.image_tag }}'."
exit 1
- name: Determine destination and tag for resulting Docker image
run: |
# tag
if [ -z "${{ github.event.inputs.image_tag }}" ]; then
echo "IMAGE_TAG=${{ github.event.inputs.vllm_tag }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.event.inputs.image_tag }}" >> $GITHUB_ENV
fi
# destination
REPO=${{ github.event.inputs.is_release == 'true' && 'intrafind' || 'dev' }}
DESTINATION=${{ vars.IF_REGISTRY }}/${REPO}/vllm-cpu
echo "DESTINATION=$DESTINATION"
echo "DESTINATION=$DESTINATION" >> $GITHUB_ENV
- name: Determine path of Dockerfiles based on vLLM version
run: |
# Set Dockerfile path according to vLLM version layout
VER=${{ github.event.inputs.vllm_tag }}
if [ "$(printf '%s\n' "v0.8.2" "$VER" | sort -V | head -n1)" != "$VER" ]; then
echo "DOCKERFILE_PATH=vllm/docker/Dockerfile" >> $GITHUB_ENV
else
echo "DOCKERFILE_PATH=vllm/Dockerfile" >> $GITHUB_ENV
fi
- name: Log in to Docker Registry for pushing the image
uses: docker/login-action@v3
if: ${{ github.event.inputs.push_image == 'true' }}
with:
username: ${{ secrets.IF_REGISTRY_USER }}
password: ${{ secrets.IF_REGISTRY_PASSWORD }}
registry: ${{ vars.IF_REGISTRY }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout vLLM
uses: actions/checkout@v4
with:
repository: vllm-project/vllm
ref: ${{ github.event.inputs.vllm_tag }}
path: vllm
- name: Modify CMake files to fix arm64 build
run: |
# Replace the condition that checks for MacOS with a constant TRUE
# Otherwise the build will fail with "unrecognized command-line option ‘-mavx2’" because it tries to make use of the AVX2 instruction set
#
# Replace:
# if (MACOSX_FOUND AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
# set(APPLE_SILICON_FOUND TRUE)
# with:
# if (TRUE AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"))
# set(APPLE_SILICON_FOUND TRUE)
#
sed -i 's/if (MACOSX_FOUND AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")/if (TRUE AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"))/g' vllm/cmake/cpu_extension.cmake
# Show the changed part to make it possible to validate it
cat vllm/cmake/cpu_extension.cmake -n | grep "set(APPLE_SILICON_FOUND TRUE)" -C 10
- name: Build and Push Docker Image for amd64
uses: docker/build-push-action@v6
with:
context: vllm
file: ${{ env.DOCKERFILE_PATH }}.cpu
platforms: linux/amd64
push: ${{ github.event.inputs.push_image == 'true' }}
tags: |
${{ env.DESTINATION }}:${{ env.IMAGE_TAG }}
labels: |
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.description=vLLM Docker Image for CPUs
org.opencontainers.image.vendor=IntraFind Software AG
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ github.ref }}
com.intrafind.vllmcpu.vllm.tag=${{ github.event.inputs.vllm_tag }}
- name: Build and Push Docker Image for arm64
uses: docker/build-push-action@v6
with:
context: vllm
file: ${{ env.DOCKERFILE_PATH }}.arm
platforms: linux/arm64
push: ${{ github.event.inputs.push_image == 'true' }}
tags: |
${{ env.DESTINATION }}:${{ env.IMAGE_TAG }}-arm
build-args: |
CMAKE_VERBOSE_MAKEFILE=ON
labels: |
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.description=vLLM Docker Image for CPUs
org.opencontainers.image.vendor=IntraFind Software AG
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ github.ref }}
com.intrafind.vllmcpu.vllm.tag=${{ github.event.inputs.vllm_tag }}
This is a well-structured and relatively comprehensive GitHub Action for building and pushing Docker images. Here's a breakdown of potential improvements, focusing on clarity, efficiency, and best practices:
1. Input Validation and Error Handling:
github.event.inputs.is_release == 'true'. GitHub Actions input types are usually handled as boolean so change your conditionals to github.event.inputs.is_release == truevllm-project/vllm repository and verify that the input tag exists. This prevents errors down the line. You can do this with the GitHub API:
- name: Validate vLLM tag
run: |
TAG=${{ github.event.inputs.vllm_tag }}
TAG_EXISTS=$(curl -s -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/vllm-project/vllm/git/refs/tags/${TAG}" | jq -r '.object.sha' 2>/dev/null)
if [[ -z "$TAG_EXISTS" ]]; then
echo "Error: vLLM tag '${TAG}' does not exist in vllm-project/vllm."
exit 1
fi
push_image Boolean Handling: Like the is_release variable, use boolean for push_image. It's generally better to use true/false directly rather than string comparisons.is_release is true, the error message could be more user-friendly.2. Code Clarity and Readability:
Simplify Conditional Logic:
{{ github.event.inputs.is_release == 'true' && 'intrafind' || 'dev' }}, use a more readable ternary operator.While generally good, consider slightly more descriptive names in some cases.
Combine steps where possible:
Use YAML anchors/aliases for repetitive sections: The labels section in both docker/build-push-action steps are identical. Use YAML anchors to avoid duplication:
# Define the labels as an anchor
x-common-labels: &common_labels
org.opencontainers.image.title: ${{ github.repository }}
org.opencontainers.image.description: vLLM Docker Image for CPUs
org.opencontainers.image.vendor: IntraFind Software AG
org.opencontainers.image.source: ${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision: ${{ github.sha }}
org.opencontainers.image.version: ${{ github.ref }}
com.intrafind.vllmcpu.vllm.tag: ${{ github.event.inputs.vllm_tag }}
jobs:
build-and-push:
steps:
# ... other steps ...
- name: Build and Push Docker Image for amd64
uses: docker/build-push-action@v6
with:
# ... other options ...
labels: *common_labels
- name: Build and Push Docker Image for arm64
uses: docker/build-push-action@v6
with:
# ... other options ...
labels: *common_labels
3. Efficiency and Optimization:
Modify CMake files to fix arm64 build step is only needed for arm64 builds, conditionally run the Checkout vLLM step within the arm64 job only.docker/metadata-action: Instead of manually setting labels, use docker/metadata-action for automatic label generation following best practices. This can streamline your Docker image metadata.4. Security:
5. Dockerfiles (vllm/docker/Dockerfile.cpu, vllm/docker/Dockerfile.arm):
USER to a non-root user..dockerignore file to exclude unnecessary files from the build context.sed to modify CMake files, consider passing configuration options directly as build arguments to the Dockerfile, making it more flexible. This is a better separation of concerns.6. Other minor issues:
Refactored Example (Illustrative):
name: Build and Push vLLM CPU Docker Image
on:
workflow_dispatch:
inputs:
vllm_tag:
description: 'vLLM version to use (tag in vllm-project/vllm)'
required: true
default: 'v0.8.2'
image_tag:
description: 'Tag for the Docker image (overrides vLLM tag). Not allowed for releases.'
required: false
default: ''
push_image:
description: 'Push Docker image to registry'
type: boolean
required: false
default: false
is_release:
description: 'Perform a release. Requires Git tag; disables image tag override.'
type: boolean
required: false
default: false
env:
BUILD_TAG: ${{ github.run_id }}
IF_REGISTRY: ${{ vars.IF_REGISTRY }} # Define default value for the variable in case it is undefined.
jobs:
build-and-push:
runs-on: ubuntu-24.04
permissions:
contents: write
strategy:
matrix:
arch: [amd64, arm64]
include:
- arch: amd64
dockerfile_suffix: cpu
image_suffix: ""
- arch: arm64
dockerfile_suffix: arm
image_suffix: "-arm"
steps:
- name: Validate Inputs
run: |
if ${{ github.event.inputs.is_release == true && !startsWith(github.ref, 'refs/tags/') }}; then
echo "Error: Release requested, but no Git tag found."
exit 1
fi
if ${{ github.event.inputs.is_release == true && github.event.inputs.image_tag != '' }}; then
echo "Error: Release requested, but image tag override is set."
exit 1
fi
TAG=${{ github.event.inputs.vllm_tag }}
TAG_EXISTS=$(curl -s -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/vllm-project/vllm/git/refs/tags/${TAG}" | jq -r '.object.sha' 2>/dev/null)
if [[ -z "$TAG_EXISTS" ]]; then
echo "Error: vLLM tag '${TAG}' does not exist in vllm-project/vllm."
exit 1
fi
- name: Determine Image Tag and Destination
run: |
IMAGE_TAG=${{ github.event.inputs.image_tag || github.event.inputs.vllm_tag }}
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
REPO=${{ github.event.inputs.is_release == true && 'intrafind' || 'dev' }}
DESTINATION=${{ env.IF_REGISTRY }}/${REPO}/vllm-cpu
echo "DESTINATION=$DESTINATION" >> $GITHUB_ENV
- name: Determine Dockerfile Path
run: |
VER=${{ github.event.inputs.vllm_tag }}
DOCKERFILE_PATH="vllm/docker/Dockerfile" # Default
if version_compare "$VER" "v0.8.2" -lt; then
DOCKERFILE_PATH="vllm/Dockerfile"
fi
echo "DOCKERFILE_PATH=$DOCKERFILE_PATH" >> $GITHUB_ENV
shell: bash
- name: Log in to Docker Registry
uses: docker/login-action@v3
if: ${{ github.event.inputs.push_image == true }}
with:
username: ${{ secrets.IF_REGISTRY_USER }}
password: ${{ secrets.IF_REGISTRY_PASSWORD }}
registry: ${{ env.IF_REGISTRY }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout vLLM
uses: actions/checkout@v4
with:
repository: vllm-project/vllm
ref: ${{ github.event.inputs.vllm_tag }}
path: vllm
- name: Modify CMake files to fix arm64 build
if: ${{ matrix.arch == 'arm64' }}
run: |
# Replace the condition that checks for MacOS with a constant TRUE
# Otherwise the build will fail with "unrecognized command-line option ‘-mavx2’" because it tries to make use of the AVX2 instruction set
#
# Replace:
# if (MACOSX_FOUND AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
# set(APPLE_SILICON_FOUND TRUE)
# with:
# if (TRUE AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"))
# set(APPLE_SILICON_FOUND TRUE)
#
sed -i 's/if (MACOSX_FOUND AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")/if (TRUE AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64"))/g' vllm/cmake/cpu_extension.cmake
# Show the changed part to make it possible to validate it
cat vllm/cmake/cpu_extension.cmake -n | grep "set(APPLE_SILICON_FOUND TRUE)" -C 10
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: vllm
file: ${{ env.DOCKERFILE_PATH }}.${{ matrix.dockerfile_suffix }}
platforms: linux/${{ matrix.arch }}
push: ${{ github.event.inputs.push_image == true }}
tags: ${{ env.DESTINATION }}:${{ env.IMAGE_TAG }}${{ matrix.image_suffix }}
build-args: |
CMAKE_VERBOSE_MAKEFILE=ON
labels: |
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.description=vLLM Docker Image for CPUs
org.opencontainers.image.vendor=IntraFind Software AG
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ github.ref }}
com.intrafind.vllmcpu.vllm.tag=${{ github.event.inputs.vllm_tag }}
Key Improvements in Refactored Example:
true and false booleans directly and ternary operator.Remember to adapt the example to your specific needs, especially the Dockerfile contents and security scanning setup. Remember to define the version_compare function. The simplest solution is probably to install coreutils with apt-get install coreutils.
By addressing these points, you can create a more robust, efficient, and maintainable GitHub Action for building and pushing your vLLM CPU Docker images.