-
Notifications
You must be signed in to change notification settings - Fork 215
ci/test-images: print docker context #894
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
30cb868
ci/test-images: print docker context
74badb1
Merge branch 'next' into surface-docker-context
alxndrsn 497541b
Add usage message
2bdfdba
update for_humans to human_size
3e94b08
add standard shebang
97311c0
fix size error checking
ce17412
add --help
bb94668
Merge branch 'next' into surface-docker-context
alxndrsn 9b5da4d
Update stackoverflow link
alxndrsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,127 @@ | ||
| #!/bin/bash -eu | ||
| set -o pipefail | ||
| shopt -s inherit_errexit | ||
|
|
||
| log() { echo "[$(basename "$0")] $*"; } | ||
|
|
||
| # See: https://stackoverflow.com/questions/38946683/ | ||
|
|
||
| usage() { | ||
| cat <<EOF | ||
| USAGE | ||
| $0 --report | ||
| $0 [--min-size NUM --max-size NUM | --skip-size] [--min-count NUM --max-count NUM | --skip-count] | ||
| EOF | ||
| } | ||
|
|
||
| if [[ $# = 0 ]]; then | ||
| usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --help) usage; exit;; | ||
|
|
||
| --report) skip_size=true; skip_count=true ;; | ||
|
|
||
| --min-size) shift;min_size="$1" ;; | ||
| --max-size) shift;max_size="$1" ;; | ||
| --skip-size) skip_size=true ;; | ||
|
|
||
| --min-count) shift;min_count="$1" ;; | ||
| --max-count) shift;max_count="$1" ;; | ||
| --skip-count) skip_count=true ;; | ||
|
|
||
| *) log "!!! Unrecognised arg: $1"; exit 1 ;; | ||
| esac | ||
| shift | ||
| done | ||
|
|
||
| tmp="$(mktemp)" | ||
|
|
||
| log "Creating custom docker build driver..." | ||
| # Use custom builder to prevent log truncation: | ||
| # > output clipped, log limit 200KiB/s reached | ||
| docker buildx rm docker_context_checker || true | ||
| docker buildx create --name docker_context_checker \ | ||
| --driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 \ | ||
| --driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=-1 | ||
| docker buildx use docker_context_checker | ||
|
|
||
| log "Building docker image..." | ||
| ( | ||
| docker \ | ||
| buildx build --load \ | ||
| --no-cache --progress plain --file - . 2>&1 <<EOF | ||
| FROM busybox | ||
| COPY . /build-context | ||
| WORKDIR /build-context | ||
| RUN find . -type f | ||
| RUN du -s . | ||
| EOF | ||
| ) | tee "$tmp" | ||
|
|
||
| vars="$(awk ' | ||
| / DONE / { stage="" } | ||
|
|
||
| /RUN find \./ { stage="files" } | ||
| /RUN du -s .$/ { stage="size" } | ||
|
|
||
| stage == "files" { ++file_count } | ||
| stage == "size" { total_size=$3 } | ||
|
|
||
| /exporting config/ { image_hash=$4 } | ||
|
|
||
| END { | ||
| print "file_count: " file_count "\n" | ||
| print "total_size: " total_size "\n" | ||
| print "image_hash: " image_hash "\n" | ||
| } | ||
| ' "$tmp")" | ||
|
|
||
|
|
||
| file_count="$(echo "$vars" | grep file_count | cut -d: -f2)" | ||
| total_size="$(echo "$vars" | grep total_size | cut -d: -f2)" | ||
| docker_img="$(echo "$vars" | grep image_hash | cut -d: -f3)" | ||
|
|
||
| cleanup() { | ||
| log "Removing docker image..." | ||
| docker image rm "$docker_img" >/dev/null | ||
| } | ||
| throw_err() { | ||
| log "!!!" | ||
| log "!!! $* !!!" | ||
| log "!!!" | ||
| cleanup | ||
| exit 1 | ||
| } | ||
|
|
||
| log "File count: $file_count" | ||
| if [[ "${skip_count-}" != "true" ]]; then | ||
| if [[ "$file_count" -lt "$min_count" ]] || [[ "$file_count" -gt "$max_count" ]]; then | ||
| throw_err "This is a surprising number of files - expected between $min_count and $max_count" | ||
| fi | ||
| fi | ||
|
|
||
| human_size() { | ||
| if [[ "$1" -gt 999999 ]]; then | ||
| echo "$(bc <<< "scale=3; $1 / 1000000") GB" | ||
| else | ||
| echo "$(bc <<< "scale=3; $1 / 1000") MB" | ||
| fi | ||
| } | ||
|
|
||
| log "Total size: $(human_size "$total_size")" | ||
| if [[ "${skip_size-}" != "true" ]]; then | ||
| # N.B. busybox `du` outputs in kB | ||
| # See: https://www.busybox.net/downloads/BusyBox.html#du | ||
| if [[ "$total_size" -lt $min_size ]]; then | ||
| throw_err "This is a surprisingly small total size (expected min: $(human_size "$min_size"))" | ||
| elif [[ "$total_size" -gt $max_size ]]; then | ||
| throw_err "This is a surprisingly large total size (expected max: $(human_size "$max_size"))" | ||
| fi | ||
| fi | ||
|
|
||
| cleanup | ||
| log "Everything looks OK." | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.