use caching for docker builds (#1340)

* try pulling for cached layers

* use cache-from and cache-to

* empty commit

* add readme

* use specific cache tags

* also cache from main
This commit is contained in:
Robert Brennan 2024-04-24 15:57:46 -04:00 committed by GitHub
parent d357fcff36
commit 8828d9836d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 3 deletions

View File

@ -30,7 +30,7 @@ jobs:
- name: Log-in to ghcr.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Delete huge unnecessary tools folder
run: rm -rf /opt/hostedtoolcache

13
containers/README.md Normal file
View File

@ -0,0 +1,13 @@
# Docker Containers
Each folder here contains a Dockerfile, and a config.sh describing how to build
the image and where to push it. These are images are built and pushed in GitHub Actions
by the `ghcr.yml` workflow.
## Building Manually
```
docker build -f containers/app/Dockerfile -t opendevin .
docker build -f containers/sandbox/Dockerfile -t sandbox .
docker build -f containers/evaluation/Dockerfile -t evaluation evaluation/SWE-bench/
```

View File

@ -9,7 +9,9 @@ if [[ $3 == "--push" ]]; then
fi
echo -e "Building: $image_name"
tags=(latest)
tags=()
cache_tag_base="buildcache"
cache_tag="$cache_tag_base"
if [[ -n $GITHUB_REF_NAME ]]; then
# check if ref name is a version number
if [[ $GITHUB_REF_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@ -18,6 +20,7 @@ if [[ -n $GITHUB_REF_NAME ]]; then
tags+=($major_version $minor_version)
fi
sanitized=$(echo $GITHUB_REF_NAME | sed 's/[^a-zA-Z0-9.-]\+/-/g')
cache_tag+="-${sanitized}"
tags+=($sanitized)
fi
echo "Tags: ${tags[@]}"
@ -38,7 +41,7 @@ fi
DOCKER_REPOSITORY=$DOCKER_REGISTRY/$DOCKER_ORG/$DOCKER_IMAGE
echo "Repo: $DOCKER_REPOSITORY"
echo "Base dir: $DOCKER_BASE_DIR"
#docker pull $DOCKER_REPOSITORY:main || true # try to get any cached layers
args=""
for tag in ${tags[@]}; do
args+=" -t $DOCKER_REPOSITORY:$tag"
@ -49,6 +52,9 @@ fi
docker buildx build \
$args \
--cache-to=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag,mode=max \
--cache-from=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag \
--cache-from=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag_base-main \
--platform linux/amd64,linux/arm64 \
--provenance=false \
-f $dir/Dockerfile $DOCKER_BASE_DIR