Commit Graph

37 Commits

Author SHA1 Message Date
Daniel J Walsh 8d5d763213
Fix stutters
Podman adds an Error: to every error message. So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

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

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-19 07:11:44 -04:00
Aditya R f46ef3b2d7
buildah: support for --retry and --retry-delay for push/pull failures
Allows users to configure `--retry` attempts and `--retry-delay`
duration using two additional flags for commands

* buildah build
* buildah pull
* buildah push
* buildah from
* buildah add
* buildah copy

Closes: https://github.com/containers/buildah/issues/4018

Not sure how we can test retry attempts in CI, but added a test in
tests/bud.bats which verfies we parse and added flag in other options
for sanity parsing checking.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-08-23 12:31:01 +05:30
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
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
Nalin Dahyabhai 44a129f586 copier.Get(): try to avoid descending into directories
When processing a directory tree, only descend into a directory that is
marked for exclusion if its path is literally a prefix of an exception
pattern.

Subtly, but in a way that's compatible with docker, this means that if
we exclude directory "subdir", but we've been told to also include
"**/file" (with an exclusion pattern of "!**/file"), we won't descend
into "subdir" and find a file named "subdir/file", because "**/file"
doesn't start with "subdir/".

More generally, exclusion patterns that start with "!" which include any
wildcards before their final component technically won't be treated
correctly.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-08-30 11:04:14 -04:00
Daniel J Walsh cfe911a3f0
Change references from master to main
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-23 11:03:24 -04:00
Nalin Dahyabhai dfe404f3de CLI add/copy: add a --from option
Add a --from option to `buildah add` and `buildah copy`, mirroring the
option for the Dockerfile instruction.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-04-08 13:21:26 -04:00
Hironori Shiina c94c412963 Add some system tests
The tests for following options are added.
- buildah add --quiet
- buildah containers -a
- buildah containers --notruncate
- buildah copy --quiet
- buildah from --memory-swap
- buildah from --authfile
- buildah from --cap-add/--cap-drop
  (imitating buildah run --cap-add/--cap-drop)
- buildah --from --ulimit
- buildah run --user

Signed-off-by: Hironori Shiina <shiina.hironori@jp.fujitsu.com>
2021-03-01 14:02:38 -05:00
Jakub Guzik 88301c85d4 buildah add/copy --chmod cli implementation for files and urls
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
2021-02-24 08:37:25 +01:00
Daniel J Walsh fde2597af8
Add --ignorefile flag to use alternate .dockerignore flags
Allow users to override location of the .dockerignore file.
If user specified an --ignorefile flag, buildah will read the
file and pass in the exclude lines based on the .dockerignore
contents.

Also add a --contextdir flag to buildah copy and buildah add to
specify where the context directory is located.  For these two
commands the --ignorefile flag requires the --contextdir flag.

When the --ignorefile flag is passed in, the .dockerignore files
in the context directory will be ignored.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-11-24 15:28:07 -05:00
Nalin Dahyabhai ff8cfe7c3f Add(): fix handling of relative paths with no ContextDir
Add() is supposed to handle relative paths when the ContextDir value
passed to it is not set, but it hasn't been doing that correctly since
it was overhauled.  Correct it to recognize relative paths at the
function start, when ContextDir is not set, by combining them with the
current directory to convert them to absolute paths.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-09-16 14:19:10 -04:00
Nalin Dahyabhai 3835460c3b Use pipes for copying
Use the copier package to rework how we handle ADD and COPY.

When evaluating cache for content that's being copied/added in, switch
from (digest the data, check for a cache entry, then maybe copy the data
and create the new layer) to (copy the data and create the new layer,
digesting as we go, check for a cache entry, either commit or discard
the new layer).

Use the copier package for ADD, COPY, and for ensuring that a specified
directory exists in the working container's rootfs.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-08-21 12:34:00 -04: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 77db7f959e BATS major cleanup: part 4: manual stuff
This is the manual part of the cleanup.

  - remove most 'buildah rm's from cleanup steps
  - remove unused variables
  - use expect_output when possible, not 'test [ x = y ]'
    - includes fixing some not-what-you-think-it-is uses
      of run_buildah | grep
  - be careful not to leave droppings in current directory

Special attention to:

  - authenticate.bats: create Dockerfile in temp dir, not pwd!
  - push.bats: remove broken output check
  - registries.bats: refactor, remove duplicate tests & code
  - rmi.bats: better checking of messages
  - secrets.bats: use TESTDIR (tmp), not TESTSDIR (/usr/share) !
    We don't want to leave droppings behind if we fail; this has
    bitten us before. And, since there's only one test, there's
    no need to override setup() / teardown(). Do setup inline,
    and take advantage of existing defaults.

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

Closes: #2029
Approved by: rhatdan
2019-12-17 18:16:45 +00: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
Yiqiao Pu aa35502984 Test: Get permission in add test
The permission may different in different system. Not always a fix
value. So update the scripts to get the permission during the test.

Signed-off-by: Yiqiao Pu <ypu@redhat.com>

Closes: #2004
Approved by: rhatdan
2019-12-04 01:56:01 +00:00
Yiqiao Pu 3e26f9e073 Tests: Add two test for buildah add
Add following tests for buildah add
1. buildah add test with --chown
2. buildah add url test

Signed-off-by: Yiqiao Pu <ypu@redhat.com>

Closes: #2004
Approved by: rhatdan
2019-12-04 01:56:01 +00:00
Ed Santiago 0b1ec142a0 Actual bug fix for 'add' test: fix the expected mode
Well, yikes: fix a broken file-mode check in two 'add' tests.
They were expecting 755, but the actual mode is 644. --debug
was spitting out unrelated output, including a 755 that
the test was matching as a substring.

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

Closes: #1935
Approved by: giuseppe
2019-10-30 11:45:12 +00:00
Eric Hripko 9d2907c4de Create directory paths for COPY thereby ensuring correct perms
Signed-off-by: Eric Hripko <ehripko@bloomberg.net>

Closes: #1615
Approved by: rhatdan
2019-06-09 09:08:29 +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
Boaz Shuster ab9547f1eb Add flags/arguments order verification to other commands
This is the third part of adding flags/args order verficiation.
In this part I am adding it to command lines that take no
arguments or more than 1 arguments such as buildah-images.

Added tests too to verify it works correctly.

Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>

Closes: #1002
Approved by: rhatdan
2018-09-13 12:13:12 +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
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 ce254f51fc Tweak ADDing/COPYing directories to copy contents
When copying or adding a source directory, copy the directory's contents
to the destination directory, to better match Dockerfile COPY behavior.

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

Closes: #50
Approved by: rhatdan
2017-03-28 19:42:47 +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 547afe50a0 Remove --destination flag from `buildah add|copy`
We need to match the syntax of Dockerfile, three forms

buildah copy $CID SOURCE
buildah copy $CID SOURCE DESTINATION
buildah copy $CID SOURCE SOURCE SOURCE DESTINATION

Closes: #40
Approved by: nalind
2017-03-24 22:50:34 +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 8bbc3a5a9c Tweak copying behavior so that dest can be a file
Change copy behavior so that the destination can be a file rather than a
directory if we're copying a single item.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-23 17:28:51 -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 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 3b44a3e3b3 Simplify copy/add logic to better match dockerd's
Simplify our implementation of copy/add to always assume that the
destination location will be a directory.  Trying to be cleverer, like
cp is, would just be confusing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-03-07 13:26:17 -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