2018-06-11 14:55:51 +08:00
#!/usr/bin/env bats
load helpers
2018-09-03 19:20:52 +08:00
@test "commit-flags-order-verification" {
2020-04-16 21:48:43 +08:00
run_buildah 125 commit cnt1 --tls-verify
2018-09-03 19:20:52 +08:00
check_options_flag_err "--tls-verify"
2020-04-16 21:48:43 +08:00
run_buildah 125 commit cnt1 -q
2018-09-03 19:20:52 +08:00
check_options_flag_err "-q"
2020-04-16 21:48:43 +08:00
run_buildah 125 commit cnt1 -f=docker --quiet --creds=bla:bla
2018-09-03 19:20:52 +08:00
check_options_flag_err "-f=docker"
2020-04-16 21:48:43 +08:00
run_buildah 125 commit cnt1 --creds=bla:bla
2018-09-03 19:20:52 +08:00
check_options_flag_err "--creds=bla:bla"
}
2018-06-11 14:55:51 +08:00
@test "commit" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON $cid alpine-image
2019-04-02 05:56:29 +08:00
run_buildah images alpine-image
2018-06-11 14:55:51 +08:00
}
2022-07-11 14:09:18 +08:00
# Mainly this test is added for rootless setups where XDG_RUNTIME_DIR
# is not set and we end up setting incorrect runroot at various steps
# Use case is typically seen on environments where current session
# is invalid login session.
@test "commit image on rootless setup with mount" {
unset XDG_RUNTIME_DIR
run dd if=/dev/zero of=${TEST_SCRATCH_DIR}/file count=1 bs=10M
run_buildah from scratch
CONT=$output
unset XDG_RUNTIME_DIR
run_buildah mount $CONT
MNT=$output
run cp ${TEST_SCRATCH_DIR}/file $MNT/file
run_buildah umount $CONT
run_buildah commit $CONT foo
run_buildah images foo
expect_output --substring "10.5 MB"
}
2025-05-15 04:57:01 +08:00
@test "commit-with-identity-label" {
run_buildah from scratch
2022-04-04 13:37:01 +08:00
cid=$output
2025-05-15 04:57:01 +08:00
touch $TEST_SCRATCH_DIR/content.txt
run_buildah add $cid $TEST_SCRATCH_DIR/content.txt /
run_buildah commit $cid scratch-image-1
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' scratch-image-1
assert "$output" != "map[]"
run_buildah commit --identity-label=true $cid scratch-image-2
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' scratch-image-2
assert "$output" != "map[]"
}
@test "commit-without-identity-label" {
run_buildah from scratch
cid=$output
touch $TEST_SCRATCH_DIR/content.txt
run_buildah add $cid $TEST_SCRATCH_DIR/content.txt /
run_buildah commit --identity-label=false $WITH_POLICY_JSON $cid scratch-image
run_buildah images scratch-image
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' scratch-image
assert "$output" = "map[]"
}
@test "commit-suppressed-identity-label" {
run_buildah from scratch
cid=$output
touch $TEST_SCRATCH_DIR/content.txt
run_buildah add $cid $TEST_SCRATCH_DIR/content.txt /
run_buildah commit --source-date-epoch=60 $WITH_POLICY_JSON $cid scratch-image-1
run_buildah images scratch-image-1
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' scratch-image-1
assert "$output" = "map[]"
export SOURCE_DATE_EPOCH=90
run_buildah commit $WITH_POLICY_JSON $cid scratch-image-2
unset SOURCE_DATE_EPOCH
run_buildah images scratch-image-2
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' scratch-image-2
assert "$output" = "map[]"
run_buildah commit --timestamp=60 $WITH_POLICY_JSON $cid scratch-image-3
run_buildah images scratch-image-3
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' scratch-image-3
assert "$output" = "map[]"
2022-04-04 13:37:01 +08:00
}
2018-06-11 14:55:51 +08:00
@test "commit format test" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON $cid alpine-image-oci
run_buildah commit --format docker --disable-compression=false $WITH_POLICY_JSON $cid alpine-image-docker
2018-06-11 14:55:51 +08:00
2020-08-12 04:46:36 +08:00
run_buildah inspect --type=image --format '{{.Manifest}}' alpine-image-oci
mediatype=$(jq -r '.layers[0].mediaType' <<<"$output")
expect_output --from="$mediatype" "application/vnd.oci.image.layer.v1.tar"
run_buildah inspect --type=image --format '{{.Manifest}}' alpine-image-docker
mediatype=$(jq -r '.layers[1].mediaType' <<<"$output")
expect_output --from="$mediatype" "application/vnd.docker.image.rootfs.diff.tar.gzip"
2018-06-11 14:55:51 +08:00
}
2021-11-02 04:52:48 +08:00
@test "commit --unsetenv PATH" {
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2021-11-02 04:52:48 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit --unsetenv PATH $WITH_POLICY_JSON $cid alpine-image-oci
run_buildah commit --unsetenv PATH --format docker --disable-compression=false $WITH_POLICY_JSON $cid alpine-image-docker
2021-11-02 04:52:48 +08:00
run_buildah inspect --type=image --format '{{.OCIv1.Config.Env}}' alpine-image-oci
expect_output "[]" "No Path should be defined"
run_buildah inspect --type=image --format '{{.Docker.Config.Env}}' alpine-image-docker
expect_output "[]" "No Path should be defined"
}
2018-06-11 14:55:51 +08:00
@test "commit quiet test" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit --iidfile /dev/null $WITH_POLICY_JSON -q $cid alpine-image
2019-04-05 23:59:54 +08:00
expect_output ""
2018-06-11 14:55:51 +08:00
}
@test "commit rm test" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON --rm $cid alpine-image
2020-04-16 21:48:43 +08:00
run_buildah 125 rm $cid
2022-09-18 18:36:08 +08:00
expect_output --substring "removing container \"alpine-working-container\": container not known"
2018-06-11 14:55:51 +08:00
}
2018-06-22 23:20:02 +08:00
@test "commit-alternate-storage" {
Move away from using docker.io
November 2020, docker.io started restricting unauthenticated
image pulls. Try to work around this by using a custom
registries.conf file.
For the most part this means copying images from docker.io
to quay.io, via:
$ skopeo copy --all docker://docker.io/library/img:tag \
docker://quay.io/libpod/img:tag
...for the following values of 'img:tag':
busybox:musl
centos:7 centos:8 centos:latest
composer:latest
debian:latest ubuntu:latest
docker:latest
php:7.2
For each of those, it was necessary to go into the quay.io
GUI, click the image name, click the settings (gear) icon
at bottom left, click 'Make public', and confirm.
This process did not work in four instances, which required
special-casing:
commit.bats : openshift/hello-openshift did not match the
mirroring rules; I switched to alpine instead.
Nalin confirmed on IRC that there was no magic
reason for requiring hello-openshift.
pull.bats : change a SHA. AFAICT there was nothing magic
about the SHA being used, it was just a
convenient one for purposes of testing
pull-by-sha. I simply switched to the SHA
of an image present on quay.
registries.bats : was assuming that fedora-minimal shortname
would be pulled from fedora registry.
Unfortunately, we have a copy on quay
(for podman tests), so that's what we
pull by shortname, and it does not match
the SHA of the fedoraproject.org one.
Solution: pull by tag (fedora-minimal:32)
and hope that nobody ever mirrors that one
on quay.
run.bats : another pull-by-SHA, but this time I changed
the SHA to a named tag, and skopeo copy'd
that image from docker.io to the given name
on quay. This time there _is_ something
magic about that particular SHA (it's an
image with a specific volume quirk) but
there's no actual reason to reference it
by SHA - we simply did so because we have
no control over tag names on docker.io.
Since we control tag names on quay.io,
it's easy and more maintainable to give
this image a descriptive tag.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-12-08 06:36:43 +08:00
_prefetch alpine
2018-06-22 23:20:02 +08:00
echo FROM
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2018-06-22 23:20:02 +08:00
echo COMMIT
2022-04-26 23:09:11 +08:00
run_buildah commit $WITH_POLICY_JSON $cid "containers-storage:[vfs@${TEST_SCRATCH_DIR}/root2+${TEST_SCRATCH_DIR}/runroot2]newimage"
2018-06-22 23:20:02 +08:00
echo FROM
2022-04-26 23:09:11 +08:00
run_buildah --storage-driver vfs --root ${TEST_SCRATCH_DIR}/root2 --runroot ${TEST_SCRATCH_DIR}/runroot2 from $WITH_POLICY_JSON newimage
2018-06-22 23:20:02 +08:00
}
2018-08-22 04:33:36 +08:00
@test "commit-rejected-name" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah 125 commit $WITH_POLICY_JSON $cid ThisNameShouldBeRejected
2019-04-05 23:59:54 +08:00
expect_output --substring "must be lower"
2018-08-22 04:33:36 +08:00
}
2019-04-04 02:57:55 +08:00
@test "commit-no-empty-created-by" {
2019-04-05 23:59:54 +08:00
if ! python3 -c 'import json, sys' 2> /dev/null ; then
2019-04-04 02:57:55 +08:00
skip "python interpreter with json module not found"
fi
target=new-image
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2019-04-04 02:57:55 +08:00
2019-12-12 02:28:27 +08:00
run_buildah config --created-by "untracked actions" $cid
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON $cid ${target}
2019-12-12 02:28:27 +08:00
run_buildah inspect --format '{{.Config}}' ${target}
2019-04-04 02:57:55 +08:00
config="$output"
2019-04-05 23:59:54 +08:00
run python3 -c 'import json, sys; config = json.load(sys.stdin); print(config["history"][len(config["history"])-1]["created_by"])' <<< "$config"
2019-04-04 02:57:55 +08:00
echo "$output"
2023-01-05 21:42:11 +08:00
assert "$status" -eq 0 "status from python command 1"
2019-12-12 07:21:51 +08:00
expect_output "untracked actions"
2019-04-04 02:57:55 +08:00
2019-12-12 02:28:27 +08:00
run_buildah config --created-by "" $cid
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON $cid ${target}
2019-12-12 02:28:27 +08:00
run_buildah inspect --format '{{.Config}}' ${target}
2019-04-04 02:57:55 +08:00
config="$output"
2019-04-05 23:59:54 +08:00
run python3 -c 'import json, sys; config = json.load(sys.stdin); print(config["history"][len(config["history"])-1]["created_by"])' <<< "$config"
2019-04-04 02:57:55 +08:00
echo "$output"
2023-01-05 21:42:11 +08:00
assert "$status" -eq 0 "status from python command 2"
2019-12-12 07:21:51 +08:00
expect_output "/bin/sh"
2019-04-04 02:57:55 +08:00
}
2019-03-21 01:06:29 +08:00
@test "commit-no-name" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON $cid
2019-03-21 01:06:29 +08:00
}
2019-11-06 11:57:38 +08:00
2020-12-22 00:19:56 +08:00
@test "commit should fail with nonexistent authfile" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah 125 commit --authfile /tmp/nonexistent $WITH_POLICY_JSON $cid alpine-image
2019-11-06 11:57:38 +08:00
}
2019-11-13 00:50:21 +08:00
@test "commit-builder-identity" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull $WITH_POLICY_JSON alpine
2019-12-12 03:11:08 +08:00
cid=$output
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON $cid alpine-image
2019-11-13 00:50:21 +08:00
2019-12-12 07:21:51 +08:00
run_buildah --version
local -a output_fields=($output)
buildah_version=${output_fields[2]}
2019-11-13 00:50:21 +08:00
2019-12-12 07:21:51 +08:00
run_buildah inspect --format '{{ index .Docker.Config.Labels "io.buildah.version"}}' alpine-image
expect_output "$buildah_version"
2019-11-13 00:50:21 +08:00
}
2019-11-20 04:23:14 +08:00
@test "commit-container-id" {
2019-12-09 21:45:52 +08:00
_prefetch alpine
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull $WITH_POLICY_JSON alpine
2019-12-12 07:21:51 +08:00
# There is exactly one container. Get its ID.
run_buildah containers --format '{{.ContainerID}}'
2019-12-12 03:11:08 +08:00
cid=$output
2019-12-12 07:21:51 +08:00
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON --format docker $cid alpine-image
2019-12-12 03:11:08 +08:00
run_buildah inspect --format '{{.Docker.Container}}' alpine-image
2019-12-12 07:21:51 +08:00
expect_output "$cid" "alpine-image -> .Docker.Container"
2019-11-06 18:20:33 +08:00
}
2019-10-28 16:25:42 +08:00
@test "commit with name" {
2019-12-09 21:45:52 +08:00
_prefetch busybox
2022-04-26 21:47:03 +08:00
run_buildah from --quiet $WITH_POLICY_JSON --name busyboxc busybox
2019-12-04 02:18:24 +08:00
expect_output "busyboxc"
# Commit with a new name
newname="commitbyname/busyboxname"
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON busyboxc $newname
2019-12-04 02:18:24 +08:00
2022-04-26 21:47:03 +08:00
run_buildah from $WITH_POLICY_JSON localhost/$newname
2019-12-04 02:18:24 +08:00
expect_output "busyboxname-working-container"
cname=$output
run_buildah inspect --format '{{.FromImage}}' $cname
expect_output "localhost/$newname:latest"
2019-10-28 16:25:42 +08:00
}
@test "commit to docker-distribution" {
2019-12-09 21:45:52 +08:00
_prefetch busybox
2022-04-26 21:47:03 +08:00
run_buildah from $WITH_POLICY_JSON --name busyboxc busybox
2022-03-10 23:22:37 +08:00
start_registry
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON --tls-verify=false --creds testuser:testpassword busyboxc docker://localhost:${REGISTRY_PORT}/commit/busybox
run_buildah from $WITH_POLICY_JSON --name fromdocker --tls-verify=false --creds testuser:testpassword docker://localhost:${REGISTRY_PORT}/commit/busybox
2019-11-20 04:23:14 +08:00
}
2020-04-17 23:48:14 +08:00
@test "commit encrypted local oci image" {
2022-03-04 18:38:38 +08:00
skip_if_rootless_environment
2020-04-17 23:48:14 +08:00
_prefetch busybox
2022-04-26 23:09:11 +08:00
mkdir ${TEST_SCRATCH_DIR}/tmp
openssl genrsa -out ${TEST_SCRATCH_DIR}/tmp/mykey.pem 1024
openssl rsa -in ${TEST_SCRATCH_DIR}/tmp/mykey.pem -pubout > ${TEST_SCRATCH_DIR}/tmp/mykey.pub
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
2020-04-17 23:48:14 +08:00
cid=$output
2022-04-26 23:09:11 +08:00
run_buildah commit --iidfile /dev/null $WITH_POLICY_JSON --encryption-key jwe:${TEST_SCRATCH_DIR}/tmp/mykey.pub -q $cid oci:${TEST_SCRATCH_DIR}/tmp/busybox_enc
imgtype -show-manifest oci:${TEST_SCRATCH_DIR}/tmp/busybox_enc | grep "+encrypted"
rm -rf ${TEST_SCRATCH_DIR}/tmp
2020-04-17 23:48:14 +08:00
}
@test "commit oci encrypt to registry" {
_prefetch busybox
2022-04-26 23:09:11 +08:00
mkdir ${TEST_SCRATCH_DIR}/tmp
openssl genrsa -out ${TEST_SCRATCH_DIR}/tmp/mykey.pem 1024
openssl rsa -in ${TEST_SCRATCH_DIR}/tmp/mykey.pem -pubout > ${TEST_SCRATCH_DIR}/tmp/mykey.pub
2022-03-10 23:22:37 +08:00
start_registry
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
2020-04-17 23:48:14 +08:00
cid=$output
2022-04-26 23:09:11 +08:00
run_buildah commit --iidfile /dev/null --tls-verify=false --creds testuser:testpassword $WITH_POLICY_JSON --encryption-key jwe:${TEST_SCRATCH_DIR}/tmp/mykey.pub -q $cid docker://localhost:${REGISTRY_PORT}/buildah/busybox_encrypted:latest
2020-04-17 23:48:14 +08:00
# this test, just checks the ability to commit an image to a registry
# there is no good way to test the details of the image unless with ./buildah pull, test will be in pull.bats
2022-04-26 23:09:11 +08:00
rm -rf ${TEST_SCRATCH_DIR}/tmp
2022-04-29 05:27:16 +08:00
# verify that encrypted layers are not cached or reused for an non-encrypted image (See containers/image#1533)
run_buildah commit --iidfile /dev/null --tls-verify=false --creds testuser:testpassword $WITH_POLICY_JSON -q $cid docker://localhost:${REGISTRY_PORT}/buildah/busybox_not_encrypted:latest
run_buildah from $WITH_POLICY_JSON --tls-verify=false --creds testuser:testpassword docker://localhost:${REGISTRY_PORT}/buildah/busybox_not_encrypted:latest
2020-04-17 23:48:14 +08:00
}
2020-08-11 17:28:41 +08:00
@test "commit omit-timestamp" {
_prefetch busybox
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
2020-08-11 17:28:41 +08:00
cid=$output
run_buildah run $cid touch /test
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON --omit-timestamp -q $cid omit
2020-08-11 17:28:41 +08:00
run_buildah inspect --format '{{ .Docker.Created }}' omit
expect_output --substring "1970-01-01"
run_buildah inspect --format '{{ .OCIv1.Created }}' omit
expect_output --substring "1970-01-01"
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON omit
2020-08-27 04:56:57 +08:00
cid=$output
run_buildah run $cid ls -l /test
expect_output --substring "1970"
2022-04-26 23:09:11 +08:00
rm -rf ${TEST_SCRATCH_DIR}/tmp
2020-08-27 04:56:57 +08:00
}
@test "commit timestamp" {
_prefetch busybox
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
2020-08-27 04:56:57 +08:00
cid=$output
run_buildah run $cid touch /test
2022-04-26 21:47:03 +08:00
run_buildah commit $WITH_POLICY_JSON --timestamp 0 -q $cid omit
2020-08-27 04:56:57 +08:00
run_buildah inspect --format '{{ .Docker.Created }}' omit
expect_output --substring "1970-01-01"
run_buildah inspect --format '{{ .OCIv1.Created }}' omit
expect_output --substring "1970-01-01"
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON omit
2020-08-11 17:28:41 +08:00
cid=$output
run_buildah run $cid ls -l /test
expect_output --substring "1970"
2022-04-26 23:09:11 +08:00
rm -rf ${TEST_SCRATCH_DIR}/tmp
2020-08-11 17:28:41 +08:00
}
2021-04-07 04:11:12 +08:00
@test "commit with authfile" {
_prefetch busybox
2022-04-26 21:47:03 +08:00
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
2021-04-07 04:11:12 +08:00
cid=$output
run_buildah run $cid touch /test
2022-03-10 23:22:37 +08:00
start_registry
2022-04-26 23:09:11 +08:00
run_buildah login --authfile ${TEST_SCRATCH_DIR}/test.auth --username testuser --password testpassword --tls-verify=false localhost:${REGISTRY_PORT}
run_buildah commit --authfile ${TEST_SCRATCH_DIR}/test.auth $WITH_POLICY_JSON --tls-verify=false $cid docker://localhost:${REGISTRY_PORT}/buildah/my-busybox
2021-04-07 04:11:12 +08:00
expect_output --substring "Writing manifest to image destination"
}
2022-08-11 02:19:19 +08:00
@test "commit-without-names" {
_prefetch busybox
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
cid=$output
run_buildah run $cid touch /testfile
run_buildah run $cid chown $(id -u):$(id -g) /testfile
run_buildah commit $cid dir:${TEST_SCRATCH_DIR}/new-image
config=$(jq -r .config.digest ${TEST_SCRATCH_DIR}/new-image/manifest.json)
echo "config blob is $config"
diffid=$(jq -r '.rootfs.diff_ids[-1]' ${TEST_SCRATCH_DIR}/new-image/${config##*:})
echo "new layer is $diffid"
run_buildah copy $cid ${TEST_SCRATCH_DIR}/new-image/${diffid##*:} /testdiff.tar
# use in-container version of tar to avoid worrying about differences in
# output formats between tar implementations
run_buildah run $cid tar tvf /testdiff.tar testfile
echo "new file looks like [$output]"
# ownership information should be forced to be in number/number format
# instead of name/name because the names are gone
assert "$output" =~ $(id -u)/$(id -g)
}
2023-12-13 03:54:42 +08:00
@test "commit-with-extra-files" {
_prefetch busybox
run_buildah from --quiet --pull=false $WITH_POLICY_JSON busybox
cid=$output
2025-06-18 00:52:28 +08:00
createrandom ${TEST_SCRATCH_DIR}/randomfile1
createrandom ${TEST_SCRATCH_DIR}/randomfile2
2023-12-13 03:54:42 +08:00
for method in --squash=false --squash=true ; do
2025-06-18 00:52:28 +08:00
run_buildah commit $method --add-file ${TEST_SCRATCH_DIR}/randomfile1:/randomfile1 $cid with-random-1
run_buildah commit $method --add-file ${TEST_SCRATCH_DIR}/randomfile2:/in-a-subdir/randomfile2 $cid with-random-2
run_buildah commit $method --add-file ${TEST_SCRATCH_DIR}/randomfile1:/randomfile1 --add-file ${TEST_SCRATCH_DIR}/randomfile2:/in-a-subdir/randomfile2 $cid with-random-both
2023-12-13 03:54:42 +08:00
# first one should have the first file and not the second, and the shell should be there
run_buildah from --quiet --pull=false $WITH_POLICY_JSON with-random-1
cid=$output
run_buildah mount $cid
mountpoint=$output
test -s $mountpoint/bin/sh || test -L $mountpoint/bin/sh
2025-06-18 00:52:28 +08:00
cmp ${TEST_SCRATCH_DIR}/randomfile1 $mountpoint/randomfile1
2023-12-13 03:54:42 +08:00
run stat -c %u:%g $mountpoint
[ $status -eq 0 ]
rootowner=$output
run stat -c %u:%g:%A $mountpoint/randomfile1
[ $status -eq 0 ]
assert ${rootowner}:-rw-r--r--
! test -f $mountpoint/randomfile2
# second one should have the second file and not the first, and the shell should be there
run_buildah from --quiet --pull=false $WITH_POLICY_JSON with-random-2
cid=$output
run_buildah mount $cid
mountpoint=$output
test -s $mountpoint/bin/sh || test -L $mountpoint/bin/sh
2025-06-18 00:52:28 +08:00
cmp ${TEST_SCRATCH_DIR}/randomfile2 $mountpoint/in-a-subdir/randomfile2
2023-12-13 03:54:42 +08:00
run stat -c %u:%g $mountpoint
[ $status -eq 0 ]
rootowner=$output
run stat -c %u:%g:%A $mountpoint/in-a-subdir/randomfile2
[ $status -eq 0 ]
assert ${rootowner}:-rw-r--r--
! test -f $mountpoint/randomfile1
# third one should have both files, and the shell should be there
run_buildah from --quiet --pull=false $WITH_POLICY_JSON with-random-both
cid=$output
run_buildah mount $cid
mountpoint=$output
test -s $mountpoint/bin/sh || test -L $mountpoint/bin/sh
2025-06-18 00:52:28 +08:00
cmp ${TEST_SCRATCH_DIR}/randomfile1 $mountpoint/randomfile1
2023-12-13 03:54:42 +08:00
run stat -c %u:%g $mountpoint
[ $status -eq 0 ]
rootowner=$output
run stat -c %u:%g:%A $mountpoint/randomfile1
[ $status -eq 0 ]
assert ${rootowner}:-rw-r--r--
2025-06-18 00:52:28 +08:00
cmp ${TEST_SCRATCH_DIR}/randomfile2 $mountpoint/in-a-subdir/randomfile2
2023-12-13 03:54:42 +08:00
run stat -c %u:%g:%A $mountpoint/in-a-subdir/randomfile2
[ $status -eq 0 ]
assert ${rootowner}:-rw-r--r--
done
}
2024-05-01 03:31:01 +08:00
@test "commit with insufficient disk space" {
skip_if_rootless_environment
_prefetch busybox
local tmp=$TEST_SCRATCH_DIR/buildah-test
mkdir -p $tmp
mount -t tmpfs -o size=4M tmpfs $tmp
# Create a temporary file which should not be easy to compress,
# which we'll add to our container for committing, but which is
# larger than the filesystem where the layer blob that would
# contain it, compressed or not, would be written during commit.
run dd if=/dev/urandom of=$TEST_SCRATCH_DIR/8M bs=1M count=8
# Create a working container.
run_buildah from --pull=never $WITH_POLICY_JSON busybox
ctrID="$output"
# Copy the file into the working container.
run_buildah copy $ctrID $TEST_SCRATCH_DIR/8M /8M
# Try to commit the image. The temporary copy of the layer diff should
# require more space than is available where we're telling it to store
# temporary things.
TMPDIR=$tmp run_buildah '?' commit $ctrID
umount $tmp
expect_output --substring "no space left on device"
}
2025-04-30 04:37:27 +08:00
@test "commit-with-source-date-epoch" {
_prefetch busybox
local url=https://raw.githubusercontent.com/containers/buildah/main/tests/bud/from-scratch/Dockerfile
local timestamp=60
local datestamp="1970-01-01T00:01:00Z"
mkdir -p $TEST_SCRATCH_DIR/context
createrandom $TEST_SCRATCH_DIR/context/randomfile1
createrandom $TEST_SCRATCH_DIR/context/randomfile2
run_buildah from -q busybox
local cid="$output"
run_buildah add --add-history "$cid" $TEST_SCRATCH_DIR/context/* /context
# commit using defaults
run_buildah commit "$cid" oci:$TEST_SCRATCH_DIR/default
# commit with an implicitly-provided timestamp
export local SOURCE_DATE_EPOCH=$timestamp
run_buildah commit "$cid" oci:$TEST_SCRATCH_DIR/implicit
run_buildah commit --rewrite-timestamp "$cid" oci:$TEST_SCRATCH_DIR/implicit-rewritten
unset SOURCE_DATE_EPOCH
# commit with an explicity-provided timestamp
run_buildah commit --source-date-epoch=$timestamp "$cid" oci:$TEST_SCRATCH_DIR/explicit
run_buildah commit --source-date-epoch=$timestamp --rewrite-timestamp "$cid" oci:$TEST_SCRATCH_DIR/explicit-rewritten
# check timestamps in the ones we forced: find the manifest's and config's digests
manifestdigest=$(oci_image_manifest_digest "$TEST_SCRATCH_DIR"/explicit)
manifestalg=${manifestdigest%%:*}
manifestval=${manifestdigest##*:}
configdigest=$(oci_image_config_digest "$TEST_SCRATCH_DIR"/explicit)
configalg=${configdigest%%:*}
configval=${configdigest##*:}
# check timestamps in the ones we forced: read the image creation date
config="$TEST_SCRATCH_DIR"/explicit/$(oci_image_config "$TEST_SCRATCH_DIR"/explicit)
run jq -r '.created' "$config"
echo "$output"
assert $status = 0 "looking for the image creation date"
assert "$output" = "$datestamp" "unexpected creation date for image"
# check timestamps in the ones we forced: read the image history entry dates
run jq -r '.history[-2].created' "$config"
echo "$output"
assert $status = 0 "looking for the image history entries"
jq '.history' "$config"
for line in "$lines[@]"; do
assert "$output" = "$datestamp" "unexpected datestamp for history entry"
done
# check timestamps in the ones we forced: extract the layer blob
layer="$TEST_SCRATCH_DIR"/explicit/$(oci_image_last_diff "$TEST_SCRATCH_DIR"/explicit)
mkdir -p "$TEST_SCRATCH_DIR"/layer
tar -C "$TEST_SCRATCH_DIR"/layer -xvf "$layer"
# check timestamps in the ones we forced: walk the layer blob, checking
# timestamps
for file in $(find $TEST_SCRATCH_DIR/layer/* -print) ; do
run stat -c %Y $file
assert $status = 0 "checking datestamp on $file in layer"
assert "$output" -gt "$timestamp" "unexpected datestamp on $file in layer"
done
# check timestamps in the ones we forced: check that we have an image config
# and manifest with the same digests when we set the source date epoch
# implicitly as we did when we forced them explicitly
test -s $TEST_SCRATCH_DIR/implicit/blobs/"$manifestalg"/"$manifestval"
test -s $TEST_SCRATCH_DIR/implicit/blobs/"$configalg"/"$configval"
# check timestamps in the ones we forced and rewrote timestamps in: the
# version where we rewrote timestamps in the layer should have produced
# different diffIDs, and thus a different config blob, and a different
# manifest, so the ones we just looked at shouldn't _also_ be in there
! test -s $TEST_SCRATCH_DIR/explicit-rewritten/blobs/"$manifestalg"/"$manifestval"
! test -s $TEST_SCRATCH_DIR/explicit-rewritten/blobs/"$configalg"/"$configval"
# check timestamps in the ones we forced and rewrote timestamps in: find the
# manifest's and config's digests
manifestdigest=$(oci_image_manifest_digest "$TEST_SCRATCH_DIR"/explicit-rewritten)
manifestalg=${manifestdigest%%:*}
manifestval=${manifestdigest##*:}
configdigest=$(oci_image_config_digest "$TEST_SCRATCH_DIR"/explicit-rewritten)
configalg=${configdigest%%:*}
configval=${configdigest##*:}
# check timestamps in the ones we forced and rewrote timestamps in: read the
# image creation date
config="$TEST_SCRATCH_DIR"/explicit-rewritten/$(oci_image_config "$TEST_SCRATCH_DIR"/explicit-rewritten)
run jq -r '.created' "$config"
echo "$output"
assert $status = 0 "looking for the image creation date"
assert "$output" = "$datestamp" "unexpected creation date for image"
# check timestamps in the ones we forced and rewrote timestamps in: read the
# image history entry dates
run jq -r '.history[-2].created' "$config"
echo "$output"
assert $status = 0 "looking for the image history entries"
jq '.history' "$config"
for line in "$lines[@]"; do
assert "$output" = "$datestamp" "unexpected datestamp for history entry"
done
# check timestamps in the ones we forced and rewrote timestamps in: extract
# the layer blob
layer="$TEST_SCRATCH_DIR"/explicit-rewritten/$(oci_image_last_diff "$TEST_SCRATCH_DIR"/explicit-rewritten)
rm -fr $TEST_SCRATCH_DIR/layer; mkdir -p $TEST_SCRATCH_DIR/layer
tar -C $TEST_SCRATCH_DIR/layer -xvf "$layer"
# check timestamps in the ones we forced and rewrote timestamps in: walk the
# layer blob, checking timestamps
for file in $(find $TEST_SCRATCH_DIR/layer/* -print) ; do
run stat -c %Y $file
assert $status = 0 "checking datestamp on $file in layer"
assert "$output" -le "$timestamp" "unexpected datestamp on $file in layer"
done
# check timestamps in the ones we forced and rewrote timestamps in: check
# that we have an image config and manifest with the same digests when we set
# the source date epoch implicitly as we did when we forced them explicitly
test -s $TEST_SCRATCH_DIR/implicit-rewritten/blobs/"$manifestalg"/"$manifestval"
test -s $TEST_SCRATCH_DIR/implicit-rewritten/blobs/"$configalg"/"$configval"
# check timestamps in the one we didn't force: find the manifest's and config's digests
manifestdigest=$(oci_image_manifest_digest "$TEST_SCRATCH_DIR"/default)
manifestalg=${manifestdigest%%:*}
manifestval=${manifestdigest##*:}
configdigest=$(oci_image_config_digest "$TEST_SCRATCH_DIR"/default)
configalg=${configdigest%%:*}
configval=${configdigest##*:}
# check timestamps in the one we didn't force: read the image creation date
config="$TEST_SCRATCH_DIR"/default/$(oci_image_config "$TEST_SCRATCH_DIR"/default)
run jq -r '.created' "$config"
echo "$output"
assert $status = 0 "looking for the image creation date"
assert "$output" != "$datestamp" "unexpected creation date for image"
# check timestamps in the one we didn't force: read the image history entry dates
run jq -r '.history[-2].created' "$config"
echo "$output"
assert $status = 0 "looking for the image history entries"
jq '.history' "$config"
for line in "$lines[@]"; do
assert "$output" != "$datestamp" "unexpected datestamp for history entry"
done
# check timestamps in the ones we didn't force: extract the layer blob
layer="$TEST_SCRATCH_DIR"/default/$(oci_image_last_diff "$TEST_SCRATCH_DIR"/default)
rm -fr $TEST_SCRATCH_DIR/layer; mkdir -p $TEST_SCRATCH_DIR/layer
tar -C $TEST_SCRATCH_DIR/layer -xvf "$layer"
# check timestamps in the ones we didn't force: walk the layer blob, checking timestamps
for file in $(find $TEST_SCRATCH_DIR/layer/* -print) ; do
run stat -c %Y $file
assert $status = 0 "checking datestamp on $file in layer"
assert "$output" != "$timestamp" "unexpected datestamp on $file in layer"
done
}
2025-06-21 03:05:20 +08:00
@test "commit-sets-created-annotation" {
_prefetch busybox
run_buildah from -q busybox
local cid="$output"
for annotation in a=b c=d ; do
local subdir=${annotation%%=*}
run_buildah commit --annotation $annotation "$cid" oci:${TEST_SCRATCH_DIR}/$subdir
local manifest=${TEST_SCRATCH_DIR}/$subdir/$(oci_image_manifest ${TEST_SCRATCH_DIR}/$subdir)
run jq -r '.annotations["'$subdir'"]' "$manifest"
assert $status -eq 0
echo "$output"
assert "$output" = ${annotation##*=}
done
for flagdir in default: timestamp:--timestamp=0 sde:--source-date-epoch=0 suppressed:--unsetannotation=org.opencontainers.image.created specific:--created-annotation=false explicit:--created-annotation=true ; do
local flag=${flagdir##*:}
local subdir=${flagdir%%:*}
run_buildah commit $flag "$cid" oci:${TEST_SCRATCH_DIR}/$subdir
local manifest=${TEST_SCRATCH_DIR}/$subdir/$(oci_image_manifest ${TEST_SCRATCH_DIR}/$subdir)
run jq -r '.annotations["org.opencontainers.image.created"]' "$manifest"
assert $status -eq 0
echo "$output"
local manifestcreated="$output"
local config=${TEST_SCRATCH_DIR}/$subdir/$(oci_image_config ${TEST_SCRATCH_DIR}/$subdir)
run jq -r '.created' "$config"
assert $status -eq 0
echo "$output"
local configcreated="$output"
if [[ "$flag" =~ "=0" ]]; then
assert $manifestcreated = $configcreated "manifest and config disagree on the image's created-time"
assert $manifestcreated = "1970-01-01T00:00:00Z"
elif [[ "$flag" =~ "unsetannotation" ]]; then
assert $configcreated != ""
assert $manifestcreated = "null"
elif [[ "$flag" =~ "created-annotation=false" ]]; then
assert $configcreated != ""
assert $manifestcreated = "null"
else
assert $manifestcreated = $configcreated "manifest and config disagree on the image's created-time"
assert $manifestcreated != ""
assert $manifestcreated != "1970-01-01T00:00:00Z"
fi
done
}