-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to reproduce moby/buildkit#2279 issue
- Loading branch information
0 parents
commit 3b33533
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.build/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |