Commit Graph

145 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 fd498cbf5d imagebuildah.Executor/StageExecutor: check numeric --from= values
When we look up a stage that's referred to in a COPY --from argument,
treat the string as a stage number not only if it parses as one, as we
checked before, but now also require that the number correspond to one
of the stages that would be completed before the one into which the
content will be copied.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-08-11 14:10:16 -04:00
flouthoc 3502889676
stage_executor: check platform of cache candidates
When building images for `manifest` list using `--platform` same image
is used for multiple platform if base is `scratch` , following PR adds a
check to always verify `platform` of `cache` with `target`.

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

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-07-11 09:44:07 -07: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
Nalin Dahyabhai df36bb835a commit: exclude parents of mount targets, too
When RUN requires us to create the target for a mountpoint, make note of
it and any parent directories that needed to be created, and filter them
out when generating a layer diff or --output data.

The exceptions will be directories that the conformance tests confirm
that BuildKit also leaves behind, though for compatibility with the
classic builder, we have to make that conditional.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-06-20 11:19:27 -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 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