File: platforms.bats

package info (click to toggle)
golang-github-containers-buildah 1.41.4%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,152 kB
  • sloc: sh: 2,569; makefile: 241; perl: 187; asm: 16; awk: 12; ansic: 1
file content (75 lines) | stat: -rw-r--r-- 2,706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bats

load helpers

# read the platform information from the configuration of the main image for
# the oci layout in $1
read_oci_layout_platform() {
  run jq -r '.manifests[0].digest' "$1"/index.json
  assert $status -eq 0
  local alg="${output%%:*}"
  local hex="${output##*:}"
  run jq -r '.config.digest' "$1"/blobs/"$alg"/"$hex"
  assert $status -eq 0
  alg="${output%%:*}"
  hex="${output##*:}"
  run jq -r '.os' "$1"/blobs/"$alg"/"$hex"
  assert $status -eq 0
  local os="$output"
  run jq -r '.architecture' "$1"/blobs/"$alg"/"$hex"
  assert $status -eq 0
  local arch="$output"
  run jq -r '.variant' "$1"/blobs/"$alg"/"$hex"
  assert $status -eq 0
  local variant="$output"
  if test "$variant" = null ; then
    variant=
  fi
  echo "$os"/"$arch""${variant:+/$variant}"
}

@test "implicit-and-explicit-platforms" {
  _prefetch busybox
  local context="$TEST_SCRATCH_DIR"/context
  mkdir -p "$context"
  cat > "$context"/Dockerfile.scratch << EOF
  FROM scratch
  COPY . .
EOF
  cat > "$context"/Dockerfile.base << EOF
  FROM busybox
EOF
  cat > "$context"/Dockerfile.derived << EOF
  FROM busybox
  COPY . .
EOF
  run_buildah version --json
  run jq -r .buildPlatform <<< "$output"
  assert $status -eq 0
  local buildplatform="$output"

  # these should either get the default determined at runtime, or the value passed
  for platform in "" linux/amd64 linux/arm64 linux/arm64/v8 ; do
    local arch="${platform##*/}"
    run_buildah build --layers --no-cache -t oci:"$TEST_SCRATCH_DIR"/scratch-"${arch:-default}" ${platform:+--platform "$platform"} -f "$context"/Dockerfile.scratch "$context"
    run read_oci_layout_platform "$TEST_SCRATCH_DIR"/scratch-"${arch:-default}"
    assert $status -eq 0
    assert "$output" = "${platform:-${buildplatform}}" "for build based on scratch for ${platform:-default platform}"
  done

  # these should inherit the values from the base image that we used for the given platform
  for platform in "" linux/amd64 linux/arm64 linux/arm64/v8 ; do
    arch="${platform##*/}"
    for base in base derived ; do
      run_buildah build --layers --no-cache -t "$base"-"${arch:-default}" ${platform:+--platform "$platform"} -f "$context"/Dockerfile."$base" "$context"
      run_buildah push "$base"-"${arch:-default}" oci:"$TEST_SCRATCH_DIR"/"$base"-"${arch:-default}"
    done
    run read_oci_layout_platform "$TEST_SCRATCH_DIR"/base-"${arch:-default}"
    assert $status -eq 0
    baseplatform="$output"
    run read_oci_layout_platform "$TEST_SCRATCH_DIR"/derived-"${arch:-default}"
    assert $status -eq 0
    derivedplatform="$output"
    assert "$baseplatform" = "$derivedplatform" "for build based for ${platform:-default platform}"
  done
}