Commit Graph

62 Commits

Author SHA1 Message Date
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 00d46292ca
Remove util.StringInSlice because it is defined in containers/common
[NO NEW TESTS NEEDED] Since this is just a code cleanup

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-05-25 05:49:04 -04:00
Nalin Dahyabhai 1680e26eb4 Handle OS version and features flags
Teach `buildah build` and `buildah config` about the OS version and
features fields.  We don't tend to use them on Linux, but they're in the
OCI and Docker config structures, so we need to be able to preserve and
manipulate their values, much as we do for variant information.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-05-03 16:11:25 -04:00
Nalin Dahyabhai 9f9f32cedd config: support the variant field
Add the variant field, along with methods for setting and querying it,
and expose them in the `buildah config` and `buildah inspect` commands.

When setting an initial architecture for a container based on an image
which doesn't contain an architecture, or from "scratch", normalize the
architecture name we've been given, and set both it and the variant
field at the same time.

Provide normalized architecture+variant values in `buildah info`.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-11-05 09:37:00 -04:00
Daniel J Walsh 00ba17b37a
Plumb the remote logger throughut Buildah
Users are not seeing Warnings when doing podman --remote build.
We need to wire the logrus messages all the way through the system.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-28 14:48:16 -04:00
Nalin Dahyabhai 9073afddef unmarshalConvertedConfig(): handle zstd compression
The Docker manifest format doesn't currently support listing layers
compressed using zstd, so we trigger an error when we try to convert an
in-memory OCI manifest to the Docker format as a preliminary step in
reading the image's config blob in the Docker format.

Instead, first create a temporary copy of the manifest, and then force
the MIME types for all layers in the temporary copy of the manifest to
appear to be compressed using gzip.  Both OCI and Docker formats will
accept the resulting manifest without issue.  We throw the copy away
after we've read the config blob, so the wackiness should be contained.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-09-20 14:49:01 -04:00
Nalin Dahyabhai ae08e01e49 bud: teach --platform to take a list
Add a pkg/parse.PlatformsFromOptions() which understands a "variant"
value as an optional third value in an OS/ARCH[/VARIANT] argument value,
which accepts a comma-separated list of them, and which returns a list
of platforms.

Teach "from" and "pull" about the --platform option and add integration
tests for them, warning if --platform was given multiple values.

Add a define.BuildOptions.JobSemaphore which an imagebuildah executor
will use in preference to one that it might allocate for itself.

In main(), allocate a JobSemaphore if the number of jobs is not 0 (which
we treat as "unlimited", and continue to allow executors to do).

In addManifest(), take a lock on the manifest list's image ID so that we
don't overwrite changes that another thread might be making while we're
attempting to make changes to it.  In main(), create an empty list if
the list doesn't already exist before we start down this path, so that
we don't get two threads trying to create that manifest list at the same
time later on.  Two processes could still try to create the same list
twice, but it's an incremental improvement.

Finally, if we've been given multiple platforms to build for, run their
builds concurrently and gather up their results.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-08-04 15:23:10 -04:00
Valentin Rothberg d97694b013 set base-image annotations
Since opencontainers/image-spec/pull/822/ the OCI spec supports two new
annotations to set the fully-qualified name and the digest of the base
image.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-03 15:51:18 +02:00
Daniel J Walsh d7d078561c
Send logrus messages back to caller when building
We want Info, Warning and Debug logrus messages to be writen to the
buildah stderr. this way when podman-remote is using build, it will
get the messages back on the client side.

[NO TESTS NEEDED] Since this will be tested in Podman.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-15 03:55:05 -04: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
Josh Soref c7963db369 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-21 16:47:18 -05:00
Daniel J Walsh 1b8d997a07
Drop error messages about OCI/Docker format to Warning level
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-27 15:46:09 -04:00
Ashley Cui 1ff0071ba0 Warn when setting healthcheck in OCI format
healthcheck only works in Docker format, so when healthcheck is set in OCI format, warn user that it will be discarded

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-09-17 13:42:46 -04:00
Nalin Dahyabhai 4e03c80a0b unmarshalConvertedConfig: avoid using the updated image's ref
The image returned by UpdatedImage() doesn't have a reference, so
attempting to include the result's name in an error message causes a
crash.  Assign it to a temporary variable first so that we can use the
name of the un-updated version in an error message.

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

Closes: #1960
Approved by: TomSweeneyRedHat
2019-11-05 14:38:30 +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
Ashley Cui 03aa80716f Bug fix for volume minus syntax
Do not check disk for existence of volume.
If volume that ends with `-` is set in config, remove it.
If not, add it into config.

Signed-off-by: Ashley Cui <ashleycui16@gmail.com>

Closes: #1767
Approved by: rhatdan
2019-08-07 15:11:05 +00:00
Ashley Cui 4ccb343cef Added '-' syntax to remove volume config option
When using the --volume flag, ojects ending in "-" are checked if they exist on disk. If they exist on disk they are added as a volume. Otherwise, if the volume is already config'd, that volume is removed

examples:
if /testvol exists:
"--volume /testvol-" removes /testvol from the config.

if /testvol- exists:
"--volume /testvol-" adds /testvol- from the config.

Signed-off-by: Ashley Cui <ashleycui16@gmail.com>

Closes: #1670
Approved by: rhatdan
2019-07-29 19:04:34 +00:00
Sascha Grunert 1d35489ca0
Add misspell linter and apply fixes
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-07-18 10:45:52 +02:00
Nalin Dahyabhai 4d8ae6c48c config: expand variables only at the command line
Skip our own attempt to expand variables in the SetEnv API, since we
need to let the Dockerfile parser be the only place that happens when
we're building using a Dockerfile.

Move the expansion logic to the CLI, and have it log an error when it
encounters a variable that it can't expand.

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

Closes: #1607
Approved by: TomSweeneyRedHat
2019-05-22 14:03:44 +00:00
Nalin Dahyabhai 5d705ffcb7 SetEnv: we only need to expand v once
We only need to expand the passed-in value once, not once for every variable
that is set in the environment.

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

Closes: #1607
Approved by: TomSweeneyRedHat
2019-05-22 14:03:43 +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
Daniel J Walsh 579f1d526f We should only warn if user actually requests Hostname be set in image
When we set the Hostname to match the container id, we don't want to print
the warning, since the user did not request the hostname being set.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1253
Approved by: vrothberg
2019-01-03 14:44:19 +00:00
Nalin Dahyabhai b2e43c7d6d Support HEALTHCHECK
Handle healthcheck configuration that imagebuilder picks up, and add CLI
flags to `buildah config` that allow the values to be set on the command
line.

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

Closes: #943
Approved by: TomSweeneyRedHat
2018-11-21 12:56:24 +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
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
Daniel J Walsh cf6e5fd8a6 Warn about using Commands in Dockerfile that are not supported by OCI.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #957
Approved by: umohnani8
2018-08-28 10:58:55 +00:00
Daniel J Walsh 9a44254275 Cleanup code to more closely match Docker Build images
Hostname should be set to a random name if not set.
Workdir should default to "" not to "/"
If Volumes and Entrypoint are not set they should return NULL not []

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #958
Approved by: TomSweeneyRedHat
2018-08-24 19:02:08 +00:00
Daniel J Walsh 462e2ef7d6 Expand variables names for --env
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #931
Approved by: vbatts
2018-08-15 18:50:33 +00:00
Miloslav Trmač 93d86062e9 Use the c/image conversion code instead of converting configs manually
Now that we have a types.Image available in Builder.initConfig, we can
let it do the heavy work of converting configs to the v2s2 and OCI formats.

This requires us to cheat a bit with c/image/types.InformationOnly, but it
works out fine.

AFAICS this should have equivalent effect to the previous implementation,
except:
- Conversion from OCI will no longer crash if "Created" timestamps are missing.
- Conversion from v2s2 to OCI only uses the Config field, not ContainerConfig.
  Considering the Docker deamon only ever uses Config for populating the
  configuration of newly created containers in (docker create), this seems
  good enough.  But, to be honest, I'm not quite clear on the purpose of the
  Config/ContainerConfig distinction in v2s2.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač 3e5102046e Don't throw away the manifest MIME type and guess again
When loading the manifest using a types.Image.Manifest,
we also get a manifest MIME type; don't just throw it away
and then guess as if the data was never available, just use it
directly (now that the loading is close enough for the throwing
away to be noticeable).

[Ultimately, this loads the manifest from a c/image/storage
backend, which calls manifest.GuessMIMEType anyway, so this
does not change behavior right now, but if the c/image/storage
backend ever changed to record MIME types, it would make a
difference.  At the very least, we now run the heuristic once
instead of twice.]

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač 6cb7048d90 Consolidate loading manifest and config in initConfig
Both callers of initConfig contain exactly the same code
to load the manifest and config; move it inside initConfig
now that initConfig has the necessary types.Image available.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač 2283f62a38 Pass a types.Image to Builder.initConfig
Both callers of initConfig use a types.Image to get a manifest and
config; so, preserve the types.Image and pass it to Builder.initConfig.

This does not change behavior (except for making the lifetime of
a types.Image a bit longer in one case), but it will allow moving the
manifest/config load into Builder.initConfig in the future.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač e137d26ab9 Use c/image/manifest.GuessMIMEType instead of a custom heuristic
Notably this will use the manifest mediaType field, instead of the
config docker_version field, to detect Docker v2s2 images; again,
docker_version is cleared by buildah itself, so it can't be relied
to decide on the image format.

Anyway, centralizing the tricky heuristic and using a single one
everywhere seems preferable for consistency.

This also allows only searching for OCI annotations on known OCI
images, and that in turn allows us not to silently ignore errors
when parsing OCI manifests.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač 35f6558e84 Do not ignore any parsing errors in initConfig
Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač c8844f060e Explicitly handle "from scratch" images in Builder.initConfig
... instead of silently ignoring failures to parse the manifest.

This does not change behavior, but it clearly delineates the
existing/scratch cases, and that which will allow us to better
handle errors in the future.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač 4b2f45325d Fix parsing of OCI images
The code apparently intended to use the OCI data to generate
a v2s2 config, instead it only generates the v2s2 config
if OCI parsing fails (from the results of the failed parsing).

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač ec4d02512d Simplify dead but dangerous-looking error handling
Drop error returns from makeDockerV2S2Image and makeOCIv1Image, they
are always nil.  Then drop the code which "handles" the errors
by silently ignoring them.

Right now that does not matter, but if make*Image ever did start
returning errors, the existing caller would silently ignore them
and record useless empty data.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Miloslav Trmač eceb6efb48 Don't ignore v2s1 history if docker_version is not set
buildah itself clears docker_version in Builder.fixupConfig; so,
buildah-created v2s1 images do not pass this test
(buildah from buildah-created-v2s1) creates an image with empty
history, which causes (buildah commit) to complain about the mismatch
between history and layer DiffID list.

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

Closes: #776
Approved by: rhatdan
2018-06-17 12:37:24 +00:00
Daniel J Walsh b66e853145 Add OnBuild support for Dockerfiles
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #722
Approved by: mheon
2018-05-31 13:30:29 +00:00
Nalin Dahyabhai 523b1095d8 Add config --comment/--domainname/--history-comment/--hostname
Add options to "buildah config" for setting comment, domainname, and
hostname configuration bits, and the comment in history items which
describe layers that we add, and tests for them.  Add a test for the
--shell option while we're at it.

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

Closes: #641
Approved by: rhatdan
2018-04-27 16:33:13 +00:00
Zhou Hao f2c532a958 config: add support for StopSignal
Add a stop-singnal option for buildah-config.

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

Closes: #567
Approved by: rhatdan
2018-04-12 06:58:26 +00:00
baude 89e9d1bd85 Add accessor functions for comment and stop signal
Podman commit needs the ability to set a comment and stop signal
when committing a container to an image.  Adding set/get functions
for each.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #560
Approved by: nalind
2018-04-10 18:14:28 +00:00
Daniel J Walsh 5ce80091ba Add support for shell
Also vendor in the latest imagebuilder code and all the packages
that come with it.

Note: imagebuilder.NewBuilderForReader has been removed from imagebuilder
so I had to split the function up into two different calls.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #517
Approved by: rhatdan
2018-04-03 22:25:56 +00:00
Boaz Shuster ba128004ca Fix "make validate" warnings
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>

Closes: #405
Approved by: rhatdan
2018-01-22 14:46:54 +00:00
Nalin Dahyabhai ae7d2f3547 Ignore sequential duplicate layers when reading v2s1
When a v2s1 image is stored to disk, some of the layer blobs listed in
its manifest may be discarded as.  Account for this.

Start treating a failure to decode v1compat information as a fatal error
instead of trying to fake it.

Tweak how we build the created-by field in history when generating one
from v2s1 information to better match what we see in v2s2 images.

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

Closes: #383
Approved by: rhatdan
2018-01-08 21:06:35 +00:00
Daniel J Walsh 3e8ded8646 Add secrets patch to buildah
Signed-off-by: umohnani8 <umohnani@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-11-08 00:01:57 +00:00
Nalin Dahyabhai 12a3abf6fa Update to match newer storage and image-spec APIs
Update to adjust to new types and method signatures in just-updated
vendored code.

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

Closes: #174
Approved by: rhatdan
2017-06-28 21:05:58 +00:00
Nalin Dahyabhai 7b5fed15ae Don't overwrite parent information when reading
Don't overwrite an image configuration's information about the source
image unless we're intending to create a new working container.

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

Closes: #141
Approved by: rhatdan
2017-06-13 21:50:42 +00:00
Nalin Dahyabhai 4a05d8643d Add an option to specify a Create date for images
Add CommitOption option that to allow a caller to specify a creation
timestamp to use in images.

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

Closes: #141
Approved by: rhatdan
2017-06-13 21:50:42 +00:00