Skip to content

Commit

Permalink
Switch to "Builder: oci-import"
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Jan 5, 2023
1 parent f7c20e1 commit d329cd3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 34 deletions.
51 changes: 28 additions & 23 deletions download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,40 @@ rm -v artifacts.zip
mv archive/* ./
rmdir archive

# remove "sbuild" tarballs
# we don't use these in Docker, and as of 2017-09-07 unstable/testing are larger than GitHub's maximum file size of 100MB (~140MB)
# they're still available in the Jenkins artifacts directly for folks who want them (and buildable reproducibly via debuerreotype)
rm -rf */sbuild/

# remove empty files (temporary fix for https://github.com/debuerreotype/debuerreotype/commit/d29dd5e030525d9a5d9bd925030d1c11a163380c)
find */ -type f -empty -delete

snapshotUrl="$(cat snapshot-url 2>/dev/null || echo 'https://deb.debian.org/debian')"
dpkgArch="$(< dpkg-arch)"

for suite in */; do
suite="${suite%/}"

[ -f "$suite/rootfs.tar.xz" ]
cat > "$suite/Dockerfile" <<-'EODF'
FROM scratch
ADD rootfs.tar.xz /
CMD ["bash"]
EODF
# TODO cleverly detect whether "bash" exists in "rootfs.tar.xz" (and fall back to "sh" if not)
# https://salsa.debian.org/debian/grow-your-ideas/-/issues/20
cat > "$suite/.dockerignore" <<-'EODI'
**
!rootfs.tar.xz
EODI
for variant in '' slim; do
dir="$suite${variant:+/$variant}"
[ -d "$dir" ]
[ -s "$dir/oci.tar" ]

mkdir "$dir/oci"
tar -xf "$dir/oci.tar" -C "$dir/oci"
rm -f "$dir/oci.tar" "$dir/rootfs.tar.xz"
rootfs='oci/blobs/rootfs.tar.gz'

[ -s "$dir/$rootfs" ]

cmd="$(jq -c '.config.Cmd' "$dir/oci/blobs/image-config.json")"
[[ "$cmd" = '["'*'"]' ]]

cat > "$dir/Dockerfile" <<-EODF
# this isn't used for the official published images anymore, but is included for backwards compatibility
# see https://github.com/docker-library/bashbrew/issues/51
FROM scratch
ADD $rootfs /
CMD $cmd
EODF

[ -f "$suite/slim/rootfs.tar.xz" ]
cp -a "$suite/Dockerfile" "$suite/.dockerignore" "$suite/slim/"
cat > "$dir/.dockerignore" <<-EODI
**
!$rootfs
EODI
done

# check whether xyz-backports exists at this epoch
if wget --quiet --spider "$snapshotUrl/dists/${suite}-backports/main/binary-$dpkgArch/Release"; then
Expand All @@ -64,7 +69,7 @@ declare -A experimentalSuites=(
)
for suite in "${!experimentalSuites[@]}"; do
base="${experimentalSuites[$suite]}"
if [ -f "$base/rootfs.tar.xz" ]; then
if [ -s "$base/Dockerfile" ]; then
[ ! -d "$suite" ]
[ -s "$base/rootfs.debian-sources" ]
mirror="$(awk '$1 == "URIs:" { print $2; exit }' "$base/rootfs.debian-sources")"
Expand Down
45 changes: 34 additions & 11 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,38 @@ for version in "${suites[@]}"; do
fi
description="$(awk -F ': ' '$1 == "Description" { print $2; exit }' <<<"$releaseFile")"

echo
cat <<-EOE
# $version -- $description
Tags: $(join ', ' "${versionAliases[@]}")
Architectures: $(join ', ' "${versionArches[@]}")
Directory: $version
EOE

for variant in \
'' \
backports \
slim \
; do
variantDir="$version/$variant"
variantDir="$version${variant:+/$variant}"

ociOrDockerfile= # 'oci' or 'Dockerfile'
variantArches=()
for arch in "${versionArches[@]}"; do
archCommit="${archCommits[$arch]}"
if _wget --spider "$rawGitUrl/$archCommit/$variantDir/Dockerfile"; then
archOciOrDockerfile=
if _wget --spider "$rawGitUrl/$archCommit/$variantDir/oci/index.json"; then
archOciOrDockerfile='oci'
variantArches+=( "$arch" )
elif _wget --spider "$rawGitUrl/$archCommit/$variantDir/Dockerfile"; then
archOciOrDockerfile='Dockerfile'
variantArches+=( "$arch" )
fi
: "${ociOrDockerfile:="$archOciOrDockerfile"}"
if [ "$archOciOrDockerfile" != "$ociOrDockerfile" ]; then
echo >&2 "error: '$arch' has a mismatching layout for '$variantDir' from '${variantArches[0]}' ('$archOciOrDockerfile' vs '$ociOrDockerfile')"
exit 1
fi
done
[ "${#variantArches[@]}" -gt 0 ] || continue

variantAliases=()
case "$variant" in
'')
variantAliases+=( "${versionAliases[@]}" )
;;
slim)
for versionAlias in "${versionAliases[@]}"; do
case "$versionAlias" in
Expand All @@ -144,10 +151,26 @@ for version in "${suites[@]}"; do
esac

echo
if [ -z "$variant" ]; then
echo "# $version -- $description"
fi
cat <<-EOE
Tags: $(join ', ' "${variantAliases[@]}")
Architectures: $(join ', ' "${variantArches[@]}")
Directory: $variantDir
EOE
if [ "$ociOrDockerfile" = 'oci' ]; then
cat <<-EOE
Builder: oci-import
Directory: $variantDir/oci
File: index.json
EOE
elif [ "$ociOrDockerfile" = 'Dockerfile' ]; then
cat <<-EOE
Directory: $variantDir
EOE
else
echo >&2 "error: unknown 'ociOrDockerfile' value: '$ociOrDockerfile'"
exit 1
fi
done
done

0 comments on commit d329cd3

Please sign in to comment.