Commit Graph

84 Commits

Author SHA1 Message Date
Nalin Dahyabhai fdf1c75cd3 linters: unused arguments shouldn't have names
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-07 10:10:35 -04:00
Aaron Lehmann 9521672fdb Document when BlobDirectory is overridden
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2024-05-27 10:50:27 -07:00
Aaron Lehmann e6c7949aa7 imagebuildah: Support custom image reference lookup for cache push/pull
This allows callers to provide custom SourceLookupReferenceFunc and
DestinationLookupReferenceFunc for cache pull/push. These can be used to
implement custom blob caches, and to wrap the reference being
pushed/pulled to influence the copy behavior.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2024-05-24 14:27:01 -07:00
Sascha Grunert ce384684c0
Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 11:41:47 +02:00
Hironori Shiina d92a4d8a5c Initialize network backend before first pull
After clean install, it is necessary to decide the network backend
before any image is pulled so that `netavark` is chosen correctly.
Without this change, if `buildah pull` is executed at first, the network
backend is not determined and an image is pulled. This results in
choosing `cni` at a next command because an image already exists while
`netavark` is chosen if `buildah from` or `buildah bud` is called at
first.

Signed-off-by: Hironori Shiina <shiina.hironori@jp.fujitsu.com>
2022-04-08 22:29:55 -04:00
Valentin Rothberg d9b3a185ca use c/image/pkg/blobcache
Buildah's pkg/blobcache has been moved into containers/image [1] to
consolidate implementations of interfaces such as image destinations
and image sources.

Since there are no functional changes: [NO NEW TESTS NEEDED]

[1] https://github.com/containers/image/pull/1459

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-02 09:55:16 +01:00
Valentin Rothberg a23a49b227 update to latest libimage
Update Buildah to the latest libimage.  Migrating Podman over to
libimage entailed a number of fixes and changes to libimage which
we need to account for in Buildah.

Most notably:

 * `(*Runtime).LookupImage()` now returns `storage.ErrImageUnknown`
   instead of `nil` in case no matching image is found.

 * `(*Runtime).LookupImage()` now does quite a bit more work finding
   a local image and will also look at the repotags (or digests) of
   all local images if needed.

 * The signature of `(*Runtime).RemoveImages()` was changed and now
   returns a slice of reports and errors.  The reports aggregate the
   data of a removed image which allows the function to be used by
   `podman image prune` which is also interested in the size of the
   removed data.  The slice of errors is also needed in Podman which
   needs to have a closer look at _all_ rmi errors in order to determine
   the appropriate exit code (Docker compat).

 * `libimage/types` has been removed.  Pull policies have been merged
   into already existing logic in `pkg/config`.

Please refer to containers/podman/pull/10147 for a more detailed
changelog.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-04 08:45:07 +02:00
Valentin Rothberg fb331c1861 restore push/pull and util API
Restore the push and pull API that commit dcd2a92e56 removed.
These changes would break vendoring into openshift/builder due
to build errors.

For the same reason, restore `util.FindImage` and `util.AddImageNames`
but deprecate the `findRegistry` argument.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-04-23 12:50:31 +02:00
Valentin Rothberg dcd2a92e56 use new containers/common/libimage package
Move all code related handling container image over to the new
`libimage` package in containers/common.  The new package is an
attempt to consolidate the code across the containers tools under the
github.com/containers umbrella.

The new `libimage` packages provides functionality to perform all kinds
of operations for managing images such as local lookups, pushing,
pulling, listing, removing, etc.

The following packages have been moved over the containers/common:

`manifests` -> `common/image/manifests`
`pkg/manifests` -> `common/pkg/manifests`
`pkg/supplemented` -> `common/pkg/supplemented`

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-04-22 17:39:00 +02:00
Daniel J Walsh 4704e6cb3f
Eliminate the use of containers/building import in pkg subdirs
We want to shrink the size of the import when importing pkg from
buildah. This should help us shrink the size of the golang bindings
in podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-12 12:43:08 -05:00
Daniel J Walsh c8f8b66bf7
Fix handling of TMPDIR environment variable
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1900822

Currently we are not passing the TMPDIR to the destination context
so when copying to containers storage we always fall back to /var/tmp.

This change sets the destination to match the source, so we can better
handle the storage.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-07 16:14:05 -05:00
OpenShift Merge Robot 11964fc3d0
Merge pull request #2754 from rhatdan/policy
Add --policy flag to buildah pull
2020-11-13 23:10:50 +01:00
Valentin Rothberg e1444dd71e short-names aliasing
Add support for short-name aliasing.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-11-13 11:58:48 +01:00
Daniel J Walsh f280cd0285
Add --policy flag to buildah pull
This allows the user to specify the pull policy for pulling images.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-11-13 03:38:27 -05:00
Qi Wang 2ddc22c2dd Skip tlsVerify insecure BUILD_REGISTRY_SOURCES
If the registry is set to insecure allowd using BUILD_REGISTRY_SOURCES, hardcode to skip the tls verify to avoid the errors.
Returns error if set insecureRegistries but force to use tls-verify.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-10-13 15:57:42 -04:00
Nalin Dahyabhai ad7cfc3e9b Heed our retry delay option values when retrying commit/pull/push
Pass our own API values for retry delays to common's retry package when
we use it to handle retrying image pull/commit/push operations.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-08-28 15:20:28 -04:00
Qi Wang cea59d97c9 Replace retry functions with common/pkg/retry
Use retry pacakge from containers/common and change the retryDelay to exponential backoff from there.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-08-13 15:28:56 -04:00
Brandon Lum 37df2b9690 implementation of encrypt/decrypt push/pull/bud/from
Signed-off-by: Brandon Lum <lumjjb@gmail.com>
2020-05-18 21:27:23 +00:00
Daniel J Walsh 8bcc55a5ee
Fix FORWARD_NULL errors found by Coverity
Error: FORWARD_NULL (CWE-476): [#def50]

These errors could lead to crashes in the code.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-10 10:16:14 -04:00
Nalin Dahyabhai b72bda2dff pull/from/commit/push: retry on most failures
If PullOptions/BuilderOptions/CommitOptions/PushOptions includes a
MaxRetries value other than 0, retry operations except for (currently)
connection-refused, authentication, and no-such-repository/no-such-tag
errors, at a default-but-configurable interval of 5 seconds.

Set the default for `buildah pull/from/commit/push` to 3 retries at 2
second intervals.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-02-10 14:07:10 -05:00
Daniel J Walsh 230ef7ac35
Close tarSource when finished using it
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-02-05 16:22:48 -05:00
Nalin Dahyabhai a925f79cc3 add --sign-by to bud/commit/push, --remove-signatures for pull/push
Add the --sign-by option to `buildah build-using-dockerfile`,
`buildah commit`, `buildah push`, and `buildah manifest push`.  Add the
`--remove-signatures` option to `buildah pull`, `buildah push`, and
`buildah manifest push`.  We just pass them to the image library, which
does all of the heavy lifting.

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

Closes: #2085
Approved by: rhatdan
2020-01-17 18:22:34 +00:00
Nalin Dahyabhai f0cf07bb60 Move to containers/image v5.0.0
Bump to containers/image's 5.0 release.

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

Closes: #1902
Approved by: rhatdan
2019-10-28 15:15:34 +00:00
Miloslav Trmač 797e618cbe Update c/image to v4.0.1
This requires updating all import paths throughout.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1891
Approved by: vrothberg
2019-10-04 07:34:03 +00:00
Nalin Dahyabhai 0bb4f3112c pull/commit/push: pay attention to $BUILD_REGISTRY_SOURCES
If $BUILD_REGISTRY_SOURCES is set, expect it to be a valid
github.com/openshift/api/config/v1.Image, and parse its
AllowedRegistries and BlockedRegistries lists when, pulling, committing,
or pushing images.

Override the local signature policy when committing or pushing an image
to ensure that local storage is always allowed.

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

Closes: #1787
Approved by: rhatdan
2019-08-29 18:42:16 +00:00
Sascha Grunert c1a2d4f46f Fix directory pull image names
This is a breaking change and modifies the resulting image name when
pull from an directory via `oci:...` or `dir:...`.

Without this patch, the image names pulled via a local directory got
prefixed with `docker.io/{library/}`, which is not correct.

We now use either the full path to the image, or the relative path as
image name, but prefixed with `localhost` to indicate that the image is
not being pulled from a remote location.

Fixes: https://github.com/containers/buildah/issues/1797

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

Closes: #1800
Approved by: nalind
2019-08-19 20:31:04 +00:00
Sascha Grunert 16e301031e Add unparam linter and apply fixes
This commit enabled the `unparam` linter and applies all reported issues.

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

Closes: #1719
Approved by: rhatdan
2019-07-16 21:21:32 +00:00
Valentin Rothberg 467983ce9f pull: check error during report write
Reported by golangci-lint.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Closes: #1678
Approved by: rhatdan
2019-06-19 11:33:36 +00:00
Nalin Dahyabhai 3bf8547fe7 Avoid fmt.Printf() in the library
Avoid calling fmt.Printf() to print things in library logic, which can't
be controlled or suppressed by callers.  Prefer returning values and
printing them in our CLI wrapper, as callers would.

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

Closes: #1596
Approved by: rhatdan
2019-05-16 23:19:49 +00:00
Douglas Schilling Landgraf be0c8d263b golint: make golint happy
should omit type ... from declaration of var ...; it will be
inferred from the right-hand side

Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>

Closes: #1426
Approved by: nalind
2019-03-20 20:49:33 +00:00
Daniel J Walsh 1ba9201f38 Remove mistaken code that got merged in other PR
Miloslav had some good comments on a previous commit.

https://github.com/containers/buildah/pull/1411

These changes address his issues by removing them.

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

Closes: #1412
Approved by: mtrmac
2019-03-18 21:14:30 +00:00
Daniel J Walsh 939de6f4d9 Allow rootless users to use the cache directory in homedir
Currently rootless podman attempts to write to /var/lib/containers/cache
and fails. This causes us to repeatedly push images that have already been
pushed.  This cache directory should be relative to the location of containers/storage
and not always stored in the same directory.

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

Closes: #1411
Approved by: TomSweeneyRedHat
2019-03-14 14:25:09 +00:00
Miloslav Trmač 95a5089061 Hard-code docker.Transport use in pull --all-tags
The code is already calling docker.GetRepositoryTags
immediately below, so the dependency already exists, and this
removes an unnecessary dependency on alltransports.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač 5946d06cb4 Use a types.ImageReference instead of (transport, name) strings in pullImage etc.
Use a typed value, to hopefully decrease further temptation to process strings
manually, and to avoid the unnecessary alltransports.ParseImageName which
resolveImage has already called.

This may change the strings used in some error/debug messages, which
now use transports.ImageName instead of the original input; the strings
should by definition have the same semantics.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač 0de7cac5a1 Don't throw away user-specified tag for pull --all-tags
Right now, we (conceptually unnecesarily) require an image with an existing
tag on the remote repository to list all other tags.

Given that, use the user-specified name:tag, if any, instead of discarding the
tag and requiring :latest to exist on the remote registry.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač 430f3dc0b4 CHANGES BEHAVIOR: Remove the string format input to localImageNameForReference
It should always be redundant with the reference itself; so,
use srcRef.StringWithinTransport() in the cases where we do
need to understand and hard-code the string syntax, after all.

Also improve the oci: format parsing a bit, to be robust
against including an image name.

NOTE: This might change the semantics a bit because StringWithinTransport
does not guarantee preserving the original string (e.g. paths
tend to be normalized not to contain symlinks).  Using local paths
as docker/distribution image names is conceptually so problematic
that this seems worth the code cleanup - but I might be wrong.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač 51c3d1d4b4 Don't try to parse imageName as transport:image in pullImage
Both callers now consistently pass the transport in the "transport"
parameter, so parsing imageName could only be incorrect.

This could possibly fix cases like pulling docker://dir:localpath,
and the debug log will no longer say
"error parsing image name %q, trying with transport %q: %v" on every pull attempt.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač 3f84d99643 Use reference.WithTag instead of manual string manipulation in Pull
Should not change behavior, except possibly failing early if the server
returns an invalid tag name.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač fa2a247388 Don't pass image = transport:repo:tag, transport=transport to pullImage
pullImage has a dedicated transport: parameter, don't pass the transport
in the image name as well. The semantics of the imageName parameter to
pullImage is now unambiguous.

Should not change behavior, pullImage was trying
alltransports.ParseImageName(imageName) first.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač 949709cd18 Fix confusing variable naming in Pull
The result of ParseImageName("docker://"...) is not a storageRef.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1361
Approved by: rhatdan
2019-02-27 14:07:22 +00:00
Miloslav Trmač c8727b4033 Fix a few issues found by tests/validate/gometalinter.sh
For some reason, the CI does not report any of these; on macOS
I see many more reports (including complaints about the standard
library), this only cleans up the trivial cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1365
Approved by: rhatdan
2019-02-25 10:27:46 +00:00
Daniel J Walsh 3531a2dfb5 Remove quiet option from pull options
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1319
Approved by: rhatdan
2019-02-20 19:31:09 +00:00
Daniel J Walsh fa71977101 Support oci layout format
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1319
Approved by: rhatdan
2019-02-20 19:31:09 +00:00
Daniel J Walsh f9e645a461 Fix pulling of images within buildah
Change references to Transfer to transfer to make it internal only.
It should be determined from the image specification and only determined
in one place.

Make buildah.Pull use registries.conf

Currently buildah pull does not resolve images based on registries.conf
This does not match the behaviour of buildah from or buildah bud

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

Closes: #1319
Approved by: rhatdan
2019-02-20 19:31:09 +00:00
TomSweeneyRedHat f1cec509e0 Add Quiet to PullOptions and PushOptions
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Add Quiet to the PullOptions and PushOptions structures.
If set to true output will be in 'quiet' mode.  This
will primarily be used by callers such as OpenShift.

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

Closes: #1302
Approved by: rhatdan
2019-01-23 20:40:14 +00:00
Zhou Hao 9a6a441f77 pull: add all-tags option
Add all-tags option to download all tagged images in the repository

After change:
```
➜  buildah git:(add-pull-all) ✗ ./buildah pull --all-tags busybox
Pulling docker://busybox:1-glibc
Getting image source signatures
Skipping fetch of repeat blob sha256:68d65759a692b254073928cce9b3da459b59ee063f4aeb217cd6bcdfac5f838b
Copying config sha256:755a2703667876f4259f24a3225ef503483953ef553fba8758406beefc2ce3f9
 1.46 KiB / 1.46 KiB [======================================================] 0s
Writing manifest to image destination
Storing signatures
755a2703667876f4259f24a3225ef503483953ef553fba8758406beefc2ce3f9
Pulling docker://busybox:1-musl
Getting image source signatures
Skipping fetch of repeat blob sha256:d900fc804a8829d0ea4db613927f60a28a1ef933aa1dbafdaab43630579646c2
Copying config sha256:3cc47384c4cb779466fe40182420bd90ba761a5f26f8564580a114bcd0dfa911
 1.46 KiB / 1.46 KiB [======================================================] 0s
Writing manifest to image destination
Storing signatures
3cc47384c4cb779466fe40182420bd90ba761a5f26f8564580a114bcd0dfa911
Pulling docker://busybox:1-ubuntu
```

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

Closes: #1263
Approved by: rhatdan
2019-01-09 20:05:43 +00:00
Nalin Dahyabhai 65707368d8 Use a blob cache when we're asked to use one
Add API hooks for designating locations to be used as blob caches when
pulling and pushing images.  When we commit read-only copies of
container layers for use in images, if we're using blob caching, store a
copy of the layer in the blob cache directory so that it can be found.

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

Closes: #1149
Approved by: rhatdan
2018-12-04 18:53:15 +00:00
Daniel J Walsh 4a6f4aeb6b
Resolve image names with default transport in from command
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-10-21 06:33:35 -04:00
Nalin Dahyabhai 189ebeccd7 Update for changes in the containers/image API
Copying an image now returns the manifest of the written image.  Return
the digest of that manifest, and a canonical reference, from our Commit
and Push APIs.

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

Closes: #1097
Approved by: rhatdan
2018-10-15 21:27:07 +00:00
Miloslav Trmač 6e0074eeed Move the "short name but no search registries" error handling to resolveImage
Use the value now returned by util.ResolveImage instead of trying to
recompute it.

Then drop the no longer used getRegistries.  (It might be reasonable
to split that part of util.ResolveImage to make it shorter; but it should
not ideally have any independent second-guessing callers.  So, just
keep the inlined one instead; that way we certainly don't break it.)

Also drop the no longer used hasRegistry.

CHANGES BEHAVIOR:
- Most notably, the "short name but no search registries" code
  has been broken for some time; pullImage was called with
  localhost/$shortname, which was a qualified name, so the
  specialized error handling was never attempted.
- Temporarily, the error handling in the "short name but no
  search registries" code trigers even if there were actually
  valid values to try (in practice there is always localhost/$shortname,
  and possibly also options.Registry/$shortname).  The next commit
  will improve it again.
- We now have more legitimate access to the original short name,
  so include it in the error message (it was technically available
  before, but using it was awkward).

NOTE: registriesConfPath is computed using the sysregistries
package, but actual access happens using the sysregistriesv2 package.
That should be cleaned up eventually.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #909
Approved by: rhatdan
2018-10-13 11:56:07 +00:00