improve cache for labels changes
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 10.3k
- Forks
- 1.5k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 50
Description
We have a use case where a dependentant image gets its cache invalidated by the upstream image adding a new label.
We are wondering if there is anything that can be done at buildkit level (since there is so much work done to improve caching) that could help us improve this use case.
We first build a php docker (using docker-compose)
FROM php:7.0-fpm-alpine AS php70
LABEL maintainer "https://github.com/FernandoMiguel"
RUN adduser -DHSu 100 nginx -s /sbin/nologin
COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY ./opcache.ini /usr/local/etc/php/conf.d/opcache.ini
RUN apk add --no-cache --virtual build-dependencies \
$PHPIZE_DEPS \
autoconf \
automake \
build-base \
cmake \
curl-dev \
file \
g++ \
gcc \
gettext-dev \
git \
icu-dev \
libc-dev \
libmcrypt-dev \
libpng-dev \
libressl-dev \
libtool \
libxml2-dev \
libxslt-dev \
make \
nasm \
pcre-dev \
pkgconf \
re2c \
sqlite-dev \
wget \
zlib-dev
[....]
WORKDIR /var/www
docker-compose tags the labels.
version: "3.6"
services:
php70:
image: xxx.dkr.ecr.eu-west-1.amazonaws.com/php:release-production-php70
build:
context: ../infrastructure-as-code/Docker/php
dockerfile: Dockerfile-7.0
labels:
COMMIT_ID.KIMI: ${COMMIT_ID_KIMI}
COMMIT_ID.SELF_SUBMODULE: ${COMMIT_ID_SELF_infrastructure_as_code}
We then build images that use that as the FROM image
ARG PHPV=-php70
FROM XXXX.dkr.ecr.eu-west-1.amazonaws.com/php:release-production${PHPV} AS lumen-builder
LABEL maintainer "https://github.com/FernandoMiguel"
COPY . /src
RUN cd /src && \
composer -v install --no-dev --no-interaction
Here's the bit from docker-compose
ms-builder:
build:
context: ../ms-xxx
dockerfile: ../.Docker-lumen/Dockerfile-builder
args:
- PHPV=${PHPV}
labels:
COMMIT_ID.KIMI: ${COMMIT_ID_KIMI}
COMMIT_ID.DOCKERFILE_SUBMODULE: ${COMMIT_ID_SELF__Docker_lumen}
image: ms-builder:release-${PHPV}
Sadly even with no code change in any of these two code bases, if anything changes in the repo, the HEAD will change, making the label be updated.
What happens is that the dependant image will now bust cache cause the upstream image updated the label, and as such the image id.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the dependent-image cache invalidation described in the Dockerfiles and docker-compose configurations, changing only the upstream labels. Trace how BuildKit handles the upstream image identity and labels, then define and verify behavior where label-only changes do not unnecessarily invalidate dependent builds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100