...

Text file src/github.com/google/go-containerregistry/cmd/crane/rebase_test.sh

Documentation: github.com/google/go-containerregistry/cmd/crane

     1#!/bin/bash
     2set -ex
     3
     4tmp=$(mktemp -d)
     5
     6go install ./cmd/registry
     7go build -o ./crane ./cmd/crane
     8
     9# Start a local registry.
    10registry &
    11PID=$!
    12function cleanup {
    13  kill $PID
    14  rm -r ${tmp}
    15  rm ./crane
    16}
    17trap cleanup EXIT
    18
    19sleep 1  # Wait for registry to be up.
    20
    21# Create an image localhost:1338/base containing a.txt
    22echo a > ${tmp}/a.txt
    23old_base=$(./crane append -f <(tar -f - -c ${tmp}) -t localhost:1338/base)
    24rm ${tmp}/a.txt
    25
    26# Append to that image localhost:1338/rebaseme
    27echo top > ${tmp}/top.txt
    28orig=$(./crane append -f <(tar -f - -c ${tmp}) -b ${old_base} -t localhost:1338/rebaseme)
    29rm ${tmp}/top.txt
    30
    31# Annotate that image as the base image (by ref and digest)
    32# TODO: do this with a flag to --append
    33orig=$(./crane mutate ${orig} \
    34  --annotation org.opencontainers.image.base.name=localhost:1338/base \
    35  --annotation org.opencontainers.image.base.digest=$(./crane digest localhost:1338/base))
    36
    37# Update localhost:1338/base containing b.txt
    38echo b > ${tmp}/b.txt
    39new_base=$(./crane append -f <(tar -f - -c ${tmp}) -t localhost:1338/base)
    40rm ${tmp}/b.txt
    41
    42# Rebase using annotations
    43rebased=$(./crane rebase ${orig})
    44
    45# List files in the rebased image.
    46./crane export ${rebased} - | tar -tvf -
    47
    48# Extract b.txt out of the rebased image.
    49./crane export ${rebased} - | tar -Oxf - ${tmp:1}/b.txt
    50
    51# Extract top.txt out of the rebased image.
    52./crane export ${rebased} - | tar -Oxf - ${tmp:1}/top.txt
    53
    54# a.txt is _not_ in the rebased image.
    55set +e
    56./crane export ${rebased} - | tar -Oxf - ${tmp:1}/a.txt  # this should fail
    57code=$?
    58echo "finding a.txt exited ${code}"
    59if [[ $code -eq 0 ]]; then
    60  echo "a.txt was found in rebased image"
    61  exit 1
    62fi

View as plain text