π OpenHands: AI-Driven Development
chore - Use blacksmith docker build with caching (#7771)
Ray Myers4b47e5215b02
diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.ymlindex 592d3f1c5f..369c8d071d 100644--- a/.github/workflows/ghcr-build.yml+++ b/.github/workflows/ghcr-build.yml@@ -29,7 +29,7 @@ env:jobs:define-matrix:- runs-on: blacksmith-4vcpu-ubuntu-2204+ runs-on: blacksmithoutputs:base_image: ${{ steps.define-base-images.outputs.base_image }}steps:@@ -151,14 +151,33 @@ jobs:- name: Lowercase Repository Ownerrun: |echo REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV- - name: Build and push runtime image ${{ matrix.base_image.image }}+ - name: Short SHA+ run: |+ echo SHORT_SHA=$(git rev-parse --short "$RELEVANT_SHA") >> $GITHUB_ENV+ - name: Determine docker build paramsif: github.event.pull_request.head.repo.fork != true+ shell: bashrun: |- ./containers/build.sh -i runtime -o ${{ env.REPO_OWNER }} --push -t ${{ matrix.base_image.tag }}+ ./containers/build.sh -i runtime -o ${{ env.REPO_OWNER }} -t ${{ matrix.base_image.tag }} --dry++ DOCKER_BUILD_JSON=$(jq -c . < docker-build-dry.json)+ echo "DOCKER_TAGS=$(echo "$DOCKER_BUILD_JSON" | jq -r '.tags | join(",")')" >> $GITHUB_ENV+ echo "DOCKER_PLATFORM=$(echo "$DOCKER_BUILD_JSON" | jq -r '.platform')" >> $GITHUB_ENV+ echo "DOCKER_BUILD_ARGS=$(echo "$DOCKER_BUILD_JSON" | jq -r '.build_args | join(",")')" >> $GITHUB_ENV+ - name: Build and push runtime image ${{ matrix.base_image.image }}+ if: github.event.pull_request.head.repo.fork != true+ uses: useblacksmith/build-push-action@v1+ with:+ push: true+ tags: ${{ env.DOCKER_TAGS }}+ platforms: ${{ env.DOCKER_PLATFORM }}+ build-args: ${{ env.DOCKER_BUILD_ARGS }}+ context: containers/runtime+ provenance: false# Forked repos can't push to GHCR, so we need to upload the image as an artifact- name: Build runtime image ${{ matrix.base_image.image }} for forkif: github.event.pull_request.head.repo.fork- uses: docker/build-push-action@v6+ uses: useblacksmith/build-push-action@v1with:tags: ghcr.io/${{ env.REPO_OWNER }}/runtime:${{ env.RELEVANT_SHA }}-${{ matrix.base_image.tag }}outputs: type=docker,dest=/tmp/runtime-${{ matrix.base_image.tag }}.tardiff --git a/containers/build.sh b/containers/build.shindex baaedc115f..72a1d2c117 100755--- a/containers/build.sh+++ b/containers/build.sh@@ -7,15 +7,17 @@ org_name=""push=0load=0tag_suffix=""+dry_run=0# Function to display usage informationusage() {- echo "Usage: $0 -i <image_name> [-o <org_name>] [--push] [--load] [-t <tag_suffix>]"+ echo "Usage: $0 -i <image_name> [-o <org_name>] [--push] [--load] [-t <tag_suffix>] [--dry]"echo " -i: Image name (required)"echo " -o: Organization name"echo " --push: Push the image"echo " --load: Load the image"echo " -t: Tag suffix"+ echo " --dry: Don't build, only create build-args.json"exit 1}@@ -27,6 +29,7 @@ while [[ $# -gt 0 ]]; do--push) push=1; shift ;;--load) load=1; shift ;;-t) tag_suffix="$2"; shift 2 ;;+ --dry) dry_run=1; shift ;;*) usage ;;esacdone@@ -113,10 +116,13 @@ echo "Repo: $DOCKER_REPOSITORY"echo "Base dir: $DOCKER_BASE_DIR"args=""+full_tags=()for tag in "${tags[@]}"; doargs+=" -t $DOCKER_REPOSITORY:$tag"+ full_tags+=("$DOCKER_REPOSITORY:$tag")done+if [[ $push -eq 1 ]]; thenargs+=" --push"args+=" --cache-to=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag,mode=max"@@ -136,6 +142,26 @@ else# For push or without load, build for multiple platformsplatform="linux/amd64,linux/arm64"fi+if [[ $dry_run -eq 1 ]]; then+ echo "Dry Run is enabled. Writing build config to docker-build-dry.json"+ jq -n \+ --argjson tags "$(printf '%s\n' "${full_tags[@]}" | jq -R . | jq -s .)" \+ --arg platform "$platform" \+ --arg openhands_build_version "$OPENHANDS_BUILD_VERSION" \+ --arg dockerfile "$dir/Dockerfile" \+ '{+ tags: $tags,+ platform: $platform,+ build_args: [+ "OPENHANDS_BUILD_VERSION=" + $openhands_build_version+ ],+ dockerfile: $dockerfile+ }' > docker-build-dry.json++ exit 0+fi++echo "Building for platform(s): $platform"