mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-08 22:38:05 -05:00
chore - Use blacksmith docker build with caching (#7771)
This commit is contained in:
27
.github/workflows/ghcr-build.yml
vendored
27
.github/workflows/ghcr-build.yml
vendored
@@ -29,7 +29,7 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
define-matrix:
|
define-matrix:
|
||||||
runs-on: blacksmith-4vcpu-ubuntu-2204
|
runs-on: blacksmith
|
||||||
outputs:
|
outputs:
|
||||||
base_image: ${{ steps.define-base-images.outputs.base_image }}
|
base_image: ${{ steps.define-base-images.outputs.base_image }}
|
||||||
steps:
|
steps:
|
||||||
@@ -151,14 +151,33 @@ jobs:
|
|||||||
- name: Lowercase Repository Owner
|
- name: Lowercase Repository Owner
|
||||||
run: |
|
run: |
|
||||||
echo REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
|
echo REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
|
||||||
|
- name: Short SHA
|
||||||
|
run: |
|
||||||
|
echo SHORT_SHA=$(git rev-parse --short "$RELEVANT_SHA") >> $GITHUB_ENV
|
||||||
|
- name: Determine docker build params
|
||||||
|
if: github.event.pull_request.head.repo.fork != true
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
./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 }}
|
- name: Build and push runtime image ${{ matrix.base_image.image }}
|
||||||
if: github.event.pull_request.head.repo.fork != true
|
if: github.event.pull_request.head.repo.fork != true
|
||||||
run: |
|
uses: useblacksmith/build-push-action@v1
|
||||||
./containers/build.sh -i runtime -o ${{ env.REPO_OWNER }} --push -t ${{ matrix.base_image.tag }}
|
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
|
# 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 fork
|
- name: Build runtime image ${{ matrix.base_image.image }} for fork
|
||||||
if: github.event.pull_request.head.repo.fork
|
if: github.event.pull_request.head.repo.fork
|
||||||
uses: docker/build-push-action@v6
|
uses: useblacksmith/build-push-action@v1
|
||||||
with:
|
with:
|
||||||
tags: ghcr.io/${{ env.REPO_OWNER }}/runtime:${{ env.RELEVANT_SHA }}-${{ matrix.base_image.tag }}
|
tags: ghcr.io/${{ env.REPO_OWNER }}/runtime:${{ env.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
|
||||||
|
|||||||
@@ -7,15 +7,17 @@ org_name=""
|
|||||||
push=0
|
push=0
|
||||||
load=0
|
load=0
|
||||||
tag_suffix=""
|
tag_suffix=""
|
||||||
|
dry_run=0
|
||||||
|
|
||||||
# Function to display usage information
|
# Function to display usage information
|
||||||
usage() {
|
usage() {
|
||||||
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 " -i: Image name (required)"
|
||||||
echo " -o: Organization name"
|
echo " -o: Organization name"
|
||||||
echo " --push: Push the image"
|
echo " --push: Push the image"
|
||||||
echo " --load: Load the image"
|
echo " --load: Load the image"
|
||||||
echo " -t: Tag suffix"
|
echo " -t: Tag suffix"
|
||||||
|
echo " --dry: Don't build, only create build-args.json"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
--push) push=1; shift ;;
|
--push) push=1; shift ;;
|
||||||
--load) load=1; shift ;;
|
--load) load=1; shift ;;
|
||||||
-t) tag_suffix="$2"; shift 2 ;;
|
-t) tag_suffix="$2"; shift 2 ;;
|
||||||
|
--dry) dry_run=1; shift ;;
|
||||||
*) usage ;;
|
*) usage ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -113,10 +116,13 @@ echo "Repo: $DOCKER_REPOSITORY"
|
|||||||
echo "Base dir: $DOCKER_BASE_DIR"
|
echo "Base dir: $DOCKER_BASE_DIR"
|
||||||
|
|
||||||
args=""
|
args=""
|
||||||
|
full_tags=()
|
||||||
for tag in "${tags[@]}"; do
|
for tag in "${tags[@]}"; do
|
||||||
args+=" -t $DOCKER_REPOSITORY:$tag"
|
args+=" -t $DOCKER_REPOSITORY:$tag"
|
||||||
|
full_tags+=("$DOCKER_REPOSITORY:$tag")
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
if [[ $push -eq 1 ]]; then
|
if [[ $push -eq 1 ]]; then
|
||||||
args+=" --push"
|
args+=" --push"
|
||||||
args+=" --cache-to=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag,mode=max"
|
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 platforms
|
# For push or without load, build for multiple platforms
|
||||||
platform="linux/amd64,linux/arm64"
|
platform="linux/amd64,linux/arm64"
|
||||||
fi
|
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"
|
echo "Building for platform(s): $platform"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user