Skip to content

Commit

Permalink
Add script to reproduce moby/buildkit#2279 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bozaro committed Aug 18, 2021
0 parents commit 3b33533
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.build/


10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG BASE=alpine:edge

FROM $BASE AS base
# RUN command always produce layer with digest `sha256:bcca0bb7...`
RUN echo "Hello, world!!!"; if [ "$(arch)" = "x86_64" ]; then sleep 1; fi; touch -d 2021-01-01 -t 00:00:00 /foo.txt
# COPY command produce differ layer per platform because /opt has differ change time
COPY .build/changed.txt /opt/changed.txt

FROM $BASE
COPY --from=base /opt/changed.txt /opt/copy.txt
28 changes: 28 additions & 0 deletions registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e

PORT=5000

# Start docker registry
if [ "$(docker ps -q -f name=registry)" == "" ]; then
docker run --rm -d -p $PORT:$PORT --name registry registry:2
fi

# Wait docker registry is ready
n=0
until nc -z localhost $PORT; do
sleep 0.1
n=$((n + 1))
if [ "$n" -gt 300 ]; then
echo Waiting port $PORT timeout
exit 1
fi
done

# Reupload used images
for image in moby/buildkit:master alpine:edge; do
local=localhost:$PORT/${image/:[[:alpha:]]*/:latest}
echo "Reupload: $image -> $local"
docker pull $image
docker tag $image $local
docker push $local
done
45 changes: 45 additions & 0 deletions test-pass.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash -e
PORT=5000
REGISTRY=localhost:$PORT

# Recreate builder for clear local cache
docker buildx rm cachebug || true
docker buildx create --name cachebug --driver docker-container --driver-opt image=$REGISTRY/moby/buildkit:latest,network=host
docker buildx inspect cachebug --bootstrap

# Create some changed file
mkdir -p .build
date > .build/changed.txt

# Run with cache-to only
docker buildx build \
--progress=plain \
--builder cachebug \
--build-arg BASE=$REGISTRY/alpine:latest \
--cache-to type=registry,ref=$REGISTRY/cachebug:buildcache,mode=max \
--platform linux/amd64 \
--platform linux/arm64 \
.

# Recreate builder for clear local cache
docker buildx rm cachebug || true
docker buildx create --name cachebug --driver docker-container --driver-opt image=$REGISTRY/moby/buildkit:latest,network=host
docker buildx inspect cachebug --bootstrap

# Create some changed file
date > .build/changed.txt

# Run with cache-from only
docker buildx build \
--progress=plain \
--builder cachebug \
--build-arg BASE=$REGISTRY/alpine:latest \
--cache-from type=registry,ref=$REGISTRY/cachebug:buildcache \
--platform linux/amd64 \
--platform linux/arm64 \
. 2>&1 | tee .build/build.log

if ( grep "Hello, world" .build/build.log | grep -v RUN > /dev/null ); then
echo "Cache miss found"
exit 1
fi
22 changes: 22 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash -e

./registry.sh

TOTAL=0
FAILED=0
for pass in {1..100}; do
if ( ./test-pass.sh > /dev/null 2>&1 ); then
echo "[$pass] OK"
else
echo "[$pass] FAIL"
FAILED=$((FAILED + 1))
fi
TOTAL=$((TOTAL + 1))
done

docker kill registry

if [ $FAILED -gt 0 ]; then
echo "FAILED $FAILED OF $TOTAL"
exit 1
fi

0 comments on commit 3b33533

Please sign in to comment.