Commit Graph

76 Commits

Author SHA1 Message Date
Nalin Dahyabhai da4647bde3 Scrub user and group names from layer diffs
When generating layer diffs or extracting container contents, scrub the
user and group name fields in tar headers before saving them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-08-10 14:47:47 -04:00
Nalin Dahyabhai bb149ea686 Use errors.Is() instead of os.Is{Not,}Exist
If errors for which os.IsExist() or os.IsNotExist() would have returned
true have been wrapped using fmt.Errorf()'s "%w" verb, os.IsExist() and
os.IsNotExist(), not having been retrofitted to use errors.Is(), will
return false.

Use errors.Is() to check if an error is an os.ErrExist or os.ErrNotExist
error instead of calling os.IsExist() or os.IsNotExist().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-07-26 15:36:58 -04: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
Aditya R e80fed065e
docker-parity: ignore sanity check if baseImage history is null
Docker still builds image and adds history even if baseImage history is
null lets follow that

Signed-off-by: Aditya R <arajan@redhat.com>
2022-06-03 00:40:55 +05:30
Aditya R c61ecc6964
build, commit: allow disabling image history with --omit-history
As per `OCI` `image-spec` setting history is optional so buildah must
support these use-cases via `--omit-history=true` some of the use-cases
are discussed below.

* There are use-cases when image-spec contributes to the image size by
  adding build history to image-spec in certain use-cases this image
history is not required by the end-users but there is no way to remove
it. See: https://github.com/containers/buildah/issues/3513

* Certain build tools don't honor setting build history in image spec
  however buildah does not allow processing images without build history
since setting build history is still optional as per `OCI` image-spec
( https://github.com/opencontainers/image-spec/blob/main/config.md#properties)
so buildah must support such use-cases.

Closes: https://github.com/containers/buildah/issues/4025
Closes: https://github.com/containers/buildah/issues/3513

Signed-off-by: Aditya R <arajan@redhat.com>
2022-06-03 00:40:48 +05:30
Aditya R d0336f2147
buildkit: add support for custom build output with --output
Allows end-users to export final build content or rootfs to external formats.

By default, a local container image is created from the build result. The --output (or -o) flag allows you to override this behavior, and a specify a custom exporter. For example, custom exporters allow you to export the build artifacts as files on the local filesystem instead of a Container image, which can be useful for generating local binaries, code generation etc.

The value for --output is a CSV-formatted string defining the exporter type and options. Currently, local and tar exporters are supported. The local exporter writes the resulting build files to a directory on the client side. The tar exporter is similar but writes the files as a single tarball (.tar).

```console
buildah build --output type=local,dest=dir .
buildah build --output type=tar,dest=rootfs.tar .
buildah build -o dir .
```
Reference: https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs

Signed-off-by: Aditya R <arajan@redhat.com>
2022-04-29 21:44:38 +05:30
Nalin Dahyabhai 785b3bf30a image: set MediaType in OCI manifests
In image-spec 1.0.2, the MediaType field is now available in OCI
manifests, so set it.

Update the imgtype helper to output the MediaType field as-is from OCI
image manifests instead of just always supplying the expected value.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-11-29 20:04:09 -05:00
Daniel J Walsh c9c5f546c6
Fix UnsetEnv for buildah bud
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-19 11:48:29 -05:00
Daniel J Walsh a5d9f1cb28
Add --unsetenv option to buildah commit and build
This option will allow users to remove environment variables from the
final image.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-09 16:17:21 -05:00
Kurt Kartaltepe e80730ae3f Avoid rehashing and noop compression writer
When creating a new image we can avoid hashing before and after compression
when we know compression will not be used. This significantly improves speed
for hashing large containers with --compress=false

There should be no functional differences so tests are not
changed/added.

[NO NEW TESTS NEEDED]

Signed-off-by: Kurt Kartaltepe <kkartaltepe@google.com>
2021-08-31 14:56:08 -07:00
Nalin Dahyabhai ff1f9a3ee0 containerImageRef/containerImageSource: don't buffer uncompressed layers
Instead of extracting layer content to a temporary file when we're
committing to transports that aren't containers-storage, record the ID
of a layer and the uncompressed size it has recorded for its contents.

When later asked for a blob, if we cached a layer ID and size, generate
the layer diff on the fly, otherwise check for a file named after the
digest of the requested blob in our cache directory location (usually
used for new layers that we're adding) and the supplemental location
(which can be supplied by a caller).

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-05-25 17:30:36 -04:00
Nalin Dahyabhai 75bdc649be containerImageRef(): squashed images have no parent images
Remove the parent image's ID from the config blob when we're squashing
the image, since after squashing, we share no layers or history with
what was once our base image, and leaving it set triggers verification
errors in registries that expect consistency between parent IDs and
perhaps layers and history.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-05-21 17:13:38 -04:00
Daniel J Walsh 08201577e5
Remove some stuttering on returns errors
Golangs os.* functions return the name of the file/directory they
fail to use.  We should not wrap these errors with the file/directory
to use names, causes stuttering when the user sees the errors, and looks
bad having huge error messages.

Since this is just code cleanup, existing tests should handle the
changes.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-04-03 06:03:13 -04:00
Giuseppe Scrivano 25a0e2c754
image: propagate errors from extractRootfs
every error from copier.Get was previously lost and not propagated
back.  That caused the caller to believe the operation was successful
and lead to incomplete images on errors.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-03-12 14:29:03 +01:00
Daniel J Walsh 514a3f1a91
Shrink the vendoring size of pkc/cli
This PR removes the pkg/auth which brings in docker/docker
since it really is not needed, and was only there to help users
discover the settings of where the authfile was, when the environment
variables were set.  Would almost never be of any value.

Move imagebuildah.BuildOptions to define.BuildOptions

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-03 14:18:35 -05:00
Ashley 021ae2f64a
Merge branch 'master' into history 2021-02-16 16:02:40 -05:00
Diego b870be611d Add base image name to comment
Add the name of the base image being used by the build
in the comments of the first layer created.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2021-02-15 16:31:41 -05: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
Hironori Shiina 073f90bd83 Compute diffID for mapped-layer at creating image source
If UID and GID mappings are specified, the container has a
mapped-layer, whose diffID is not computed when created.
Committing the image fails due to lack of diffID. This fix
computes diffID at creating an image source if a layer
doesn't have a diffID (UncompressedDigest).

This fix also tests if a container with UID and GID mappings
can be committed.

Signed-off-by: Hironori Shiina <shiina.hironori@fujitsu.com>
2020-11-17 13:58:51 +09:00
Daniel J Walsh 39f4cfb79d
Stop excessive wrapping
Golang built in functions like os.Create and others print the name of
the file system object when they fail.  Wrapping them a second time
with the file system object, makes the error message look like crap
when reported to the user.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-15 14:03:13 -04:00
Nalin Dahyabhai 27bed70688 containerImageRef.NewImageSource(): don't always force timestamps
Avoid forcing the timestamps on content in new layers to the current
time when a timestamp is not specified.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-08-31 17:09:10 -04:00
Daniel J Walsh b715fb86ee
Use --timestamp rather then --omit-timestamp
We recieved feedback on the --omit-timestamp that
users would rather specify the timestamp seconds
rather then just use EPOCH.

This PR removes --omit-timestamp from buildah bud
since this has never been released.

We also hide --omit-timestamp from buildah commit
and allow users to continue to use it, but it conflicts
with --timestamp.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-28 05:23:41 -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 8bb100be2a
Add --omit-timestamp flag to buildah bud
Currently you can only do deterministic builds with commit command
this change will cause the metadata in the container image to be
epoch 0.

Next step is to save the data in the tar balls as 0.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-11 05:28:41 -04:00
zvier 9be668b2dd
fix error info about get signatures for containerImageSource
Remove these error checks since the instanceDigest is not used
and can just be ignored.

Signed-off-by: zvier <liuzekun0524@163.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-05-08 08:58:10 -04: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 1e6a70c1c2 commit(docker): always set ContainerID and ContainerConfig
For the sake of the Docker output format, always set the ContainerID
field, and if we have a non-nil Config, set ContainerConfig to the same
values.

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

Closes: #1989
Approved by: rhatdan
2019-11-20 14:27:55 +00:00
Nalin Dahyabhai 0817460525 Update for manifest-lists API changes in containers/image
Update the blobcache implementation to match API changes to the image
library.

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

Closes: #1902
Approved by: rhatdan
2019-10-28 15:15: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 cc80ccc252 makeImageRef: ignore EmptyLayer if Squash is set
If Squash is set, then we're only committing one layer, so if EmptyLayer
is set, which would normally tell us to skip committing the final layer,
we should ignore the EmptyLayer flag.

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

Closes: #1839
Approved by: TomSweeneyRedHat
2019-09-04 23:00:41 +00:00
Sascha Grunert 7eb4e5972d
Add goimports linter and apply fixes
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-07-18 10:42:46 +02:00
Nalin Dahyabhai 4ae0e14ea8 image: make sure we don't try to use zstd compression
Don't try to use zstd to compress layers until we know what MIME type to
use to describe layers that are compressed with zstd.

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

Closes: #1723
Approved by: TomSweeneyRedHat
2019-07-18 01:55:56 +00:00
Nalin Dahyabhai 3bdc9edd67 imagebuildah: handle ID mappings for COPY --from
Fix handling of ID mapping for COPY: when copying from other containers,
use their mappings, and when copying from the host, use host mappings.

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

Closes: #1630
Approved by: TomSweeneyRedHat
2019-06-06 13:11:25 +00:00
Nalin Dahyabhai bc53b5d980 commit: commit on every instruction, but not always with layers
When building an image with multiple layers, go back to committing
images for instructions for which we previously wouldn't bother
committing an image, but create them without adding a new layer.

This violates some assumptions that we currently make elsewhere, as it's
possible for an image that's derived from a base image to add no layers
relative to the base image, when previously it was always the case that
we'd add at least one whenever we committed it.

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

Closes: #1539
Approved by: rhatdan
2019-04-25 19:11:26 +00:00
Nalin Dahyabhai 5c068beb85 makeImageRef: pass in the whole CommitOptions structure
Instead of passing in an increasing number of the fields of
CommitOptions to makeImageRef(), just pass the whole thing.

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

Closes: #1539
Approved by: rhatdan
2019-04-25 19:11:26 +00:00
Nalin Dahyabhai 810efa340a commit: always set a parent ID
Always set a parent ID when we go to commit an image, whether it's as
part of build-using-dockerfile or our "commit" CLI.  Coerce the parent
image's ID directly into the value that we use instead of digesting it
again.

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

Closes: #1538
Approved by: vrothberg
2019-04-23 08:25:37 +00:00
Nalin Dahyabhai d6340f18c1 commit: set created-by to the shell if it isn't set
Set the CreatedBy field of the new image's new history item to the shell
if we don't have a different value to set.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-04-03 15:16:36 -04:00
Johannes Brüderl 4bcddb7cbe cmd/commit: add flag omit-timestamp to allow for deterministic builds
By default, a field called "createdAt" is written into the image manifest.
However, even if my image build process is perfectly deterministic, the image
sha256 hash will be different every time, even if my sources are exactly the
same. In many cases it is desirable that the same input results in the exactly
same output.
This commit introduces the flag --omit-timestamp to the commit command. If set to
true, the timestamp is set to epoch 0, instead of the current timestamp (which
causes different results every time commit is invoked).

Signed-off-by: Johannes Brüderl <johannes.bruederl@gmail.com>

Closes: #1294
Approved by: nalind
2019-01-21 19:54:07 +00:00
Nalin Dahyabhai 23ed59594b Add options for empty-layer history entries
Add configuration methods for adding entries which will show up in a
committed image's history, both before and after the new layer that we
add while committing the image.  Expose them from the CLI in the form of
a new --add-history option for the "add", "config", "copy", and "run"
commands.

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

Closes: #1300
Approved by: rhatdan
2019-01-21 19:11:21 +00:00
Valentin Rothberg 08e942383b vendor parallel-copy from containers/image
Parallel copying of layers is currently supported when pulling from
a registry to the storage.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-01-04 17:23:09 +01:00
Miloslav Trmač b77856eae3 Update for API changes
NOTE: This is a very minimal update; blobinfocache.go should be
substantially reworked to benefit from the cache instead of decompressing
layers to get the DiffID values.

Also removes some HasBlob checks in the blobinfocache test suite which don't have
a direct equivalent in the new API, and makes the test suite independent
of host's signature policy.

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

Closes: #1218
Approved by: rhatdan
2018-12-07 15:11:36 +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
TomSweeneyRedHat 1e4d1eb31e Remove no longer valid todo
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #1115
Approved by: rhatdan
2018-10-19 21:29:49 +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 7ce41914c9 NewImageSource(): only create one Diff() at a time
Update github.com/containers/storage and github.com/containers/image,
and modify containerImageRef.NewImageSource() to account for the change
that the ReadCloser that store.Diff() returns now holds a lock until
it's closed, and because that's the same lock that store.PutLayer()
takes, we can't read more than one layer's contents at a time.

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

Closes: #1024
Approved by: nalind
2018-09-27 13:32:50 +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
TomSweeneyRedHat 9af14c4540 Use manifest from container/image
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #870
Approved by: rhatdan
2018-07-19 15:42:01 +00:00
Daniel J Walsh a2c8358455 Vendor in latest containers/image and containers/storage
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #869
Approved by: rhatdan
2018-07-19 15:12:57 +00:00
umohnani8 6c4bef7f2e Add --layers and --no-cache to buildah bud
This patch adds in the caching feature to buildah bud.

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

Closes: #784
Approved by: rhatdan
2018-06-12 20:20:39 +00:00