github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/tests/integration/bootstrap-get-images.sh (about) 1 #!/usr/bin/env bash 2 set -Eeuo pipefail 3 4 # This script generates "get-images.sh" using Official Images tooling. 5 # 6 # ./bootstrap-get-images.sh > get-images.sh 7 # 8 # This script requires "bashbrew". To get the latest version, visit 9 # https://github.com/docker-library/bashbrew/releases 10 11 images=( 12 # pinned to an older BusyBox (prior to 1.36 becoming "latest") because 1.36.0 has some unresolved bugs, especially around sha256sum 13 'https://github.com/docker-library/official-images/raw/eaed422a86b43c885a0f980d48f4bbf346086a4a/library/busybox:glibc' 14 15 # pinned to an older Debian Buster which has more architectures than the latest does (Buster transitioned from the Debian Security Team to the LTS Team which supports a smaller set) 16 'https://github.com/docker-library/official-images/raw/ce10f6b60289c0c0b5de6f785528b8725f225a58/library/debian:buster-slim' 17 ) 18 19 cat <<'EOH' 20 #!/bin/bash 21 22 # DO NOT EDIT! Generated by "bootstrap-get-images.sh" 23 24 # This script checks if container images needed for tests (currently 25 # busybox and Debian 10 "Buster") are available locally, and downloads 26 # them to testdata directory if not. 27 # 28 # The script is self-contained/standalone and is used from a few places 29 # that need to ensure the images are downloaded. Its output is suitable 30 # for consumption by shell via eval (see helpers.bash). 31 32 set -e -u -o pipefail 33 34 # Root directory of integration tests. 35 INTEGRATION_ROOT=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") 36 # Test data path. 37 TESTDATA="${INTEGRATION_ROOT}/testdata" 38 # Sanity check: $TESTDATA directory must exist. 39 if [ ! -d "$TESTDATA" ]; then 40 echo "Bad TESTDATA directory: $TESTDATA. Aborting" >&2 41 exit 1 42 fi 43 44 function get() { 45 local dest="$1" url="$2" 46 47 [ -e "$dest" ] && return 48 49 # Sanity check: $TESTDATA directory must be writable. 50 if [ ! -w "$TESTDATA" ]; then 51 echo "TESTDATA directory ($TESTDATA) not writable. Aborting" >&2 52 exit 1 53 fi 54 55 if ! curl -o "$dest" -fsSL --retry 5 "$url"; then 56 echo "Failed to get $url" 1>&2 57 exit 1 58 fi 59 } 60 61 arch=$(go env GOARCH) 62 if [ "$arch" = 'arm' ]; then 63 arm=$(go env GOARM) 64 : "${arm:=7}" 65 arch=${arch}v$arm 66 fi 67 EOH 68 69 # shellcheck disable=SC2016 # this generates shell code intentionally (and many of the '$' in here are intended for "text/template" not the end shell anyhow) 70 bashbrew cat --format ' 71 {{- "\n" -}} 72 {{- "case $arch in\n" -}} 73 74 {{- range .TagEntry.Architectures -}} 75 {{- $repo := $.TagEntry.ArchGitRepo . | trimSuffixes ".git" -}} 76 {{- $branch := $.TagEntry.ArchGitFetch . | trimPrefixes "refs/heads/" -}} 77 {{- $commit := $.TagEntry.ArchGitCommit . -}} 78 {{- $dir := $.TagEntry.ArchDirectory . -}} 79 {{- $tarball := eq $.RepoName "debian" | ternary "rootfs.tar.xz" "busybox.tar.xz" -}} 80 81 {{ . | replace "arm64v8" "arm64" "arm32" "arm" "i386" "386" }} {{- ")\n" -}} 82 {{- "\t" -}}# {{ $repo }}/tree/{{ $branch }}{{- "\n" -}} 83 {{- "\t" -}}# {{ $repo }}/tree/{{ $commit }}/{{ $dir }}{{- "\n" -}} 84 {{- "\t" -}} url="{{ $repo }}/raw/{{ $commit }}/{{ $dir }}/{{ $tarball }}"{{- "\n" -}} 85 {{- "\t" -}} ;; {{- "\n" -}} 86 {{- "\n" -}} 87 {{- end -}} 88 89 *){{- "\n" -}} 90 {{- "\t" -}}echo >&2 "error: unsupported {{ $.RepoName }} architecture: $arch"{{- "\n" -}} 91 {{- "\t" -}}exit 1{{- "\n" -}} 92 {{- "\t" -}};;{{- "\n" -}} 93 94 {{- "esac\n" -}} 95 {{- printf `rootfs="$TESTDATA/%s-${arch}.tar.xz"` $.RepoName -}}{{- "\n" -}} 96 {{- `get "$rootfs" "$url"` -}}{{- "\n" -}} 97 {{- printf "var=%s_image\n" $.RepoName -}} 98 {{- `echo "${var^^}=$rootfs"` -}} 99 ' "${images[@]}"