Commit Graph

73 Commits

Author SHA1 Message Date
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
Ben Parees add81c3de4 fix missing format param
Signed-off-by: Ben Parees <bparees@redhat.com>

Closes: #1083
Approved by: rhatdan
2018-10-12 19:22:46 +00:00
Nalin Dahyabhai bc2ea08003 Make sure we log or return every error
Make sure that when attempting to diagnose an error, if we encounter an
error during the diagnostic attempt, we return the original error rather
than the error encountered in trying to diagnose it.  Log that one.

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

Closes: #1072
Approved by: rhatdan
2018-10-07 12:07:09 +00:00
Nalin Dahyabhai 464a3e587f pullImage(): when completing an image name, try docker://
If we're handed a name for a source image, and
alltransports.ParseImageName() doesn't like it as-is, we normally try
prefixing the Transport option and parsing it again.  If that option
isn't set, though, we return an error, when we should be trying the
default ("docker"), which is how NewBuilder() does things.

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

Closes: #1072
Approved by: rhatdan
2018-10-07 12:07:09 +00:00
Nalin Dahyabhai 318fc8940f Enforce "blocked" for registries for the "docker" transport
Check if reading and writing from the registry named by an image is
allowed when the transport is "docker".

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

Closes: #1056
Approved by: rhatdan
2018-10-05 15:30:11 +00:00
Nalin Dahyabhai 62c01da3e4 Correctly set DockerInsecureSkipTLSVerify when pulling images
The image library's copy routine doesn't itself consult the registries
configuration in order to decide whether or not to disable TLS
verification when communicating with a registry, so it's on us to use
the name of a source or destination image to decide whether to set the
flag for that behavior.

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

Closes: #1056
Approved by: rhatdan
2018-10-05 15:30:11 +00:00
Daniel J Walsh ba012ddec6
Move buildah from projecatatomic/buildah to containers/buildah
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-09-18 08:06:11 -04:00
W. Trevor King 0d39b40e02 pull: Return image-pulling errors from pullImage
Instead of throwing out the upstream error message, save it and return
it if we can't come up with a more-specific suggestion.  This softens
the approach from 043fd2e3 (Add registry errors for pull,
2018-06-01, #747), because that could make debugging harder [1].

[1]: https://github.com/projectatomic/buildah/issues/849

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #1014
Approved by: rhatdan
2018-09-14 18:41:39 +00:00
Miloslav Trmač 344fbdc882 Remove an unused srcRef.NewImageSource in pullImage
- The result is not used anywhere
- In the common case of pulling from docker:// this does not do
  anything notable (only sets up configuration, no network checks)
- ... but it can be pretty expensive for compressed archives,
  creating an uncompressed on-disk copy.
- copy.Image soon after the removed code calls srcRef.NewImageSource
  internally anyway.

This should not change behavior on success; it may change which error is
reported if there is more than one reason for the pull to fail.

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

Closes: #922
Approved by: TomSweeneyRedHat
2018-08-10 20:31:27 +00:00
Nalin Dahyabhai 618bf54c74 Export a Pull() function
Provide a Pull() function that can be called directly, to go with the
Push() function.

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

Closes: #918
Approved by: rhatdan
2018-08-09 18:18:11 +00:00
TomSweeneyRedHat 338b23ea3e Revert pull error handling from 881
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #910
Approved by: rhatdan
2018-08-04 07:58:21 +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