Skip to content

Commit 79a2696

Browse files
committed
Add support for "Builder: oci-import" in diff-pr
Also, update other scripts to use `bashbrew fetch` and `gitCache` effectively to remove unnecessary reimplementations of `BASHBREW_CACHE` default value calculation (new in bashbrew v0.1.8). As a parting gift, add the raw list of total supported architectures to a file so it's more obvious when new ones are added or removed (like `ubuntu` losing `riscv64`).
1 parent f62a71c commit 79a2696

File tree

4 files changed

+95
-42
lines changed

4 files changed

+95
-42
lines changed

.github/workflows/.bashbrew/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ runs:
1010

1111
# these two version numbers are intentionally as close together as I could possibly get them because no matter what I tried, GitHub will not allow me to DRY them (can't have any useful variables in `uses:` and can't even have YAML references to steal it in `env:` or something)
1212
- shell: 'bash -Eeuo pipefail -x {0}'
13-
run: echo BASHBREW_VERSION=v0.1.7 >> "$GITHUB_ENV"
14-
- uses: docker-library/[email protected].7
13+
run: echo BASHBREW_VERSION=v0.1.8 >> "$GITHUB_ENV"
14+
- uses: docker-library/[email protected].8
1515
if: inputs.build == 'host'
1616

1717
- run: docker build --pull --tag oisupport/bashbrew:base "https://github.com/docker-library/bashbrew.git#$BASHBREW_VERSION"

diff-pr.sh

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ if [ "$#" -eq 0 ]; then
9191
set -- $images
9292
fi
9393

94-
export BASHBREW_CACHE="${BASHBREW_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bashbrew}"
9594
export BASHBREW_LIBRARY="$PWD/oi/library"
9695

9796
: "${BASHBREW_ARCH:=amd64}" # TODO something smarter with arches
@@ -103,9 +102,8 @@ template='
103102
{{- "\n" -}}
104103
{{- range $.Entries -}}
105104
{{- $arch := .HasArchitecture arch | ternary arch (.Architectures | first) -}}
106-
{{- $froms := $.ArchDockerFroms $arch . -}}
107105
{{- $outDir := join "_" $.RepoName (.Tags | last) -}}
108-
git -C "$BASHBREW_CACHE/git" archive --format=tar
106+
git -C "{{ gitCache }}" archive --format=tar
109107
{{- " " -}}
110108
{{- "--prefix=" -}}
111109
{{- $outDir -}}
@@ -116,12 +114,28 @@ template='
116114
{{- $dir := .ArchDirectory $arch -}}
117115
{{- (eq $dir ".") | ternary "" $dir -}}
118116
{{- "\n" -}}
119-
mkdir -p "$tempDir/{{- $outDir -}}" && echo "{{- .ArchFile $arch -}}" > "$tempDir/{{- $outDir -}}/.bashbrew-dockerfile-name"
117+
mkdir -p "$tempDir/{{- $outDir -}}" && echo "{{- .ArchBuilder $arch -}}" > "$tempDir/{{- $outDir -}}/.bashbrew-builder" && echo "{{- .ArchFile $arch -}}" > "$tempDir/{{- $outDir -}}/.bashbrew-file"
120118
{{- "\n" -}}
121119
{{- end -}}
122120
tar -cC "$tempDir" . && rm -rf "$tempDir"
123121
'
124122

123+
_tar-t() {
124+
tar -t "$@" \
125+
| grep -vE "$uninterestingTarballGrep" \
126+
| sed -e 's!^[.]/!!' \
127+
-r \
128+
-e 's!([/.-]|^)((lib)?(c?python|py)-?)[0-9]+([.][0-9]+)?([/.-]|$)!\1\2XXX\6!g' \
129+
| sort
130+
}
131+
132+
_jq() {
133+
if [ "$#" -eq 0 ]; then
134+
set -- '.'
135+
fi
136+
jq --tab -S "$@"
137+
}
138+
125139
copy-tar() {
126140
local src="$1"; shift
127141
local dst="$1"; shift
@@ -132,19 +146,73 @@ copy-tar() {
132146
return
133147
fi
134148

135-
local d dockerfiles=()
136-
for d in "$src"/*/.bashbrew-dockerfile-name; do
149+
local d indexes=() dockerfiles=()
150+
for d in "$src"/*/.bashbrew-file; do
137151
[ -f "$d" ] || continue
138152
local bf; bf="$(< "$d")"
139153
local dDir; dDir="$(dirname "$d")"
140-
dockerfiles+=( "$dDir/$bf" )
141-
if [ "$bf" = 'Dockerfile' ]; then
142-
# if "Dockerfile.builder" exists, let's check that too (busybox, hello-world)
143-
if [ -f "$dDir/$bf.builder" ]; then
144-
dockerfiles+=( "$dDir/$bf.builder" )
154+
local builder; builder="$(< "$dDir/.bashbrew-builder")"
155+
if [ "$builder" = 'oci-import' ]; then
156+
indexes+=( "$dDir/$bf" )
157+
else
158+
dockerfiles+=( "$dDir/$bf" )
159+
if [ "$bf" = 'Dockerfile' ]; then
160+
# if "Dockerfile.builder" exists, let's check that too (busybox, hello-world)
161+
if [ -f "$dDir/$bf.builder" ]; then
162+
dockerfiles+=( "$dDir/$bf.builder" )
163+
fi
145164
fi
146165
fi
147-
rm "$d" # remove the ".bashbrew-dockerfile-name" file we created
166+
rm "$d" "$dDir/.bashbrew-builder" # remove the ".bashbrew-*" files we created
167+
done
168+
169+
# now that we're done with our globbing needs, let's disable globbing so it doesn't give us wrong answers
170+
local -
171+
set -o noglob
172+
173+
for i in "${indexes[@]}"; do
174+
local iName; iName="$(basename "$i")"
175+
local iDir; iDir="$(dirname "$i")"
176+
local iDirName; iDirName="$(basename "$iDir")"
177+
local iDst="$dst/$iDirName"
178+
179+
mkdir -p "$iDst"
180+
181+
_jq . "$i" > "$iDst/$iName"
182+
183+
local digest
184+
digest="$(jq -r --arg name "$iName" '
185+
if $name == "index.json" then
186+
.manifests[0].digest
187+
else
188+
.digest
189+
end
190+
' "$i")"
191+
192+
local blob="blobs/${digest//://}"
193+
local blobDir; blobDir="$(dirname "$blob")"
194+
local manifest="$iDir/$blob"
195+
mkdir -p "$iDst/$blobDir"
196+
_jq . "$manifest" > "$iDst/$blob"
197+
198+
local configDigest; configDigest="$(jq -r '.config.digest' "$manifest")"
199+
local blob="blobs/${configDigest//://}"
200+
local blobDir; blobDir="$(dirname "$blob")"
201+
local config="$iDir/$blob"
202+
mkdir -p "$iDst/$blobDir"
203+
_jq . "$config" > "$iDst/$blob"
204+
205+
local layers
206+
layers="$(jq -r '[ .layers[].digest | @sh ] | join(" ")' "$manifest")"
207+
eval "layers=( $layers )"
208+
local layerDigest
209+
for layerDigest in "${layers[@]}"; do
210+
local blob="blobs/${layerDigest//://}"
211+
local blobDir; blobDir="$(dirname "$blob")"
212+
local layer="$iDir/$blob"
213+
mkdir -p "$iDst/$blobDir"
214+
_tar-t -f "$layer" > "$iDst/$blob 'tar -t'"
215+
done
148216
done
149217

150218
for d in "${dockerfiles[@]}"; do
@@ -238,13 +306,7 @@ copy-tar() {
238306
case "$g" in
239307
*.tar.* | *.tgz)
240308
if [ -s "$dstG" ]; then
241-
tar -tf "$dstG" \
242-
| grep -vE "$uninterestingTarballGrep" \
243-
| sed -e 's!^[.]/!!' \
244-
-r \
245-
-e 's!([/.-]|^)((lib)?(c?python|py)-?)[0-9]+([.][0-9]+)?([/.-]|$)!\1\2XXX\6!g' \
246-
| sort \
247-
> "$dstG 'tar -t'"
309+
_tar-t -f "$dstG" > "$dstG 'tar -t'"
248310
fi
249311
;;
250312
esac
@@ -269,6 +331,8 @@ _metadata-files() {
269331
if [ "$#" -gt 0 ]; then
270332
bashbrew list "$@" 2>>temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || :
271333

334+
bashbrew cat --format '{{ range .Entries }}{{ range .Architectures }}{{ . }}{{ "\n" }}{{ end }}{{ end }}' "$@" 2>>temp/_bashbrew.err | sort -u > temp/_bashbrew-arches || :
335+
272336
"$diffDir/_bashbrew-cat-sorted.sh" "$@" 2>>temp/_bashbrew.err > temp/_bashbrew-cat || :
273337

274338
bashbrew list --uniq "$@" \
@@ -277,14 +341,15 @@ _metadata-files() {
277341
| xargs -r bashbrew cat --format "$templateLastTags" 2>>temp/_bashbrew.err \
278342
> temp/_bashbrew-list-build-order || :
279343

344+
bashbrew fetch --arch-filter "$@"
280345
script="$(bashbrew cat --format "$template" "$@")"
281346
mkdir tar
282347
( eval "$script" | tar -xiC tar )
283348
copy-tar tar temp
284349
rm -rf tar
285350
fi
286351

287-
if [ -n "$externalPins" ] && command -v crane &> /dev/null && command -v jq &> /dev/null; then
352+
if [ -n "$externalPins" ] && command -v crane &> /dev/null; then
288353
local file
289354
for file in $externalPins; do
290355
[ -e "oi/$file" ] || continue
@@ -293,7 +358,7 @@ _metadata-files() {
293358
digest="$(< "oi/$file")"
294359
dir="temp/$file"
295360
mkdir -p "$dir"
296-
bashbrew remote arches --json "$pin@$digest" | jq -S . > "$dir/bashbrew.json"
361+
bashbrew remote arches --json "$pin@$digest" | _jq > "$dir/bashbrew.json"
297362
local manifests manifest
298363
manifests="$(jq -r '
299364
[ (
@@ -308,10 +373,10 @@ _metadata-files() {
308373
' "$dir/bashbrew.json")"
309374
eval "manifests=( $manifests )"
310375
for manifest in "${manifests[@]}"; do
311-
crane manifest "$pin@$manifest" | jq -S . > "$dir/manifest-${manifest//:/_}.json"
376+
crane manifest "$pin@$manifest" | _jq > "$dir/manifest-${manifest//:/_}.json"
312377
local config
313378
config="$(jq -r '.config.digest' "$dir/manifest-${manifest//:/_}.json")"
314-
crane blob "$pin@$config" | jq -S . > "$dir/manifest-${manifest//:/_}-config.json"
379+
crane blob "$pin@$config" | _jq > "$dir/manifest-${manifest//:/_}-config.json"
315380
done
316381
done
317382
fi

naughty-commits.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ set -Eeuo pipefail
33

44
fileSizeThresholdMB='2'
55

6-
: "${BASHBREW_CACHE:=$HOME/.cache/bashbrew}"
7-
export BASHBREW_CACHE BASHBREW_ARCH=
8-
9-
if [ ! -d "$BASHBREW_CACHE/git" ]; then
10-
# initialize the "bashbrew cache"
11-
bashbrew --arch amd64 from --uniq --apply-constraints hello-world:linux > /dev/null
12-
fi
6+
export BASHBREW_ARCH=
137

8+
gitCache="$(bashbrew cat --format '{{ gitCache }}' <(echo 'Maintainers: empty hack (@example)'))"
149
_git() {
15-
git -C "$BASHBREW_CACHE/git" "$@"
10+
git -C "$gitCache" "$@"
1611
}
1712

1813
if [ "$#" -eq 0 ]; then
@@ -21,12 +16,11 @@ fi
2116

2217
imgs="$(bashbrew list --repos "$@" | sort -u)"
2318
for img in $imgs; do
19+
bashbrew fetch --all "$img" # force `git fetch`
2420
commits="$(
2521
bashbrew cat --format '
2622
{{- range $e := .Entries -}}
2723
{{- range $a := .Architectures -}}
28-
{{- /* force `git fetch` */ -}}
29-
{{- $froms := $.ArchDockerFroms $a $e -}}
3024
{
3125
{{- json "GitRepo" }}:{{ json ($e.ArchGitRepo $a) -}},
3226
{{- json "GitFetch" }}:{{ json ($e.ArchGitFetch $a) -}},

naughty-constraints.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/usr/bin/env bash
22
set -Eeuo pipefail
33

4-
: "${BASHBREW_CACHE:=$HOME/.cache/bashbrew}"
5-
export BASHBREW_CACHE BASHBREW_ARCH=
6-
7-
if [ ! -d "$BASHBREW_CACHE/git" ]; then
8-
# initialize the "bashbrew cache"
9-
bashbrew --arch amd64 from --uniq --apply-constraints hello-world:linux > /dev/null
10-
fi
4+
export BASHBREW_ARCH=
115

126
if [ "$#" -eq 0 ]; then
137
set -- '--all'

0 commit comments

Comments
 (0)