Commit Graph

135 Commits

Author SHA1 Message Date
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 0835cb4760 Use slices.Clone
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 15:26:09 -07:00
Kir Kolyshkin 1ede7ddce7 Use any instead of interface{}
Brought to you by

	gofmt -r 'interface{} -> any' -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-08 10:19:51 -07:00
flouthoc 022ff233fc
stage_executor: reset platform in systemcontext for stages
Every stage now has its own copy of systemcontext.

On processing of every stage platform spec in systemcontext must be
correctly reset.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-04-03 09:19:05 -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
Giuseppe Scrivano eb7a422176
executor: allow to specify --no-pivot-root
the functionality is already implemented, it must be exposed through
the BuildOptions struct.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-11-13 13:06:37 +01:00
Nalin Dahyabhai 81d1256bd7 imagebuildah.StageExecutor: clean up volumes/volumeCache
Clean up the distinctions between the volumes slice and the volumeCache
and volumeCacheInfo maps so that --compat-volumes will work correctly
when we're building with multiple layers.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-09-12 09:02:22 -04:00
Nalin Dahyabhai f88579d1fe imagebuildah: make scratch config handling toggleable
The default configuration that `docker build` applies to images built
using "scratch" has changed from classic builds to BuildKit.  Add a
toggle for selecting which behavior to mimic.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-28 10:21:16 -04:00
Nalin Dahyabhai 8ae99121c1 CI: enable the gofumpt linter
Turn on the gofumpt linter.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-08-15 13:17:44 -04:00
Nalin Dahyabhai 3e38e5e138 imagebuildah: always have default values for $TARGET... args ready
Always have values for $TARGET... build args ready to be used.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-24 11:05:34 -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 66957cc05e commit: set "parent" for docker format only when requested
Make setting the Parent field in the config blob of a docker format
image optional (yes, we're bringing it back!), since it no longer
appears to be set by newer versions of docker build.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-18 09:55:38 -04:00
Nalin Dahyabhai a42019d614 Drop copyStringSlice() and copyStringStringMap()
Use slices.Clone() and maps.Clone() instead of our own non-generic
functions.  We have to be more careful in a couple of places where we
set items in maps which aren't unconditionally initialized.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-05 11:01:07 -04:00
Aaron Lehmann 7ff83d5055 Change to take a types.ImageReference arg
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2024-05-24 14:27:09 -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
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 34dff20dae
Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-01-28 07:25:10 -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
Philip Dubé a42bfd0191 Replace map[K]bool with map[K]struct{} where it makes sense
Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-05 15:58:43 +00:00
Philip Dubé 53c65dd360 Replace strings.SplitN with strings.Cut
Introduced in go 1.18: https://github.com/golang/go/issues/46336

[NO NEW TESTS NEEDED]

Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-02 17:15:12 +00:00
openshift-merge-bot[bot] bf3b55ba74
Merge pull request #5129 from flouthoc/bump-c-image
image: replace `GetStoreImage` with `ResolveReference` and  bump `c/image` to `373c52a9466f`
2023-11-09 18:34:06 +00:00
Aditya R 61de02b0fe
image: replace GetStoreImage with ResolveReference
replace deprecated GetStoreImage -> ResolveReference

Signed-off-by: Aditya R <arajan@redhat.com>
2023-11-09 13:14:44 +05:30
Nalin Dahyabhai 9f1c9a8eec Use a constant definition instead of "scratch"
Use a definition of "scratch" that's exported by imagebuilder instead of
hard-coding it ourselves like it's just some magic value we came up
with, in the multiple places where we refer to it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-11-08 15:53:45 -05:00
Valentin Rothberg 02f781b354 container.conf: support attributed string slices
All `[]string`s in containers.conf have now been migrated to attributed
string slices which require some adjustments in Buildah and Podman.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 15:34:23 +02:00
Daniel J Walsh 48a9c43718
Add --no-hostname option to buildah containers
Fixes: https://github.com/containers/buildah/issues/5093

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-10-24 19:43:56 -04:00
Valentin Rothberg c536048cac vendor c/common: appendable containers.conf strings, Part 1
This change is the first step of integrating appendable string arrays
into containers.conf and starts with enabling the `Env`, `Mounts`, and
`Volumes` fields in the `[Containers]` table.

Both, Buildah and Podman, read (and sometimes write) the fields of the
`Config` struct at various places, so I decided to migrate the fields
step-by-step.  The ones in this change are most critical ones for
customers.  Once all string slices/arrays are migrated, the docs of
containers.conf will be updated.  The current changes are entirely
transparent to users.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-24 17:00:38 +02:00
Aditya R 07d955f277
imagebuildah,multi-stage: do not remove base images
When building a multi-stage image ( without `--layers` ) and a
stage contains only a base-image buildah removes the base-image
itself as part of cleanup process. This is a bug and following commit
fixes that.

Reproducer

```Dockerfile
FROM parent
FROM another-base
COPY --from=0 somefile .
```

`buildah build -t multi-stage .`

Closes: https://github.com/containers/podman/issues/20291

Signed-off-by: Aditya R <arajan@redhat.com>
2023-10-09 15:45:12 +05:30
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
Nalin Dahyabhai 7545685800 Don't try to look up names when committing images
Don't try to look up an image by name when we're committing an image,
because we don't want to accidentally take advantage of any fuzzy
matching that libimage might start doing.  Instead, just use the
normalization call.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-09-05 16:37:14 -04:00
Aditya R a3f2aa3c74
executor: build-arg warnings must honor global args
build-arg warnings must honor globally defined arguments and must not
produce warnings if an arguments is already defined globally.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-18 16:26:02 +05:30
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
guoguangwu d22a5293be chore: pkg imported more than once
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-06-27 13:35:36 +08:00
Aditya R 0766b004bb
executor: apply label to only final stage
In https://github.com/containers/buildah/pull/4673 we made a change were
we were applying labels to end of each stage, which is different than
what we were doing before i.e applying label at the end of the each
step.

However buildkit does not adds label to any stage or steps it only adds
label at the end of final stage so lets do that.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-05-27 07:49:49 +05:30
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
Aditya R dfc9bb20e4
executor: only apply label on the final stage
Buildah currently applies labels to each intermediate image which is not
the right thing to do since others builds uses these intermediate image
and they can inherit the label even though they never had this
intention.

Only apply labels to the final build i.e last instruction of last stage
which will make sure that labels are only applied to final image and not
to the intermediate images.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-03-29 20:46:40 +05:30
Daniel J Walsh 15114d97a1
Merge pull request #4634 from flouthoc/dont-warn-multi-arch
executor: don't warn about unused `TARGETARCH`,`TARGETOS`,`TARGETPLATFORM`
2023-03-02 08:40:03 -05:00
Aditya R 46ffaf9354
executor,copy: honor default ARG value while eval stage
COPY must honor processing any argument if any configured while
evaulating `--from=` statement.

Makes below Containerfile functional without any external `--build-arg`
value from CLI

```Dockerfile
ARG my_env=a

FROM alpine as stage_a
RUN /bin/true

FROM alpine
COPY --from=stage_${my_env} /bin/true true
```

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-03-02 14:33:47 +05:30
Aditya R 8a8f99e09b
executor: do not warn on builtin default args
Do not warn on builtin default args

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-03-02 11:37:08 +05:30
Aditya R b9e4e29e90
executor: don't warn about unused TARGETARCH,TARGETOS,TARGETPLATFORM
Buildah warns about TARETARCH, TARGETOS, TARGETPLATFORM in a multi-arch
build however its not very useful for end-users and there are cases
where this can be left untouched so do not warn about test default build
args

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-03-02 11:37:02 +05:30
Aditya R be10b8d20c
executor: also add stage with no children to cleanupStages
While preparing list of cleanup stages, executor must add stage with no
children also to cleanupStages since a stage can also exist in the form
only `FROM base_image` i.e without any child nodes.

Ensures we leave no dandling build container for cases such as

```dockerfile
FROM quay.io/quay/busybox:latest AS busybox

FROM scratch

COPY --from=busybox /bin/busybox /bin/busybox
```

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

Signed-off-by: Aditya R <arajan@redhat.com>
2023-02-17 09:55:33 +05:30
Nalin Dahyabhai 67ab55bbb7 bud: Consolidate multiple synthetic LABEL instructions
We handle --label command line arguments by appending LABEL instructions
to the Dockerfile contents before we parse it.  Previously, we were
appending a separate line for each label-value pair.  Consolidate them
for the sake of tools that arbitrarily limit the length of histories
that they're willing to accept in images (boo!).

Add a similar implementation for --env command line arguments.
Previously, we'd set them in the initial configuration for each stage
and also set them at commit-time, and that potentially overrode any
values that were explicitly in the stage itself, and which would have
affected RUN instructions.  Remove the set-at-commit-time logic so that
the history reflects what ends up in the image.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-01-09 16:45:10 -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 a237085fe0
executor: honor default ARG value while eval base name
While PR https://github.com/containers/buildah/pull/3947 added support
for evaluating `--build-args` in base image names for a builds but it
missed processing default value if any. So for scenarios where `ARG`
already has a default value in Containerfile via `ARG key=value` but
was not specified with `--build-arg key=value` the processing ignored
the default value. Following commit just adds support for that.

Makes below Containerfile functional without any external `--build-arg`
value from CLI

```Dockerfile
ARG my_env=a

FROM alpine as stage_a
RUN /bin/true

FROM stage_${my_env} as stage_b
RUN /bin/true
```

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-11-01 11:11:28 +05:30
Marcus Watkins 1d0dd78c38 Fix RUN --mount=type=bind,from=<stage> not preserving rootfs of stage
The lack of the preservation was probably an oversight when --mount was added for RUN.

I added a test that fails without the modification and succeeds with.

Fixes #4375

Signed-off-by: Marcus Watkins <mwatkins@mitre.org>
2022-10-26 19:43:32 -04:00
Aditya R 9d43eb95e5
imagebuildah: warnOnUnsetBuildArgs while processing stages from executor
Before this commit buildah produces warning for UnsetBuildArgs at the
top level while preparing the build in `imagebuildah/build` hence it
makes it hard to honor certain logic like `do not produce warning for
stages which are not used` therefore move `warnOnUnsetBuildArgs` to
`imagebuldah/executor` so we can warn while processing each stage.

Following commit will prevent warning unnecessarily for stages which are
completely skipped.

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

Signed-off-by: Aditya R <arajan@redhat.com>
2022-10-10 13:12:56 +05:30