Skip to content
The Chat Archive
gpt-4o-mini-2024-07-18· OpenAI LMArena Human Preference 140K

Give me feedback on this github action. What can be improved? [code]

  1. User

    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 }}
    
  2. Assistant

    Your GitHub Action for building and pushing Docker images is well-structured and covers a lot of important aspects. However, there are several areas where you could improve clarity, maintainability, and functionality. Here are some suggestions:

    1. Input Validation

    • Type Checking: You are using string comparisons for boolean inputs (is_release and push_image). Consider using if: ${{ github.event.inputs.is_release }} directly, as GitHub Actions will treat it as a boolean.
    • Input Constraints: You could add more validation for the vllm_tag input to ensure it matches the expected format or exists in the repository.

    2. Error Handling

    • Consistent Error Messages: Instead of using echo followed by exit 1, consider using fail or error commands to provide clearer feedback. This can help in debugging.
    • Use of set -e: Consider adding set -e at the beginning of your shell scripts to ensure that the script exits immediately if any command fails.

    3. Environment Variables

    • Use of GITHUB_ENV: You are using echo "VAR=value" >> $GITHUB_ENV multiple times. You could consolidate these into a single step to reduce redundancy and improve readability.
    • Variable Naming: Ensure that environment variable names are consistent and descriptive. For example, DESTINATION could be renamed to DOCKER_IMAGE_DESTINATION for clarity.

    4. Docker Build Steps

    • Conditional Builds: If the push_image input is false, you might want to skip the build steps entirely. This can save time and resources.
    • Use of BuildKit: Ensure that Docker BuildKit is enabled for better performance and caching. You can set DOCKER_BUILDKIT=1 in the environment.

    5. Documentation and Comments

    • Inline Comments: While you have some comments, consider adding more detailed comments explaining the purpose of each step, especially for complex logic.
    • README Update: Ensure that the README or documentation for this action is updated to reflect any changes in inputs or behavior.

    6. Versioning

    • Action Versions: You are using specific versions for actions (e.g., docker/login-action@v3). Consider using the latest stable version or a specific commit SHA for better stability.
    • Docker Image Tags: Ensure that the tags used for Docker images are versioned appropriately to avoid confusion in the future.

    7. Testing and Validation

    • Test Cases: If possible, create a separate job to run tests on the built images to ensure they work as expected.
    • Linting: Consider adding a step to lint your Dockerfiles to catch potential issues early.

    8. Performance Optimization

    • Caching: If your builds take a long time, consider using caching strategies for dependencies or layers to speed up the build process.

    9. Security Considerations

    • Secrets Management: Ensure that sensitive information (like Docker credentials) is handled securely and not exposed in logs.
    • Docker Image Scanning: Consider adding a step to scan the built images for vulnerabilities.

    10. Final Touches

    • Consistent Formatting: Ensure consistent formatting throughout the YAML file for better readability.
    • Use of jobs.<job_id>.steps[*].if: Instead of using if conditions in the run steps, consider using the if attribute directly on the steps to make the logic clearer.

    By implementing these suggestions, you can enhance the robustness, maintainability, and clarity of your GitHub Action.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.