Commit Graph

33 Commits

Author SHA1 Message Date
Chris Evich 313ada6b7a
[release-1.29] Add conditional release-checking system test
Unfortunately on a number of occasions, Buildah has been released
officially with a `-dev` suffix in the version number.  Assist in
catching this mistake at release time by the addition of a simple
conditional test.  Note that it must be positively enabled by a
magic env. var. before executing the system tests.

Ref: original PR https://github.com/containers/buildah/pull/6243

Signed-off-by: Chris Evich <cevich@redhat.com>
2025-07-02 15:19:14 -04:00
Ed Santiago a75b263f75 system tests: remove unhelpful assertions
Regular primitive bats uses assertions like '[ $foo = something ]'.
These are worthless for debugging: when they fail, all you know
is that foo is not "something" but you don't know what foo _is_.

Find and replace those assertions with 'assert', which is
more informative. Instances found via:

   $ ack '^ *\[' tests/*.bats

There are many matches for 'test' (instead of '[') but those
mostly look like file-existence ones, which are less evil
than string-check tests. I'm leaving those be for now.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2023-01-05 08:20:25 -07:00
Ed Santiago 552d09b272 Rename $TESTSDIR (the plural one), step 4 of 3
...rename $TESTDIR (the singular one) to $TEST_SCRATCH_DIR,
which is clearer but unfortunately longer

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-04-26 09:11:22 -06:00
Ed Santiago 267f309911 Rename $TESTSDIR (the plural one), step 1 of 3
...refactor '--signature-policy .../policy.json' to $WITH_POLICY_JSON

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-04-26 09:11:05 -06:00
Ed Santiago 2637df51e9 Don't pollute
Several tests were doing '--iidfile x', where 'x' is a filename
with no path. This is super bad: if running as root, it leaves
litter in the current directory. If rootless, it may throw EPERM.
Clean those up, using $TESTDIR for each one.

Tested by running the test suite on my laptop and confirming
there are no more droppings.

And, refactor one particularly hairy set of duplicated build
incantations: make them a series of simple clean loops.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-03-23 11:17:37 -06:00
Aditya R 0b8c6ca49f
test: remove skips for rootless users
Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-09 21:36:04 +05:30
Aditya R d27b883709
tests: skip tests for rootless which need unshare
Instrument test so that they can be executed in rootless environment.

Certain tests perform mount directly and they need a seperate
usernamespace, these tests are marked to be skipped for `rootless
environment`

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-08 15:08:03 +05:30
Valentin Rothberg 2301d148da --iidfile: print hash prefix
Prefix the image ID with the hash prefix when using `--iidfile` to be
compatible with Docker.  The absence of the hash can cause
docker-compose to error out.

Reported-in: github.com/containers/podman/issues/9260
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-08 12:24:56 +01:00
Daniel J Walsh 2f671a26b2
Return exit code from failed containers
Buildah run was exiting with the correct exit code, when a container
failed.  Buildah bud was not, so this should fix this.

Also switched to the proper exit codes when containers fail.  When
Buildah fails to execute it will exit with a 125 exit code like
Podman does.  If a command fails to execute inside of a container
we will exit with a 126. Currently we do not support the 127 for
exiting when the command does not exist.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-04-20 11:24:52 -04:00
Ed Santiago 0f5fd98218 Flake handling: cache and prefetch images
Show of hands: who here loves submitting a PR, then coming back
hours later to find one job failed, then spending time poring
over logs and finding a network error? Anyone? Anyone?

This is a lame attempt to minimize such flakes by caching
commonly-used images and restoring them on demand. We
introduce a new helper, _prefetch(), which podman-pulls
an image the first time, podman-saves it, then on
subsequent calls (for the same image) podman-loads it:

    @test foo {
        _prefetch alpine busybox
        ...tests that run buildah-from either
    }

This is an imperfect solution: it is incomplete and will
grow more so over time as new tests are added. It is
difficult to verify its coverage. I'm really unhappy
with it but if it works, the Total Sum Of Unhappiness
might decrease overall thanks to fewer flakes. If it
doesn't work, it's trivial to remove _prefetch calls
using a sed script. Shall we give it a chance?

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-02-06 08:16:02 -07:00
Ed Santiago 6063bff02a BATS major cleanup, step 3: yet more run_buildah
Replace plain 'buildah' invocations with run_buildah

For ease of review, this commit was entirely machine-generated via:

   $ perl -pi -e 's/^(\s+)buildah(\s)/${1}run_buildah${2}/' *.bats

Signed-off-by: Ed Santiago <santiago@redhat.com>

Closes: #2029
Approved by: rhatdan
2019-12-17 18:16:45 +00:00
Ed Santiago 229b18f6a8 BATS major cleanup, part 2: use more run_buildah
Replace this pattern:

       cid=$(buildah ...)
with:
       run_buildah ...
       cid=$output

As a special case, if the buildah command is 'from' and the
string 'scratch' does not appear in the arguments, add '--quiet'.
Otherwise we'll get Pulling messages as part of $output. This
is an overkill solution.

For ease of review, this commit was entirely machine-generated via:

   $ perl -pi -e 's{^(\s+)(\S+)=\$\(buildah (.*)\)$}{$indent=$1;$var=$2;$cmd=$3; $cmd =~ s/(\bfrom)\s(?!.*scratch)/$1 --quiet $2/; "${indent}run_buildah $cmd\n$indent$var=\$output"}e' *.bats

Signed-off-by: Ed Santiago <santiago@redhat.com>

Closes: #2029
Approved by: rhatdan
2019-12-17 18:16:45 +00:00
Ed Santiago dee4b68ef0 BATS major cleanup, part 1: log-level
PR #1935 removed the default --debug logging; so all run_buildah
calls now use the default (error). It is safe to remove unnecessary
instances of --log-level=error .

For ease of review, this commit was entirely machine-generated via:

    $ perl -pi -e 's/ --log-level=error / /' *.bats

Signed-off-by: Ed Santiago <santiago@redhat.com>

Closes: #2029
Approved by: rhatdan
2019-12-17 18:16:45 +00:00
TomSweeneyRedHat 89bc2a6a6a Fix --pull=true||false and add --pull-never to bud and from (retry)
(Replaces #1873 as it had lint issues that were timing out tests that I couldn't
track down easily)

Prior to this fix, if someone did `buildah bud --pull=false .` and the image in
the Containerfile's FROM statement was not local, the build would fail. The same
build on Docker will succeed. In Docker, when `--pull` is set to false, it only
pulls the image from the registry if there was not one locally. Buildah would never
pull the image and if the image was not locally available, it would throw an error.
In certain Kubernetes environments, this was especially troublesome.

To retain the old `--pull=false` functionality, I've created a new `--pull-never`
option that fails if an image is not locally available just like the old
`--pull=false` option used to do.

In addition, if there was a newer version of the image on the repository than
the one locally, the `--pull=true` option would not pull the image as it should
have, this corrects that.

Changes both the from and bud commands.

Addresses: #1675

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #1959
Approved by: rhatdan
2019-11-06 22:20:24 +00:00
Sascha Grunert 567141716e Add `--log-level` command line option and deprecate `--debug`
The previous log-level implementation does not seem to work, which is
now fixed and aligns to other projects like podman and CRI-O. Therefore
the `--debug` flag has been deprecated and is now hidden.

Added documentation as well as integration tests.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>

Closes: #1811
Approved by: rhatdan
2019-08-29 12:49:11 +00:00
Ed Santiago 021d607282 rename 'is' to 'expect_output'
...and make the "$output" argument implicit, as well as the
description text. This greatly simplifies its invocation.

Also: make it test for exact matches unless --substring
option is passed; this eases my mind about a few potentially
ambiguous situations such as the one in #1464.

Also: add comments to two truth-table check functions

Also: reorder some config checks alphabetically, for ease
of reading.

Thanks to Tom Sweeney for the suggestions and encouragement.

Signed-off-by: Ed Santiago <santiago@redhat.com>

Closes: #1492
Approved by: rhatdan
2019-04-09 12:04:53 +00:00
Ed Santiago 6ecc6d6cb4 BATS tests - extensive but minor cleanup
This started off as bug fixes necessary to get BATS tests
actually working on RHEL8 (they weren't). It grew. I will
defend my actions in the first comment post.

Primary change: import some helpers from podman BATS tests,
most importantly 'run_buildah' and 'is'. The vast majority
of the changes you'll see here are of the form:

    - run buildah ...
    - [ $status = 0 ]
    - [ check $output ]
    + run_buildah ...            ! automatically checks status
    + is "$output" "..."

Also: chmod'ed some files -x. Necessary because rpmbuild tries
to be oh-so-clever about requirements, and when it sees an
executable file with a shebang line like '#!env bats' it
helpfully adds 'Requires: /usr/bin/bats' to the rpm, which
then fails to install because RHEL8 does not have bats.

Also: refactored duplicate code in a few places, by writing
and invoking module-specific helper functions.

Also: changed a handful of 'buildah's to run_buildah, in
order to get error checking and debug logging.

Also: added descriptive reasons to many "skip"s.

Also: selinux test: some tweakery to make it run on production
system (context is different if /usr/bin/buildah is chcon'ed
appropriately). I can't get this test to pass on Fedora from
a build dir, and I'm actually not convinced that this test
has ever passed, but let's see what CI shows.

Also: selinux test: skip broken test (#1465).

Also: version test: skip parts of it if running w/o sources.

Tests are now passing as root on RHEL8; rootless has numerous
failures which I don't believe are related to this PR.

Signed-off-by: Ed Santiago <santiago@redhat.com>

Closes: #1472
Approved by: TomSweeneyRedHat
2019-04-06 16:25:42 +00:00
umohnani8 d93c6886ac Fix rmi to remove intermediate images associated with an image
buildah rmi now removes cached images associated with an image
when the image is removed only if the cached image is not required
by another image.
If an image is a parent and has a name then untag, otherwise return
an error stating the image can't be remoed as it has dependent
child images.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #871
Approved by: rhatdan
2018-08-03 19:05:44 +00:00
TomSweeneyRedHat ba976ed310 Return policy error on pull
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #881
Approved by: rhatdan
2018-08-03 17:29:14 +00:00
Daniel J Walsh 3088277ee8 Add support for --iidfile to bud and commit
Add support for an --iidfile which specifies the file to write the
image id, when committing a new image.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #636
Approved by: TomSweeneyRedHat
2018-04-26 12:19:43 +00:00
Daniel J Walsh b75bf0a5b3 Currently buildah run is not handling command options correctly
This patch will allow commands like

buildah run $ctr ls -lZ /

To work correctly.

Need to update vendor of urfave cli.

Also changed all commands to no longer accept global options after the COMMAND.
Single boolean options can now be passed together.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #493
Approved by: rhatdan
2018-02-27 12:08:45 +00:00
Nalin Dahyabhai 0df1c44b12 tests: check $status whenever we use run
Always be sure to check $status after using the run helper.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #313
Approved by: rhatdan
2017-11-10 09:58:08 +00:00
Daniel J Walsh dd98523b8d Add flag to remove containers on commit
I think this would be good practice to eliminate wasted disk space.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Dan Walsh <dwalsh@redhat.com>

Closes: #189
Approved by: rhatdan
2017-07-17 19:07:21 +00:00
Nalin Dahyabhai 933a4a1107 Broaden what "rmi" can accept, and add tests
Teach "rmi" to handle arbitrary image references and incomplete
references, and add tests for both.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #61
Approved by: rhatdan
2017-04-11 18:35:08 +00:00
Nalin Dahyabhai 2f6cc3ee21 Use "scratch" for tests where we never "run"
We can use "scratch" now as a source for building images, so speed
things up a bit by using it instead of pulling alpine in tests where it
isn't expected to affect the test result.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #55
Approved by: rhatdan
2017-03-29 07:52:32 +00:00
Nalin Dahyabhai 53f12844b2 Accept commit targets which are just store refs
Accept commit target names which don't include a transport name by
checking if they parse as valid containers-storage references after they
fail to parse as a general reference.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #49
Approved by: rhatdan
2017-03-28 19:33:07 +00:00
Nalin Dahyabhai fc27a56f12 Rename "list"/"delete" to "containers"/"rm"
Rename the "list" and "delete" commands to "containers" and "rm",
respectively, and add "images" and "rmi" counterparts for them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #32
Approved by: rhatdan
2017-03-28 17:59:09 +00:00
Nalin Dahyabhai 6715edfd18 Add some more options for Run
Add options to Run() for passing in additional environment variables,
overriding the default command, user, and working directory, and a flag
for controlling whether or not we attach to the host's network.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #46
Approved by: rhatdan

Closes: #39
Approved by: nalind
2017-03-28 15:53:18 +00:00
Daniel J Walsh c0b38746d3 Remove all --name and --root options
Also fix up buildah commit to require name and image
2017-03-24 14:05:25 -04:00
Nalin Dahyabhai 0d83d9ebfa Pull required flag values from the arguments list
When flags that we'd require be specified aren't, if there are command
line arguments, use their values as flag values.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-17 18:46:16 -04:00
Nalin Dahyabhai 6afcabc1aa Test looking up containers by name and root
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-15 17:29:18 -04:00
Nalin Dahyabhai 01a148a00b Fixup cleanliness in tests
Clean up the tests so that data files that we generate don't get dropped
in the root directory of the host, or in a part of ${TMPDIR} that we
won't clean up.  Add tests to exercise "add"'s extracting logic.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-07 15:54:51 -05:00
Nalin Dahyabhai 2160a9e803 Add some integration tests
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-06 18:47:51 -05:00