Commit Graph

43 Commits

Author SHA1 Message Date
Nalin Dahyabhai 16680a4dfd modernize: use strings.CutPrefix/SplitSeq/FieldsSeq
Use the CutPrefix(), SplitSeq(), and FieldsSeq() functions from the
strings package when chopping up or iterating over parts of strings, per
golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-09-10 13:11:00 -04:00
Jan Kaluza a0a9ac6380 Switch common, storage and image to monorepo.
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-08-29 15:04:28 +02:00
Nalin Dahyabhai 7cecaa79ea pkg/cli.GenBuildOptions(): don't hardwire optional bools
Treat the five optional bool flags as optional bool values, allowing for
them to not be set if they weren't explicitly given on the command line.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-08-04 18:41:00 -04:00
Nalin Dahyabhai 5968d82047 build, commit: set the OCI ...created annotation on OCI images
When building or committing an image in OCI format, default to setting
the org.opencontainers.image.created annotation to the value used in the
image's config blob for the image's creation date. The behavior can be
controlled using the new --created-annotation flag.

Add --annotation and --unsetannotation flags to `buildah commit` which
mimic the same flags for `buildah build`.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-23 15:05:02 -04:00
flouthoc 47da2f29b2
build: add support for --inherit-annotations
Allows users to specify if they want to inherit annotations from base image
or not.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-06-13 12:28:12 -07:00
openshift-merge-bot[bot] 714f5ba2e5
Merge pull request #6195 from flouthoc/unsetanno
build,config: add support for `--unsetannotation`
2025-06-09 14:19:35 +00:00
Nalin Dahyabhai 865daceebb build: add --source-date-epoch and --rewrite-timestamp flags
Use $SOURCE_DATE_EPOCH as the default for the --source-date-epoch flag
to the "build" CLI.

When a source-date-epoch is set, we'll use it when writing new history
entries, force timestamps in data written for --output to the specified
timestamp, and populate a "SOURCE_DATE_EPOCH" ARG that we treat as
always being set, and which we don't complain about being left unused.
By default, this will not affect timestamps in newly-added layers.

Add a --rewrite-timestamp flag, which "clamps" timestamps in newly-added
layers to not be later than the --source-date-epoch value if the
--source-date-epoch flag is set, but has no effect otherwise.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-05 10:22:56 -04:00
flouthoc 83acf720d9
build,config: add support for --unsetannotation
Just like `--unsetlabel` add support for `--unsetannotation`.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-06-04 12:58:43 -07:00
Nalin Dahyabhai 3a85df003e build: allow --output to be specified multiple times
Allow --output to be specified multiple times for `buildah build`.
That's of limited usefulness right now, but as exporters get added, it
won't be, and it's better to provide the new multiple-values API field
sooner rather than later.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-05-21 09:53:04 -04:00
Aditya R a235033662
build: add support for inherit-labels
Allows users to specify if they want to inherit labels from base image
or not.

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-04-14 14:01:00 -07:00
Kir Kolyshkin 84a3905f61 Use slices.Contains
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 15:26:01 -07:00
Eng Zer Jun 59024c41ad
refactor: replace golang.org/x/exp with stdlib
These experimental packages are now available in the Go standard
library since Go 1.21:

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/maps -> maps [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.21#maps

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-01-24 00:27:55 +08:00
Nalin Dahyabhai ca3b80eb0f CI: enable the whitespace linter
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-15 16:09:25 -04:00
Nalin Dahyabhai a7098c776a imagebuildah: make traditional volume handling not the default
Make the traditional handling of volumes (where they're "frozen" and can
only be modified by ADD or COPY, which requires that we cache their
contents and save/restore them before/after RUN instructions) an option
that is not enabled by default.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-15 09:38:28 -04:00
Nalin Dahyabhai 5198af7d7c Add support for passing CDI specs to --device
Add support for using CDI to resolve `--device` devices for RUN
instructions during `buildah build`, `buildah from`, and `buildah run`,
as `podman run` does.

This generally requires that we stop resolving device specifications
(arguments passed to --device) earlier and deferring that until it's
time to run a process, because CDI wants to pick over those values,
modify a runtime spec to set up the ones that it knows about, and then
hand back the list of values that it doesn't know about.

We don't want to do a dry run of this during CLI processing because that
would create a window where the underlying hardware state could change,
and that could produce some hard-to-diagnose errors.

Being able to test this is going to require that we add the `--device`
flag to `buildah run` (`--security-opt` affects how we build the
container's layer, so it has to be done at `buildah from`).

The default configured devices list is pulled in by CLI flag processing
during `buildah from` and `buildah build`, so it doesn't also need to be
explicitly passed to `buildah run` or the internal Run() method.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-29 16:57:10 -04:00
Daniel J Walsh d0ffb9d374
Use retry logic from containers/common
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-28 09:44:33 -05:00
Nalin Dahyabhai 4f0b619dd2 Use golang.org/x/exp/slices.Contains
... instead of github.com/containers/common/pkg/util.StringInSlice,
per linters.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-02-07 11:50:41 -05:00
Nalin Dahyabhai cf69e8a187 build,commit: add --sbom to scan and produce SBOMs when committing
Add a --sbom flag to `buildah build` and `buildah commit` which will
scan the rootfs and specified context directories to build SPDX or
CycloneDX SBOMs and lists of package URLs.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-01-19 13:55:57 -05:00
Aditya R 8b63fa37bf
build,config: add support for --unsetlabel
Just like `--unsetenv` following flag allows to unset image label.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-09-27 10:27:54 +05:30
Nalin Dahyabhai e89fac6c9b Add `buildah mkcw`, add `--cw` to `buildah commit` and `buildah build`
Add a --cw option to `buildah build` and `buildah commit`, which takes a
comma-separated list of arguments and produces an image laid out for use
as a confidential workload:
  type: sev or snp
  attestation_url: location of a key broker server
  cpus: expected number of virtual CPUs to run with
  memory: expected megabytes of memory to run with
  workload_id: a distinguishing identifier for the key broker server
  ignore_attestation_errors: ignore errors registering the workload
  passphrase: for encrypting the disk image
  slop: extra space to allocate for the disk image

At least one of attestation_url and passphrase must be specified in
order for the encrypted disk image to be decryptable at run-time.  Other
arguments can be omitted.  ignore_attestation_errors is intentionally
undocumented, as it's mainly used to permit some amount of testing on
systems which don't have the required hardware.

Add an `mkcw` top-level command, for converting directly from an image
to a confidential workload.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-09-07 14:05:10 -04:00
Aditya R f888b3d84b
buildah: add --layer-label for setting labels on layers
`--layer-label` allows users to set labels on intermediate labels agnostic
of the labels set on actual image. Since there are use-cases where users
want to perform operation on intermediate images only on the basis of
certain labels.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-03 12:09:12 +05:30
Daniel J Walsh 6714a79eb0
Make cli.EncryptConfig,DecryptConfig, GetFormat public
We want to share these functions with Podman, Podman currently
has a slightly different version which is correct, so use correct
version in Buildah and vendor it into Podman.

Fixing: https://github.com/containers/podman/issues/18196

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-06-09 11:09:18 -04:00
Chris Bandy c95370cd3d build: pass process environment variables by reference
See: https://github.com/containers/buildah/issues/4688
Signed-off-by: Chris Bandy <bandy.chris@gmail.com>
2023-04-02 18:24:10 -05:00
Jack Wearden 3afa5ca74d build: accept arguments from file with --build-arg-file
Allows codifying build arguments into a structured file, perhaps one
named arguments.Containerargs

The build arg file also accepts comments starting #, so automated
tooling or CI/CD workflows can monitor arguments like versions to
ensure they are up-to-date.

Signed-off-by: Jack Wearden <jack@jackwearden.co.uk>
2023-03-25 11:04:23 +00:00
Daniel J Walsh 4dfb828909
Run codespell on codebase
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-02-09 09:05:03 -05:00
Daniel J Walsh 60be7f2509
Add support for --group-add to buildah from
Allow containers running under buildah to use
--group-add keep-groups, so that they can inherit
access to the users groups.

Also allow users to add supplimental groups to the container.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-12-22 11:53:00 -05:00
Daniel J Walsh c65d837641
Merge pull request #4443 from flouthoc/extend-cache-from-api
remote-cache: support multiple sources and destination for `--cache-to` and `--cache-from`
2022-12-12 14:41:48 -05:00
Chris Evich 46eea31588
Replace io/ioutil calls with os calls
In golang 1.19, `io/ioutil` is fully deprecated preventing Buildah from
compiling.  Replace all calls with equivalent calls from the `os`
package.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-12-06 14:29:32 -05:00
Aditya R ffed850367
remote-cache: support multiple sources and destinations
Buildah must support multiple sources for remote cache when using
`--cache-to` and `--cache-from` so users can distribute and collect
cache from various sources.

We also need for compat with buildkit api which in past broke `podman`
compat build API see: https://github.com/containers/podman/pull/16380

More discussion here: https://github.com/containers/podman/pull/16380

Signed-off-by: Aditya R <arajan@redhat.com>
2022-12-05 12:10:41 +05:30
Aditya R 4c9fc47f0a
run,build: conflict --isolation=chroot and --network
Conflict --isolation=chroot and --network, since internally --chroot
will always configure network ns equivalent to host.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-21 12:27:44 +05:30
Ed Santiago de9c3841c7 Fix broken dns test (from merge collision)
And, while I'm at it, fix grammar ("cannot" is one word)

Signed-off-by: Ed Santiago <santiago@redhat.com>
2022-09-20 20:02:40 -06:00
Daniel J Walsh f0bee4ee3d
Merge pull request #4250 from rhatdan/dns
Prevent use of --dns* options with --net=none
2022-09-19 13:47:00 -04:00
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 3c092e5edd
build: support --skip-unused-stages for multi-stage builds
In multi-stage builds buildah will skip stages which are unused (i.e
stages which don't contribute anything to target stage directly or
indirectly) however in certain cases users need to process these unused
stages hence add support for `--skip-unused-stages` which allows users
to control this behaviour.

Ref: https://github.com/GoogleContainerTools/kaniko#flag---skip-unused-stages

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-17 12:51:15 +05:30
Daniel J Walsh 87d4ae8864
Prevent use of --dns* options with --net=none
This is blocked in Podman for run and create but not
for build, we should block it also for build.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-15 15:10:58 -04:00
Aditya R fd14bfe545
buildah: make --cache-ttl=0s equivalent to --no-cache
If user explicitly specified `--cache-ttl=0s
it would effectively mean that user is asking
to use no cache at all. In such use cases
buildah can skip looking for cache entierly
by setting `--no-cache=true` internally.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-15 15:55:07 +05:30
Aditya R a30b71db2c
build: honor <Containerfile>.containerignore as ignore file
As per buildkit backend documentation when using the BuildKit backend, docker build searches for
a `.dockerignore` file relative to the Dockerfile name. For example, running `docker build -f myapp.Dockerfile .`
will first look for an ignore file named `myapp.Dockerfile.dockerignore`. If such a file is not found, the
`.dockerignore` file is used if present. Using a Dockerfile based `.dockerignore` is useful if a project contains
multiple Dockerfiles that expect to ignore different sets of files.

Following PR introduces this buildkit feature parity.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-09-13 20:37:39 +05:30
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
Aditya R b7f51ea3d7
build: support filtering cache by duration using --cache-ttl
`build` or `bud` now supports a new flag `--cache-ttl` which accepts
duration and allows end users to ignore cache images which are not under
the specified duration.

Following flag is useful for setups/platforms which heavily relies on
`--layer` and buildah caching but want recompute certain `RUN` steps
after specified duration to make sure specific `RUN` steps are always
updated. Example `RUN dnf update` or `RUN dnf install`

Closes: https://github.com/containers/buildah/issues/4160
Somewhat similar to kaniko's: https://github.com/GoogleContainerTools/kaniko#--cache-ttl-duration

Signed-off-by: Aditya R <arajan@redhat.com>
2022-08-05 11:50:15 +05:30
Aditya R 6f660bde17
build,cache: support pulling/pushing cache layers to/from remote sources
Following commit

* Initiates `cacheKey` or `layerKey` for intermediate images generated
  for layers.
* Allows end users to upload cached layers with `cacheKey` to remote
  sources using `--cache-to`. `--cache-to` is a optional flag to be used
with `buildah build` which publishes cached layers to remote sources.
* Allows end users to use cached layers from `remote` sources with
  `--cache-from`. `--cache-from` is a optional flag to be used with
`buildah build` and it pulls cached layers from remote sources in a step
by step manner only if is a valid cache hit.

Example
* Populate cache source or use cached layers if already present
```bash
buildah build -t test --layers --cache-to registry/myrepo/cache --cache-from registry/myrepo/cache .
```

Future:
* `cacheKey` or `layerKey` model is only being used when working with
  remote sources however local cache lookup can be also optimized if its
is altered to use `cacheKey` model instead of iterating through all the
images in local storage. As discussed here

References:
* Feature is quite similar to `kaniko`'s `--cache-repo`: https://github.com/GoogleContainerTools/kaniko#--cache-repo

Closes: issues#620

Signed-off-by: Aditya R <arajan@redhat.com>
2022-07-26 01:49:13 +05:30
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
Daniel J Walsh 3aea4093d4
Sort buildoptions and move cli/build functions to internal
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-06-07 10:31:55 -04:00
Daniel J Walsh 6225b23d68
Move options parsing out of build.go and into pkg/cli
Attempting to share common code for CLI parsing between
buildah build and podman build

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-06-06 14:58:38 -04:00