Commit Graph

24 Commits

Author SHA1 Message Date
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