Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reuse cached layers to reduce build times #156

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container $UPSTREAM_CONTAINER_CPU \
--push
)
Expand All @@ -96,6 +97,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.base-notebook-cpu.outputs.tag_pinned }} \
--push

Expand All @@ -121,6 +123,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.minimal-notebook-cpu.outputs.tag_pinned }} \
--push

Expand All @@ -146,6 +149,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.minimal-notebook-cpu.outputs.tag_pinned }} \
--push

Expand All @@ -171,6 +175,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.minimal-notebook-cpu.outputs.tag_pinned }} \
--push

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.upstream-equivalent-notebook-gpu.outputs.tag_pinned }} \
--push

Expand All @@ -120,6 +121,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.base-notebook-gpu.outputs.tag_pinned }} \
--push

Expand All @@ -145,6 +147,7 @@ jobs:
--image_name ${{ env.IMAGE_NAME }} \
--tag_pinned ${{ github.sha }} \
--tag_latest ${{ steps.get_branch_name.outputs.branch_name }} \
--cache_from ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_branch_name.outputs.branch_name }} \
--base_container ${{ steps.minimal-notebook-gpu.outputs.tag_pinned }} \
--push \
--prune_this
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ As summary of each step is given in their respective `readme.md` files. The note

Github Actions CI is set up to build and deploy the images on merge to master. Settings defining the base images used for CI (from `docker-stacks` and from `gpu-jupyter`) are defined in `build_settings.env`.

To reduce build times, the Github Actions CI workflow attempts to pull the latest version of each image from ACR before building. In cases where cached layers can be reused, this can considerably reduce build time (at the cost of some data transfer time). In general this appears to be of net benefit (if changing upstream images or `base-notebook` total build times will be ~5 minute slower, but if iterating on any other image build times will be ~10-60 minutes faster).

## Development Notes

Expand Down
2 changes: 1 addition & 1 deletion base-notebook/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ This provides a common notebook setup for both CPU and GPU paths, ensuring they'

## CI

For CI, see `.github/workflows/build-cpu.yml` and `.github/workflows/build-gpu.yml`. They leverage the `.github/workflows/build_push.sh` wrapper for tagging and pushing all at once.
For CI, see `.github/workflows/build-cpu.yml` and `.github/workflows/build-gpu.yml`. They leverage the `.github/workflows/build_push.sh` wrapper for tagging, pushing, and caching all at once.
2 changes: 1 addition & 1 deletion figures/dockerfile_hierarchy.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="app.diagrams.net" modified="2020-09-15T13:31:54.533Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36" etag="VA33pAITnzlLLc3zy3ud" version="13.6.9" type="google"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7V1Zd5s4GP01Pqfz4BwWsz3GSZeZduZkJs20fVRAsakxclkSe379CJAwIGzkBeSFvAQECKF776dPnxYP1Lv58mMAFtM/kQO9gSI5y4F6P1AURTJH+F+SsspSZEWzspRJ4DokbZ3w6P4HSaJEUmPXgWHpxgghL3IX5UQb+T60o1IaCAL0Vr7tBXnlty7ABDIJjzbw2NRvrhNNs1RTMdbpn6A7mdI3yzr5vjmgN5MvCafAQW+FJPX9QL0LEIqyo/nyDnpJ7dF6+fb76pv3ZaZ//OPv8Bd4Gn/++te/wyyz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37jovnWxc29zbgkVO8dG5/1+jC0bAOE/VWCdsQFoXcgWp5ANof1kne02vfOQDbykf8zbGz7P/WfyHY1PSFBs1KIXVEknPILaAHs3grIETxHbzZ05b6StQ6fJHLgnteB5VFcF9aFzSQ77Taaa4FTeSu4QdTrPhnJknlxDabDBoi276F0YHvro5PCwWIH005iEzVypHT7tdCqDxQYD+5krrcEtfNqaxc5cSfLGLbMdXpEdPoHfo2OnLSRWM3ZcdIHVX52822pMHJ+uf983m/67/plk9f3/</diagram></mxfile>
<mxfile host="app.diagrams.net" modified="2020-11-25T18:47:58.638Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" etag="C-ojRN1zDol2ZeOevRNX" version="13.10.3" type="device"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7V3bdps4FP0ar9V5cBYXc3uMkzadaacrM2mm7aMCik2Nkcslsfv1Iy7CgLCRbUA4Ji+xhBBYe++jo6OLR/LNcn3ngdX8b2RBZyQJ1nok344kSRImOv4X5WySHHWiJBkzz7aSLHGb8WD/hmmmkOaGtgX9QsEAISewV8VME7kuNINCHvA89Fos9oyc4lNXYAapjAcTOHTuN9sK5kmuLmnb/I/Qns3Jk0XVSK4sASmcfhN/Diz0msuS34/kGw+hIPm0XN9AJ2o80i7f/tx8cz4v1Lu//vF/gcfpp69f/hsnlX045JbsK3jQDY6u+mWxBurjYrpRP325X3y4naLr9TjF8gU4Ydpe6XcNNqQBoYXbM00iL5ijGXKB836bO/VQ6FoweoyAU9synxFa4UwRZ/6EQbBJyQHCAOGsebB00qvPtuPcIAd58RNlKFoK1HC+H3hoAXNXDFWTgYqvMLZI2nI+Cj0T7iknp8QE3gwGe5prkpSLmiTHrrS97yBawsDb4AIedEBgvxQpCFImz7JyW7TwhxSwA3ghU+CFT6EbhKOJ8PDxmgKyCNPr3A7gwwrE7fKKtV+CBLlBipeIv+F05gDfT29NYCFqikpn0hCOQhPf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g5/qxx21o513EqBP0Vkc9yacsvI4wcGt8xg1rkt0oe3zWBFqCEeK4MVMuFBKlI6ZrA4MLgTBmusDG58sWU18VS1IQarGmcGS71icKvLC0oMFrpksMy6WljqKPzzdmywPDC4Ewaz2mCpKy9CryEesw2uk0LbDKY30BQjW+YFDbQnmnhVxFWumPbtdqg9oePHDLGtS0JNlXuIGh0wPiS6dUnwabreP/i0oV/vVXyLdFOtx7cMypbIR0e4qKrKfG27b+c8tX4xLGaNcU06Gl+pSmMsVkS1XFV5BXHbLO7XXMPbZTHrGGvS0VyDLjbGYlXjzWJlmG/ohMXEUehRrKvWDWC2xfXOSdssHuYcumEx846wzuJdtQaUlcVavXPSNovTUUdhp1IyFo/GzQV+q79CRC6M/Zih0VYMjPV6e5GM3z8kGzRK+zKSmvGbJpWTXRglHdXtp8jvTN21l/U8dlaUIp5V5z/pFYP91jZWKFXb3BukQ2EXTWNkyNYK71pdfJZkEKv2PHfLBjogTlDzV8A9ng1f53a0wepfuEI5GiR1MtOgSVApSgnxX6dwV+1a7RbuyzuEsbodWOeIlX4dKaXQgfbhHMajjpvQuG8FUoaTGAsSqz+KsV/nQykMB0QNhzE2d3Aq920xynAaY0GH9YKVeiVY8t7DgYxcBGxwP+FNHQ5kLOiyXsDcDiHf+97DkYydCFYUuB/Jpr6JMxlH+SB+7ab7psXOfNK50S+xM5x1PhzJ2LIB4P5rBcYZG4CmhWwwClnr1zhZpYdN7xxkAicaH7OOhs/z/JnsUOMeCYqOWlyqoDTWcawm9kpQBuclYoe5M2eFtNH4MpkTj6XmvI7qLUPd+FqS036WqSI4lfWSB0SdzrOjnOi96yiJ0d+3p+XN4qFOeoeHQQtkWMbEbeVK5fRpp0sZDDoYOKxcaQ1u7svWDHrlSlQ37plN/4LscA9+ko5ethBZzdCy0Rts/vLi3VZj4ji5/YnfZPnv9oeS5ff/Aw==</diagram></mxfile>
Binary file modified figures/dockerfile_hierarchy_detailed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion geomatics-notebook/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This is a Dockerfile which adds geomatics-related R packages. Typical usage for

## CI

For CI, see `.github/workflows/build-cpu.yml`. It leverages the `.github/workflows/build_push.sh` wrapper for tagging and pushing all at once.
For CI, see `.github/workflows/build-cpu.yml`. It leverages the `.github/workflows/build_push.sh` wrapper for tagging, pushing and caching all at once.
2 changes: 1 addition & 1 deletion machine-learning-notebook/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This is a Dockerfile which adds Tensorflow and Pytorch. Typical usage for this D

## CI

For CI, see `.github/workflows/build-cpu.yml` and `.github/workflows/build-gpu.yml`. They leverage the `.github/workflows/build_push.sh` wrapper for tagging and pushing all at once.
For CI, see `.github/workflows/build-cpu.yml` and `.github/workflows/build-gpu.yml`. They leverage the `.github/workflows/build_push.sh` wrapper for tagging, pushing and caching all at once.
2 changes: 1 addition & 1 deletion minimal-notebook/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Typical usage for this Dockerfile is to be built off a `base-notebook-cpu` or `b

## CI

For CI, see `.github/workflows/build-cpu.yml` and `.github/workflows/build-gpu.yml`. They leverage the `.github/workflows/build_push.sh` wrapper for tagging and pushing all at once.
For CI, see `.github/workflows/build-cpu.yml` and `.github/workflows/build-gpu.yml`. They leverage the `.github/workflows/build_push.sh` wrapper for tagging, pushing and caching all at once.
2 changes: 1 addition & 1 deletion r-studio/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ This is a Dockerfile which adds R-studio and some additional R packages. Typica

## CI

For CI, see `.github/workflows/build-cpu.yml`. It leverages the `.github/workflows/build_push.sh` wrapper for tagging and pushing all at once.
For CI, see `.github/workflows/build-cpu.yml`. It leverages the `.github/workflows/build_push.sh` wrapper for tagging, pushing and caching all at once.
17 changes: 15 additions & 2 deletions scripts/build_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ set -e
USAGE_MESSAGE="
This script handles building, tagging, and (optionally) pushing an image to a docker repo. It builds the image requested, adds two tags (one intended for version pinning such as a git sha, and one intended for something like 'latest')
and emits the github action 'tag_pinned' when when run as a step in a github action. It optionally can:
* pull an existing image to use as a layer cache
* pass a build-arg 'BASE_CONTAINER' to the 'docker build' command, indicating the container to build from
* prune either all docker images/containers or the images built since starting this script (typically just the images built here, but not guaranteed if other processes run in parallel)
Usage: $0 --registry REGISTRY --image_name IMAGE_NAME --tag_pinned GITHUB_SHA --tag_latest TAG_LATEST [--base_container BASE_CONTAINER] [--push] [--prune]
Usage: $0 --registry REGISTRY --image_name IMAGE_NAME --tag_pinned GITHUB_SHA --tag_latest TAG_LATEST [--base_container BASE_CONTAINER] [--cache-from FULL_IMAGE_PATH] [--push] [--prune]
Where:
registry: container registry full path, such as myRegistry.azurecr.io
image_name: name of the image to be pushed
tag_pinned: tag used for the 'pinned' version (typically a github sha)
tag_latest: tag used for the latest version (typically branch name or master)
tag_latest: tag used for the latest version, both to pull a recent cache and push back to registry
base_container: (optional) if set, pass this value to docker as a build arg (eg: '--build-arg BASE_CONTAINER=THIS_VALUE')
cache_from: (optional) if set, will pull this image to help caching. Typically set to a recently built version of this image, such as myRegistry.azurecr.io/IMAGE_NAME:TAG_LATEST
push: (optional) if set, will push all products to registry. Default is unset
prune_all: (optional) if set, will 'docker system prune -f -a' after build. Default is unset
prune_this: (optional) if set, will remove all images built since this job started (like prune_all but only for products of this job)
Expand All @@ -23,6 +25,7 @@ Where:
PUSH=""
PRUNE_ALL=""
PRUNE_THIS=""
CACHE_FROM=""
BASE_CONTAINER=""
REGISTRY=""
REMOVE_DANGLING="true"
Expand All @@ -40,6 +43,7 @@ while [[ "$#" -gt 0 ]]; do case $1 in
--tag_pinned) GITHUB_SHA="$2"; shift;;
--tag_latest) LATEST="$2"; shift;;
--base_container) BASE_CONTAINER="$2"; shift;;
--cache_from) CACHE_FROM="$2"; shift ;;
--push) PUSH="true"; ;;
--prune_all) PRUNE_ALL="true"; ;;
--prune_this) PRUNE_THIS="true"; ;;
Expand Down Expand Up @@ -74,6 +78,15 @@ fi

BUILD_COMMAND="docker build -t $TAG_PINNED"

# Initialize layer caching by pulling the cache_from image
if [ -z "$CACHE_FROM" ]; then
echo "Skipping cache pull"
else
echo "Pulling cache image"
docker pull "$CACHE_FROM" || true
BUILD_COMMAND="$BUILD_COMMAND --cache-from $CACHE_FROM"
fi

echo "Building image"
if [ -z "$BASE_CONTAINER" ]; then
BUILD_COMMAND="$BUILD_COMMAND ."
Expand Down