buildah/examples/copy.sh

106 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -e
set -x
: " Build a temporary directory; make sure ocid is running."
export PATH=`pwd`:$PATH
d=`mktemp -d`
trap 'cd /;rm -fr "$d"' EXIT
cd "$d"
systemctl restart ocid
read
: " Check if we have some images to work with."
read
ocic image list
read
: " Create a working container, and capture its name "
read
echo '[container1=`buildah from ${1:-alpine}`]'
container1=`buildah from ${1:-alpine}`
read
: " Mount that working container, and capture the mountpoint "
read
echo '[mountpoint1=`buildah mount $container1`]'
mountpoint1=`buildah mount $container1`
read
: " List random files in the container "
read
echo '[find $mountpoint1 -name "random*"]'
find $mountpoint1 -name "random*"
read
: " Ensure the default destination for copying files is / "
read
echo '[buildah config $container1 --workingdir /]'
buildah config $container1 --workingdir /
read
: " Add a file to the container "
read
echo '[dd if=/dev/urandom of=random1 bs=512 count=1]'
echo '[buildah copy $container1 random1]'
dd if=/dev/urandom of=random1 bs=512 count=1
buildah copy $container1 random1
read
: " Change the default destination for copying files "
read
echo '[buildah config $container1 --workingdir /tmp]'
buildah config $container1 --workingdir /tmp
read
: " Add another new file to the container "
read
echo '[dd if=/dev/urandom of=random2 bs=512 count=1]'
echo '[buildah copy $container1 random2]'
dd if=/dev/urandom of=random2 bs=512 count=1
buildah copy $container1 random2
read
: " Copy a subdirectory with some files in it "
read
echo '[mkdir -p randomsubdir]'
echo '[dd if=/dev/urandom of=randomsubdir/random3 bs=512 count=1]'
echo '[dd if=/dev/urandom of=randomsubdir/random4 bs=512 count=1]'
echo '[buildah copy $container1 randomsubdir]'
mkdir -p randomsubdir
dd if=/dev/urandom of=randomsubdir/random3 bs=512 count=1
dd if=/dev/urandom of=randomsubdir/random4 bs=512 count=1
buildah copy $container1 randomsubdir
read
: " List some of the container's contents "
read
echo '[find $mountpoint1 -name "random*"]'
find $mountpoint1 -name "random*"
read
: " Download a tarball "
read
echo '[wget -c https://releases.pagure.org/tmpwatch/tmpwatch-2.9.17.tar.bz2]'
wget -c https://releases.pagure.org/tmpwatch/tmpwatch-2.9.17.tar.bz2
read
: " Copy that tarball to the container "
read
echo '[mkdir -p $mountpoint1/tmpwatch]'
echo '[buildah copy $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2]'
mkdir -p $mountpoint1/tmpwatch
buildah copy $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2
read
: " Download another tarball to the container "
read
echo '[buildah copy $container1 --dest /tmpwatch https://releases.pagure.org/newt/newt-0.52.19.tar.gz]'
buildah copy $container1 --dest /tmpwatch https://releases.pagure.org/newt/newt-0.52.19.tar.gz
read
: " List the contents of the target directory "
read
echo '[find $mountpoint1/tmpwatch]'
find $mountpoint1/tmpwatch
read
: " Now 'add' the downloaded tarball to the container "
read
echo '[buildah add $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2]'
buildah add $container1 --dest /tmpwatch tmpwatch-2.9.17.tar.bz2
read
: " List the contents of the target directory again "
read
echo '[find $mountpoint1/tmpwatch]'
find $mountpoint1/tmpwatch
read
: " Clean up, because I ran this like fifty times while testing "
read
echo '[buildah delete $container1]'
buildah rm $container1