Преглед изворни кода

Fix for sha detection for docker tags (#4197)

Robert Brennan пре 1 година
родитељ
комит
2f310d9338
2 измењених фајлова са 9 додато и 8 уклоњено
  1. 6 5
      .github/workflows/ghcr-build.yml
  2. 3 3
      containers/build.sh

+ 6 - 5
.github/workflows/ghcr-build.yml

@@ -27,6 +27,7 @@ on:
 
 
 env:
 env:
   BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST: nikolaik/python-nodejs:python3.12-nodejs22
   BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST: nikolaik/python-nodejs:python3.12-nodejs22
+  RELEVANT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
 
 
 jobs:
 jobs:
   # Builds the OpenHands Docker images
   # Builds the OpenHands Docker images
@@ -83,7 +84,7 @@ jobs:
           export REPO_OWNER=${{ github.repository_owner }}
           export REPO_OWNER=${{ github.repository_owner }}
           REPO_OWNER=$(echo $REPO_OWNER | tr '[:upper:]' '[:lower:]')
           REPO_OWNER=$(echo $REPO_OWNER | tr '[:upper:]' '[:lower:]')
           # Run the build script in the app image
           # Run the build script in the app image
-          docker run -e SANDBOX_USER_ID=0 -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/${REPO_OWNER}/openhands:${{ github.sha }} /bin/bash -c "mkdir -p containers/runtime; python3 openhands/runtime/utils/runtime_build.py --base_image ${{ env.BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST }} --build_folder containers/runtime --force_rebuild" 2>&1 | tee docker-outputs.txt
+          docker run -e SANDBOX_USER_ID=0 -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/${REPO_OWNER}/openhands:$RELEVANT_SHA /bin/bash -c "mkdir -p containers/runtime; python3 openhands/runtime/utils/runtime_build.py --base_image ${{ env.BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST }} --build_folder containers/runtime --force_rebuild" 2>&1 | tee docker-outputs.txt
           # Get the hash from the build script
           # Get the hash from the build script
           hash_from_app_image=$(cat docker-outputs.txt | grep "Hash for docker build directory" | awk -F "): " '{print $2}' | uniq | head -n1)
           hash_from_app_image=$(cat docker-outputs.txt | grep "Hash for docker build directory" | awk -F "): " '{print $2}' | uniq | head -n1)
           echo "hash_from_app_image=$hash_from_app_image" >> $GITHUB_OUTPUT
           echo "hash_from_app_image=$hash_from_app_image" >> $GITHUB_OUTPUT
@@ -160,7 +161,7 @@ jobs:
         if: github.event.pull_request.head.repo.fork
         if: github.event.pull_request.head.repo.fork
         uses: docker/build-push-action@v6
         uses: docker/build-push-action@v6
         with:
         with:
-          tags: ghcr.io/all-hands-ai/runtime:${{ github.sha }}-${{ matrix.base_image.tag }}
+          tags: ghcr.io/all-hands-ai/runtime:$RELEVANT_SHA-${{ matrix.base_image.tag }}
           outputs: type=docker,dest=/tmp/runtime-${{ matrix.base_image.tag }}.tar
           outputs: type=docker,dest=/tmp/runtime-${{ matrix.base_image.tag }}.tar
           context: containers/runtime
           context: containers/runtime
       - name: Upload runtime image for fork
       - name: Upload runtime image for fork
@@ -284,7 +285,7 @@ jobs:
           # Install to be able to retry on failures for flaky tests
           # Install to be able to retry on failures for flaky tests
           poetry run pip install pytest-rerunfailures
           poetry run pip install pytest-rerunfailures
 
 
-          image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
+          image_name=ghcr.io/${{ github.repository_owner }}/runtime:$RELEVANT_SHA-${{ matrix.base_image }}
           image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
           image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
 
 
           SKIP_CONTAINER_LOGS=true \
           SKIP_CONTAINER_LOGS=true \
@@ -362,7 +363,7 @@ jobs:
           # Install to be able to retry on failures for flaky tests
           # Install to be able to retry on failures for flaky tests
           poetry run pip install pytest-rerunfailures
           poetry run pip install pytest-rerunfailures
 
 
-          image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
+          image_name=ghcr.io/${{ github.repository_owner }}/runtime:$RELEVANT_SHA-${{ matrix.base_image }}
           image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
           image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
 
 
           SKIP_CONTAINER_LOGS=true \
           SKIP_CONTAINER_LOGS=true \
@@ -435,7 +436,7 @@ jobs:
         run: make install-python-dependencies
         run: make install-python-dependencies
       - name: Run integration tests
       - name: Run integration tests
         run: |
         run: |
-          image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
+          image_name=ghcr.io/${{ github.repository_owner }}/runtime:$RELEVANT_SHA-${{ matrix.base_image }}
           image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
           image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
 
 
           TEST_RUNTIME=eventstream \
           TEST_RUNTIME=eventstream \

+ 3 - 3
containers/build.sh

@@ -44,10 +44,10 @@ OPENHANDS_BUILD_VERSION="dev"
 cache_tag_base="buildcache"
 cache_tag_base="buildcache"
 cache_tag="$cache_tag_base"
 cache_tag="$cache_tag_base"
 
 
-if [[ -n $GITHUB_SHA ]]; then
-  git_hash=$(git rev-parse --short "$GITHUB_SHA")
+if [[ -n $RELEVANT_SHA ]]; then
+  git_hash=$(git rev-parse --short "$RELEVANT_SHA")
   tags+=("$git_hash")
   tags+=("$git_hash")
-  tags+=("$GITHUB_SHA")
+  tags+=("$RELEVANT_SHA")
 fi
 fi
 
 
 if [[ -n $GITHUB_REF_NAME ]]; then
 if [[ -n $GITHUB_REF_NAME ]]; then